Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I link against libpython.a such that the runtime linker can find all the symbols in libpython.a?

Tags:

python

gcc

g++

In a sequel question to this question, my corporate environment lacks the libpython2.6.so shared object but has the libpython2.6.a file. Is there a way that I can compile in libpython2.6.a while retaining the symbols in libpython2.6.a such that dynamic libraries can find these symbols at runtime?

My current compile with the static library looks like:

g++ -I/usr/CORP/pkgs/python/2.6.2/include/python2.6 \
    ~/tmp.cpp -pthread -lm -ldl -lutil \
    /usr/CORP/pkgs/python/2.6.2/lib/python2.6/config/libpython2.6.a \
    -o tmp.exe

However, if I load a module like 'math', it dies with:

undefined symbol: PyInt_FromLong
like image 381
Ross Rogers Avatar asked Dec 04 '25 17:12

Ross Rogers


1 Answers

You need to pass --export-dynamic to the linker. So from g++ it's...

g++ -Wl,--export-dynamic ...
like image 52
alex tingle Avatar answered Dec 07 '25 05:12

alex tingle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!