-   Programming (
-   -   GCC Static linking error (

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:

#include "CBuzzer.h"

int main()
return 0;
And makefile rule:

$(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

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

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


Originally Posted by CartmanYO (Post 3999065)

$(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 08:35 AM.