LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 03-15-2013, 11:52 PM   #1
ajrmoore
LQ Newbie
 
Registered: Mar 2013
Location: Canada
Distribution: Fedora 18
Posts: 3

Rep: Reputation: 0
Problems statically linking C program to ncurses


Greetings everyone. I've been having issues trying to statically build a C file on my machine with ncurses. I have the ncurses-static and glibc-static libraries installed on my computer and have tried compiling with gcc -c test.c -o test.o

That works fine. But when I try to link with this:

ld test.o -o test -static -lncurses

I get a lot of errors for undefined referrences. Many of them are to SP but there are others as well. There are way too many errors to include them all here, but here's a snippet:

(.text+0x864): undefined reference to `tparm'
/lib/libncurses.a(lib_mvcur.o): In function `relative_move.constprop.2':
(.text+0x876): undefined reference to `_nc_str_copy'
/lib/libncurses.a(lib_mvcur.o): In function `relative_move.constprop.2':
(.text+0x882): undefined reference to `_nc_safe_strcat'
/lib/libncurses.a(lib_mvcur.o): In function `relative_move.constprop.2':
(.text+0x88f): undefined reference to `SP'
/lib/libncurses.a(lib_mvcur.o): In function `relative_move.constprop.2':
(.text+0x89e): undefined reference to `cur_term'
/lib/libncurses.a(lib_mvcur.o): In function `relative_move.constprop.2':
(.text+0x900): undefined reference to `_nc_safe_strcat'
/lib/libncurses.a(lib_mvcur.o): In function `relative_move.constprop.2':
(.text+0x958): undefined reference to `_nc_safe_strcat'
/lib/libncurses.a(lib_mvcur.o): In function `relative_move.constprop.2':
(.text+0x96e): undefined reference to `SP'
/lib/libncurses.a(lib_mvcur.o): In function `relative_move.constprop.2':
(.text+0x98a): undefined reference to `SP'
/lib/libncurses.a(lib_mvcur.o): In function `relative_move.constprop.2':
(.text+0x9aa): undefined reference to `SP'
/lib/libncurses.a(lib_mvcur.o): In function `relative_move.constprop.2':
(.text+0x9bd): undefined reference to `SP'
/lib/libncurses.a(lib_mvcur.o): In function `relative_move.constprop.2':
(.text+0x9fa): undefined reference to `SP'
/lib/libncurses.a(lib_mvcur.o).text+0xa0d): more undefined references to `SP' follow

Am I just passing the wrong arguments to gcc/ld or is there something more serious happening? I've tried checking various websites through Google but I can't seem to find a solution. The program does build dynamically with gcc test.c -o test -lncurses with no warnings or errors. I probably left out some information which would be useful and if so, please let me know and I will provide it here.
 
Old 03-16-2013, 04:13 AM   #2
Slackyman
Member
 
Registered: Mar 2011
Location: Rome - Italy
Distribution: Slackware 13.1
Posts: 347

Rep: Reputation: 44
Try:
Quote:
ld test.o -lncurses -static -o test
or try to give it the static lib itself like
Quote:
ld test.o /usr/lib/libncurses.a -static -o test
 
1 members found this post helpful.
Old 03-16-2013, 09:39 AM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
You need to link libtinfo as well (shared libraries pull in their dependencies automatically which is why you don't need it normally). Also, it's easier to link with gcc instead of ld because gcc knows all the basic system libraries that are needed:
Code:
gcc hello-ncurses.o -o hello-ncurses -static -lncurses -ltinfo
 
3 members found this post helpful.
Old 03-16-2013, 06:15 PM   #4
ajrmoore
LQ Newbie
 
Registered: Mar 2013
Location: Canada
Distribution: Fedora 18
Posts: 3

Original Poster
Rep: Reputation: 0
Thumbs up

Thanks ntubski, what you suggested worked perfectly. No problems at all now :-)
 
  


Reply



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
Cygwin and libcurl - problem with linking statically NTxC Programming 1 04-15-2012 05:49 AM
[SOLVED] Statically linking an extremely simple c++ program using g++. c_moriarty Programming 15 04-30-2011 11:54 AM
Statically linking to libraries lazylogik Linux - Newbie 1 07-06-2009 11:43 AM
implication of statically linking to libstdc++ zero79 Linux - General 3 04-08-2006 01:03 PM
Problems statically linking with libsdl jakobf Programming 3 08-27-2004 12:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:34 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration