I found it: I had a typo writing "C.nil" instead of "nil". thanks for your help!

On Sun, Jun 11, 2017 at 9:31 PM, Ian Lance Taylor <i...@golang.org> wrote:
> On Sun, Jun 11, 2017 at 7:56 PM, andrey mirtchovski
> <mirtchov...@gmail.com> wrote:
>>
>> I have a piece of cgo code which doesn't do much, but links a lot of
>> libraries in. As far as I can tell all my includes are there and they
>> shouldn't stomp on each other (they don't when compiled in C), however
>> with cgo I get the following weirdness:
>>
>> $ go build
>> # mypkg
>> Undefined symbols for architecture x86_64:
>>   "___DARWIN_NULL", referenced from:
>>       __cgohack___DARWIN_NULL in _cgo_main.o
>>      (maybe you meant: __cgohack___DARWIN_NULL)
>> ld: symbol(s) not found for architecture x86_64
>> clang: error: linker command failed with exit code 1 (use -v to see 
>> invocation)
>>
>> If I decide to be bold and #define __DARWIN_NULL in my Cgo preamble
>> (before "import C"), I get the following:
>>
>> $ go build
>> # mypkg
>> ./main.go:53:9: warning: '__DARWIN_NULL' macro redefined [-Wmacro-redefined]
>> /usr/include/sys/_types.h:52:9: note: previous definition is here
>>
>> I'm a little bit stumped. How to debug the chain on #includes to get
>> to the bottom of this? Why is this not a problem elsewhere?
>
> Presumably your Go code is referring to C.__DARWIN_NULL.  In some
> cases that will cause cgo to generate C code that looks like
>     extern char __DARWIN_NULL[];
>     void *_cgohack___DARWIN_NULL = __DARWIN_NULL;
> This kind of thing works for a variable or function, but not for a
> macro.  This may be a version of https://golang.org/issue/18720.  The
> simplest fix is to write, in your C preamble,
>     void *my_DARWIN_NULL = __DARWIN_NULL; // use the appropriate type here
> and then refer to C.my_DARWIN_NULL in your Go code.
>
> Ian

-- 
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