make the return type in your go program C.int and it'll compile.

then using LD_PRELOAD against the so should work.

On Monday, May 8, 2017 at 5:44:09 PM UTC-4, Tony Walker wrote:
>
> Hi All,
>
> I'd like to experiment writing a shared library that will override system 
> functions via LD_LIBRARY_PATH. I'd like to achieve something like the basic 
> functionality demonstrated here where rand() is overridden.
>
> If I write a simple function to overwrite it (see here 
> <https://play.golang.org/p/PF76cJVO6X>) I get the following error when 
> trying to compile with go build -o rand.so -buildmode=c-shared test.go (Go 
> 1.7.4 - same with 1.8 but a slightly different error):
>
> # command-line-arguments
> In file included from $WORK/command-line-arguments/_obj/_cgo_export.c:3:0:
> /tmp/go-build613177413/command-line-arguments/_obj/_cgo_export.h:55:14: 
> error: conflicting types for ‘rand’
>  extern GoInt rand();
>               ^~~~
> In file included from $WORK/command-line-arguments/_obj/_cgo_export.c:2:0:
> /usr/include/stdlib.h:335:12: note: previous declaration of ‘rand’ was here
>  extern int rand (void) __THROW;
>             ^~~~
> /tmp/go-build613177413/command-line-arguments/_obj/_cgo_export.c:17:7: 
> error: conflicting types for ‘rand’
>  GoInt rand()
>        ^~~~
> In file included from $WORK/command-line-arguments/_obj/_cgo_export.c:2:0:
> /usr/include/stdlib.h:335:12: note: previous declaration of ‘rand’ was here
>  extern int rand (void) __THROW;
>             ^~~~
> I'm not clear whether I simply need to find a way to declare an equivalent 
> signature which matches the stdlib, or whether creating a function which is 
> already defined is just not allowed.
>
> Can anyone help here?
>
> Thanks,
>
> Tony
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to