LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   GCC Static linking error (http://www.linuxquestions.org/questions/programming-9/gcc-static-linking-error-813359/)

CartmanYO 06-10-2010 10:03 AM

GCC Static linking error
 
Hello! There's a problem with static linking (and no problems with dynamic linking). Here's my code:
Quote:

#include "CBuzzer.h"

int main()
{
BuzzerInit();
return 0;
}
And makefile rule:
Quote:

$(OUTDIR)/plainc_test: plainc_test.c
@echo "Plain C API test: $@"
@nm -a $(LIB_ROOT)/obj/$(ARCH)/$(CFG)/libtfccore.a | grep BuzzerInit
$(CC) -o $@ $(INCLUDES) $(PLAIN_CCFLAGS) -L$(LIB_ROOT)/obj/$(ARCH)/$(CFG) -ltfccore $<
That's dynamic linking. And it works perfectly. If i use static linking
Quote:

$(CC) -o $@ $(INCLUDES) $(PLAIN_CCFLAGS) -L$(LIB_ROOT)/obj/$(ARCH)/$(CFG) -static -ltfccore $<
there is an undefined reference error:
Quote:

Plain C API test: obj/target/plainc_test
00000b88 T BuzzerInit
/tmp/ccxZih7c.o: In function `main':
/home/aparamonov/svn/tfccore/trunk/tests/plainc_test.c:44: undefined reference to `BuzzerInit'
collect2: ld returned 1 exit status
make: *** [obj/target/plainc_test] Error 1
As nm shows there's a symbol named BuzzerInit in static library. Does anybody know what's wrong with it?

JohnGraham 06-10-2010 12:04 PM

Quote:

Originally Posted by CartmanYO (Post 3999065)
Code:

$(CC) -o $@ $(INCLUDES) $(PLAIN_CCFLAGS) -L$(LIB_ROOT)/obj/$(ARCH)/$(CFG) -static -ltfccore $<

Have you tried putting '-ltfccore' after '$<'? Order matters, especially when linking statically.

CartmanYO 06-11-2010 02:28 AM

Thanks a lot! It works now.


All times are GMT -5. The time now is 11:39 PM.