Hello,

 

Since I could not find the answer in the cgo documentation, I would really 
appreciate if somebody could help me to understand why when I build cgo code 
with calls to the shared library, the linker tries to find the shared library 
even though it is instructed to build dynamic binary and not static.

 

I have C built shared library, I have no control how it gets built, I only have 
lib_blahblah_x64_86.so . There are 2 external functions 
bind_wrapper/unbind_wrapper in that library which I call from cgo. 

 

Here is the command line I use to compile:

 

CC=/bin/tools/llvm11/llvm-11.0-p25/bin/clang-11 go build -o go_connect 
-linkshared -ldflags "-linkmode external -extldflags -dynamic" go_connect.go

 

The compilation succeeds, but the linker is complaining:

 

/tmp/go-link-2323626149/000001.o: In function 
`_cgo_df3b8c92b86e_Cfunc_bind_wrapper':

/tmp/go-build/cgo-gcc-prolog:68: undefined reference to `bind_wrapper'

/tmp/go-link-2323626149/000001.o: In function 
`_cgo_df3b8c92b86e_Cfunc_unbind_wrapper':

/tmp/go-build/cgo-gcc-prolog:87: undefined reference to `unbind_wrapper'

clang-11: error: linker command failed with exit code 1 (use -v to see 
invocation)

 

 

My expectation was that the linker will not check external references to these 
functions while building the binary, and only when the binary is executed, the 
dynamic linker will attempt to resolve them.  I am suspecting I got something 
wrong, appreciate if somebody could provide some suggestions.

 

Thank you

Serguei

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/D81654F3-8CF7-4FE9-9477-261A305C19D5%40gmail.com.

Reply via email to