Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22000

golang gcc c++ existing static library can not be used when making a PIE object; recompile with -fPIC

$
0
0

I tried to link an existing C++ library to go code. The C++ library only has a static library and a header file, no source code.

I used swigc to generate a libfoo.go and I wrote a simple libb.go to build this library. This worked well on ubuntu 16.04 with gcc-6 earlier.

However, once I upgraded to ubuntu 18, and even with older go1.9 and gcc-6, which used to work, I am hitting the following error:

/usr/bin/ld: ./lib/libfoo.a(parser.o): relocation R_X86_64_32S against symbol `xmlSAX2IgnorableWhitespace' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: ./lib/libfoo.a(tree.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC

I have downgraded both go compiler and gcc to the version that used to work.

The following is the libb.go that used to work

/*
#cgo CXXFLAGS: -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -w
#cgo CFLAGS: -I${SRCDIR}/include -w
#cgo LDFLAGS: -Wl -rpath,./lib, -L${SRCDIR}/lib -l:libfoo.a  -l:libxml2.a 
*/
import "C"

What should I do get this fixed? I searched and it seems that I have to recompile that static library, which is mission impossible in my case. I tried to pass the -no-pie parameter to LDFLAGS, that didn't work either.


Viewing all articles
Browse latest Browse all 22000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>