I am trying to call one function in a .so which contains quite a lot of functions, but after having tried to get it working for days, am at a dead end. Using the nm command, the .so has a few undefined symbols, but the vast majority, including the one I am calling, are defined (labelled with a 'T'), so I see no reason for the linking to fail.
The code that originally created the .so is not mine, the most involved I got was to run it's Makefile. A note is that a different project that relies on this .so, and other .so's, works fine on my machine, but I've been unable to find out how exactly they use the .so's.
Code is:
Code:
#include <stdio.h>
int main(void)
{
int i;
i = SCIPtechVersion();
printf("Version is %i.\n", i);
return 0;
}
I have tried a number of ways to get the linking working, using different arrangements of -shared, -static, or no options
1)
Makefile:
Code:
SCIPDIR = /home/andy/Project/Source/ziboptsuite-1.2.0/scip-1.2.0
HOMELIB = /home/andy/Project/Lib
test:
gcc -shared test.c -o test.o
gcc test.o $(HOMELIB)/scip-1.2.0/libscip.so -o test
clean:
rm test.o test
Output is:
Code:
/home/andy/Project/Lib/scip-1.2.0/libscip.so: undefined reference to `gzputc'
/home/andy/Project/Lib/scip-1.2.0/libscip.so: undefined reference to `SCIPlpiInfinity'
/home/andy/Project/Lib/scip-1.2.0/libscip.so: undefined reference to `gzflush'
/home/andy/Project/Lib/scip-1.2.0/libscip.so: undefined reference to `SCIPlpiGetObjval'
/home/andy/Project/Lib/scip-1.2.0/libscip.so: undefined reference to `sqrt'
.
.
.
/home/andy/Project/Lib/scip-1.2.0/libscip.so: undefined reference to `fesetround'
/home/andy/Project/Lib/scip-1.2.0/libscip.so: undefined reference to `SCIPlpiIsObjlimExc'
/home/andy/Project/Lib/scip-1.2.0/libscip.so: undefined reference to `log10'
/home/andy/Project/Lib/scip-1.2.0/libscip.so: undefined reference to `BMSduplicateBlockMemory_call'
collect2: ld returned 1 exit status
make: *** [test] Error 1
True, these functions are undefined the original .so, but I am not asking to use these.
2)
Code:
SCIPDIR = /home/andy/Project/Source/ziboptsuite-1.2.0/scip-1.2.0
HOMELIB = /home/andy/Project/Lib
test:
gcc -shared test.c -o test.o
gcc -shared test.o $(HOMELIB)/scip-1.2.0/libscip.so -o test
clean:
rm test.o test
The linking performs fine, but when I run the test binary, I get a segmentation fault.
nm reveals that the symbol representing SCIPtechVersion isn't present in test, although it is present in test.o.
3)
Trying to link test.o and the .so file with -static fails because test.o is compiled as a dynamic object. If I try to compile test.c without the -shared option, it obviously fails due to the undefined function reference.
I am desperate to resolve this issue. Hopefully, I've included enough information.