0
votes

I have a static library which I compiled with gcc without c99 mode. I am trying to link it in compilation using gcc -std=c99. This is giving me an error:

undefined reference to 'functionName'

Here, functionName is function inside the static library.

This is my compilation:

gcc -std=c99 -g -I../ -Llib/ -lmylib test.c ../file1.c ../file2.c -o test  

I am using C99 here because my code in test.c #includes header files whose implementation uses C99 standard.

The static library(lib/libmylib.a) in not compiled with c99 standard because it's code uses some libraries which are failing to compile in C99 mode(but compiles without c99 flag).

I also tried changing the order of the -L & -l flags to the end & immediately after gcc -std=c99 but it gave the same 'undefined reference' error.

How do I link these together?

Thank you.

EDIT: The function which I've mentioned as functionName is a pseudonym for setupStacktrace() shown here: http://pastebin.com/2RbEEPaj. It is signature is void setupStacktrace();

1
Are you certain that functionName is defined in one of the source files/library, and that it isn't defined inline? - Casey
Libraries after object files! Try: gcc -std=c99 -g -I../ -Llib/ test.c ../file1.c ../file2.c -lmylib -o test - Jonathan Leffler
@Casey that functionName is inside the static library. Will edit the question to add clarity. - Bharat
Add the declaration of functionName to the question, please. (C99 does some interesting things with inline) - Casey
@Casey, its not an inline function. I've edited my question with the function definition. - Bharat

1 Answers

1
votes

The order of the command line arguments matter. The way you have it now, the linker goes through your static libraries, realizes that nothing so far need anything it provides, and throw away everything in it. Do this:

gcc -std=c99 -g -I../ -Llib/  test.c ../file1.c ../file2.c -lmylib -o test