Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-10-2010, 11:03 AM   #1
LQ Newbie
Registered: Jun 2009
Posts: 27

Rep: Reputation: 1
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?

Last edited by CartmanYO; 06-10-2010 at 11:07 AM.
Old 06-10-2010, 01:04 PM   #2
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Originally Posted by CartmanYO View Post
$(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.
1 members found this post helpful.
Old 06-11-2010, 03:28 AM   #3
LQ Newbie
Registered: Jun 2009
Posts: 27

Original Poster
Rep: Reputation: 1
Thanks a lot! It works now.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
static linking in gcc lavixu Linux - Newbie 1 11-27-2009 08:07 AM
gcc errors on static, but NOT dynamic, linking MALDATA Programming 5 10-03-2008 12:20 AM
Linking error. static const int kerenLinuxForum Linux - Software 1 08-28-2008 08:18 AM
Finding and Linking Static Libraries with gcc neorich Programming 15 08-10-2003 05:03 PM
gcc linking error. ugenn Linux - Software 0 01-23-2003 12:18 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:46 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration