LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 06-10-2010, 10:03 AM   #1
CartmanYO
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:
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?

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

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

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


Reply


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 07:07 AM
gcc errors on static, but NOT dynamic, linking MALDATA Programming 5 10-02-2008 11:20 PM
Linking error. static const int kerenLinuxForum Linux - Software 1 08-28-2008 07:18 AM
Finding and Linking Static Libraries with gcc neorich Programming 15 08-10-2003 04:03 PM
gcc linking error. ugenn Linux - Software 0 01-22-2003 11:18 PM


All times are GMT -5. The time now is 05:39 AM.

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