0

I need to compile and, most importantly, link a C program that uses a proprietary function present in a shared library file. Because of lack of communication with the previous development team, there is no proper documentation. I declared a function prototype (because I know the number and type of arguments):

int CustomFunction(unsigned char *in, int size); 

Since that function name can be grepped from /customlibs/libcustom.so, I tried to compile the code and link it like this:

gcc -L/customlibs testing.c -o testing -lcustom 

Which throws a few error messages looking like this:

/customlibs/libcustom.so: undefined reference to `AnotherCustomFunction' 

Obviously, I need to tell linker to include other libraries as well, and, to make things worse, they need to be in certain order. I tried exporting LD_LIBRARY_PATH, using -Wl,-rpath=, -Wl,--no-undefined and -Wl,--start-group. Is there an easy way to give the linker all the .so files without the proper order?

3 Answers 3

1

I found the solution (or a workaround) to my problem: adding -Wl,--warn-unresolved-symbols, which turns errors to warnings. Note that this works only if you are ABSOLUTELY certain your function does not depend on the symbols mentioned in undefined refernce to: messages.

Sign up to request clarification or add additional context in comments.

Comments

0

Add them on the command line is a way to do it. Something like this below. The LD_LIBRARY_PATH tells gcc where to look for libraries, but you still need to say what libraries to include.

gcc -L/customlibs testing.c -o testing -lcustom -lmylib1 -lmylib2 -lmylib3

3 Comments

I tried that, and it complains about more undefined references
Ulrik, Which references? You should add more libs... And you may try ldd command on every shared library to extract which libraries it depend on, and then use topological sort or just try to add them all to the link command (between -( and -) option pair).
When I add all the shared libraries with -Wl,--start-group -lcustom1 -lcutom2 ... -Wl,--end-group I get even more messages like /customlibs/libcustom.so: undefined reference to AnotherCustomFunction'`
0

You should also include all the header files of your shared library by adding the -I option of gcc, for example : gcc [...] -I/path/to/your/lib/header/files [...]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.