, , (gcc , - gcc -v - ). , :
, . main. , ?
, , , , ( , , ). , .
, , ( , , ). , "" ( , ), - .
, :
gcc -L/path -lpython3.x <other libs> foo.o
, , python3.x lib: , main, python-lib, python-lib . foo.o, , Python-, .
: ! :
gcc -L/path foo.o -lpython3.x <other libs>
, python-lib, .
.
A) , :
gcc -L/path --Wl,-start-group -lpython3.x <other libs> foo.o -Wl,-end-group
-Wl,-start-group -Wl,-end-group , ( ) . .
B) --no-as-needed ( ), , .
gcc -L/path -Wl,-no-as-needed -lpython3.x -Wl,-as-needed <other libs> foo.o
, ld- - --no-as-needed, gcc-frontend ld --as-needed, , -no-as-needed python .
. , ( glibc), , , , python- .
: , . libmylib A B, ..
-L/A -L/B lmylib
:
A/libmylib.so
A/libmylib.a
B/libmylib.so
B/libmylib.a
, A , ( , B).
, - , -Wl,-verbose .
-Bstatic, :
gcc foo.o -L/path -Wl,-Bstatic -lpython3.x -Wl,-Bdynamic <other libs> -Wl,-verbose -o foo
:
:
gcc <cflags> L/paths foo.c -Wl,-Bstatic -lpython3.X -Wl,-Bdynamic <other libs> -o foo -Wl,-verbose
...
attempt to open path/libpython3.6m.a succeeded
...
ldd foo shows no dependency on python-lib
./foo
It works!
, static glibc ( ), -Xlinker -export-dynamic .
-Xlinker -export-dynamic c-, , ldopen.