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 02-14-2012, 06:13 PM   #1
John H.
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Rep: Reputation: Disabled
Undefined reference errors with static compile - dynamic works fine.


Trying to compile a program on Red Hat EL 6.2. It runs into "undefined reference" errors at link time. I've searched the web and attempted everything suggested. No luck.

One thing to note is it compiles fine when linked dynamically. It's only when we use the "-static" option it fails.

Also, the "-static" compile works fine on a CentOS 5.7 system.

Any suggestions beyond termcap and cuses libs are highly appreciated.

System info and errors follow. Note the "undefined reference" errors start in our own code, but then start lib the libcurses.a file.

Quote:
Library system info:

$ rpm -qa | grep curses
ncurses-5.7-3.20090208.el6.i686
ncurses-devel-5.7-3.20090208.el6.i686
ncurses-static-5.7-3.20090208.el6.i686
ncurses-base-5.7-3.20090208.el6.i686
ncurses-libs-5.7-3.20090208.el6.i686

$ rpm -qa | grep term
libtermcap-2.0.8-20.i386
termcap-9.12.6-15.i386

$ rpm -qa | grep gcc
libgcc-4.4.6-3.el6.i686
gcc-4.4.6-3.el6.i686
Quote:
Compile link errors:

/usr/bin/gcc [-I,<include directory>]... -O2 [-L<library path>]... -o <binary filename> [<object filename>]... [-l<libarary>].... -lcurses -static
dispproc.o: In function `prompt_pid':
dispproc.c.text+0x1d): undefined reference to `LINES'
dispproc.c(.text+0x3b): undefined reference to `COLS'

<... more .o files with undefined reference to `LINES` & `COLS` ...>

lib/libcursesutil.a(cursedfkeys.o): In function `initFkeyModule':
cursedfkeys.c: (.text+0x765): undefined reference to `cur_term'
cursedfkeys.c: (.text+0x7cc): undefined reference to `tparm'
cursedfkeys.c: (.text+0x7d4): undefined reference to `putp'
cursedfkeys.c: (.text+0xb2a): undefined reference to `tigetstr'

lib/libcursesutil.a(cursedfkeys.o): In function `initFkeyModule':
cursedfkeys.c: (.text+0xc60): undefined reference to `setupterm'

lib/libcursesutil.a(cursedwindow.o): In function `flushInput':
cursedwindow.c: (.text+0x127): undefined reference to `flushinp'

lib/libcursesutil.a(cursedwindow.o): In function `keypadOn':
cursedwindow.c: (.text+0x607): undefined reference to `keypad'

lib/libcursesutil.a(cursedwindow.o): In function `addChar':

lib/libcursesutil.a(cursedwindow.o): In function `resetShellMode':
cursedwindow.c: (.text+0x9f7): undefined reference to `reset_shell_mode'

lib/libcursesutil.a(cursedwindow.o): In function `resetProgramMode':
cursedwindow.c: (.text+0xa57): undefined reference to `reset_prog_mode'

lib/libcursesutil.a(cursedwindow.o): In function `defineShellMode':
cursedwindow.c: (.text+0xb47): undefined reference to `def_shell_mode'

lib/libcursesutil.a(cursedwindow.o): In function `defineProgramMode':
cursedwindow.c: (.text+0xba7): undefined reference to `def_prog_mode'

lib/libcursesutil.a(cursedshell.o): In function `cursed_shell_cmd':

lib/libcursesutil.a(cursedmisc.o): In function `enter_curses_mode':
cursedmisc.c: (.text+0x7e): undefined reference to `cbreak'

/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_addch.o): In function `waddch_nosync':
(.text+0xda): undefined reference to `unctrl'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_addch.o): In function `waddch_nosync':
(.text+0x4b2): undefined reference to `TABSIZE'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_addch.o): In function `_nc_waddch_nosync':
(.text+0x86c): undefined reference to `unctrl'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_addch.o): In function `_nc_waddch_nosync':
(.text+0x2c): undefined reference to `acs_map'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_box.o): In function `wborder':
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_box.o): (.text+0xc3): more undefined references to `acs_map' follow
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_delwin.o): In function `delwin':
(.text+0x21): undefined reference to `_nc_globals'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_delwin.o): In function `delwin':
(.text+0x99): undefined reference to `curscr'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_echo.o): In function `echo':
(.text+0x1): undefined reference to `SP'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_endwin.o): In function `endwin':
(.text+0x2f): undefined reference to `reset_shell_mode'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_getch.o): In function `_nc_wgetch':
(.text+0x1ef): undefined reference to `_nc_keypad'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_getch.o): In function `_nc_wgetch':
(.text+0x355): undefined reference to `_nc_timed_wait'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_getch.o): In function `_nc_wgetch':
(.text+0xa2d): undefined reference to `_nc_handle_sigwinch'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_getch.o): In function `_nc_wgetch':
(.text+0xa3d): undefined reference to `_nc_update_screensize'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_getstr.o): In function `wgetnstr':
(.text+0x10d): undefined reference to `_nc_get_tty_mode'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_getstr.o): In function `wgetnstr':
(.text+0x149): undefined reference to `noraw'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_getstr.o): In function `wgetnstr':
(.text+0x151): undefined reference to `cbreak'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_getstr.o): In function `wgetnstr':
(.text+0x156): undefined reference to `erasechar'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_getstr.o): In function `wgetnstr':
(.text+0x15e): undefined reference to `killchar'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_getstr.o): In function `wgetnstrb:
(.text+0x2bc): undefined reference to `_nc_set_tty_mode'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_initscr.o): In function `initscr':
(.text+0x12): undefined reference to `stdscr'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_initscr.o): In function `initscr':
(.text+0x22): undefined reference to `_nc_globals'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_initscr.o): In function `initscr':
(.text+0x5d): undefined reference to `def_prog_mode'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_initscr.o): In function `initscr':
(.text+0x62): undefined reference to `stdscr'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `repeated_append':
(.text+0x45): undefined reference to `_nc_safe_strcat'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `_nc_mvcur_resume':
(.text+0x68): undefined reference to `cur_term'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `_nc_mvcur_resume':
(.text+0x7a): undefined reference to `putp'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `_nc_mvcur_resume':
(.text+0x7f): undefined reference to `cur_term'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `_nc_mvcur_resume':
(.text+0xaa): undefined reference to `tparm'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `_nc_mvcur_resume':
(.text+0xb2): undefined reference to `putp'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `_nc_mvcur_resume':
(.text+0xe8): undefined reference to `curs_set'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `_nc_msec_cost':
(.text+0x2af): undefined reference to `_nc_prescreen'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `relative_move':
(.text+0xa0b): undefined reference to `_nc_str_copy'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `relative_move':
(.text+0xa23): undefined reference to `cur_term'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `relative_move':
(.text+0xa55): undefined reference to `_nc_safe_strcat'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `relative_move':
(.text+0xc79): undefined reference to `_nc_str_init'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `relative_move':
(.text+0xc7f): undefined reference to `cur_term'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `relative_move':
(.text+0xce8): undefined reference to `SP'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `relative_move':
(.text+0xd20): undefined reference to `_nc_safe_strcat'
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../libcurses.a(lib_mvcur.o): In function `relative_move':
(.text+0xd4a): undefined reference to `cur_term'

...
 
Old 02-15-2012, 02:48 AM   #2
NevemTeve
LQ Guru
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 5,078
Blog Entries: 1

Rep: Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935
Please paste here the link-command...
 
Old 02-16-2012, 03:40 PM   #3
John H.
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
no command line link used

I didn't explicitly type a link command - gcc deals with that. And all the gcc options that are used to execute the link command are listed.

Here's gcc -v output:

Quote:
/usr/bin/gcc -I../includes [-I
<include dir>]... -D__USE_SVID -v -O2 [-L<lib dir>]... -o <binary filename> <.o object file>... -l<libraries>... -lcurses -static

Using built-in specs.
Target: i686-redhat-linux

Configured with: ../configure
--prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap
--enable-shared --enable-threads=posix --enable-checking=release
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-ppl --with-cloog --with-tune=generic --with-arch=i686
--build=i686-redhat-linux

Thread model: posix
gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)

COMPILER_PATH=/usr/libexec/gcc/i686-redhat-linux/4.4.6/:/usr/libexec/gcc/i686-redhat-linux/4.4.6/:/usr/libexec/gcc/i686-redhat-linux/:/usr/lib/gcc/i686-redhat-linux/4.4.6/:/usr/lib/gcc/i686-redhat-linux/:/usr/libexec/gcc/i686-redhat-linux/4.4.6/:/usr/libexec/gcc/i686-redhat-linux/:/usr/lib/gcc/i686-redhat-linux/4.4.6/:/usr/lib/gcc/i686-redhat-linux/

LIBRARY_PATH=/usr/lib/gcc/i686-redhat-linux/4.4.6/:/usr/lib/gcc/i686-redhat-linux/4.4.6/:/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../:/lib/:/usr/lib/

COLLECT_GCC_OPTIONS='[-I <include dir>]... '-D__USE_SVID' '-v' '-O2'
'-L/home/herbergj/swdev/RedLinux2632x86D06p_branchopt/share/lib'
'-L/home/herbergj/swdev/RedLinux2632x86D06p_branchopt/sos/share/lib'
'-L/home/herbergj/swdev/RedLinux2632x86D06p_branchopt/share/lib' '-o' 'cvhost' '-static' '-mtune=generic' '-march=i686'

/usr/libexec/gcc/i686-redhat-linux/4.4.6/collect2 --build-id -m elf_i386
--hash-style=gnu -static -o <binary filename>
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../crt1.o
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../crti.o
/usr/lib/gcc/i686-redhat-linux/4.4.6/crtbeginT.o [-L<librar path>]....
-L/usr/lib/gcc/i686-redhat-linux/4.4.6 -L/usr/lib/gcc/i686-redhat-linux/4.4.6
-L/usr/lib/gcc/i686-redhat-linux/4.4.6/../../.. -l<library>... -lcurses
--start-group -lgcc -lgcc_eh -lc --end-group
/usr/lib/gcc/i686-redhat-linux/4.4.6/crtend.o
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../crtn.o
 
Old 02-17-2012, 02:20 AM   #4
NevemTeve
LQ Guru
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 5,078
Blog Entries: 1

Rep: Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935Reputation: 1935
Then please paste the command you gave to gcc to perform linking...
 
Old 02-17-2012, 10:20 AM   #5
John H.
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Maybe the fact that I've taken out the specifics that aren't applicable to the problem (or a solution ) caused confusion. But the gcc command has been included in both posts.

Items specific to my files, my libraries, and my include directories aren't included, but what is emphasized below is that I'm already linking in the curses library (that's the only -l for a library not developed by me) and we're specifying "-static".

/usr/bin/gcc -I../includes [-I <include dir>]... -D__USE_SVID -v -O2 [-L<lib dir>]... -o <binary filename> <.o object file>... -l<libraries>... -lcurses -static
 
Old 02-18-2012, 07:00 AM   #6
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
As it’s working with a dynamic link, it can point to circular references between the libraries. They would then be need to be put in a group for static linking:
Code:
-Wl,--start-group <lib1> <lib2> -Wl,--end-group
<libn> can be absolute paths or referenced by the -l option (man ld section “--start-group archives --end-group”).
 
Old 02-18-2012, 05:53 PM   #7
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,823

Rep: Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105
I don't think there is a circular reference, just libcurses depends on libtermcap, try adding -ltermcap after -lcurses.
 
Old 02-18-2012, 09:14 PM   #8
John H.
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Sadly, I have tried that one, but due to an error (and not understanding why a static compile would require a library that a dynamic does not), I gave-up on it. Assuming it will fix the problem though ...

where in the world can I find a static libtermcap library for Red Hat 6.2?

Output that shows current termcap libs installed & static compile error follow:

$ rpm -qa | grep termcap
libtermcap-2.0.8-20.i386
termcap-9.12.6-15.i386

$ ls /lib/*term*
/lib/libtermcap.so.2 /lib/libtermcap.so.2.0.8

Compile/link error with the "-static" option:

/usr/bin/ld: cannot find -ltermcap
collect2: ld returned 1 exit status
gmake: *** [cvhost] Error 1
 
Old 02-18-2012, 11:29 PM   #9
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,823

Rep: Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105Reputation: 2105
Quote:
Originally Posted by John H. View Post
not understanding why a static compile would require a library that a dynamic does not
Dynamic libraries pull in their dependencies automatically, but the same libraries are required in both cases.

Quote:
where in the world can I find a static libtermcap library for Red Hat 6.2?
(lib)termcap-devel, maybe?
 
Old 02-19-2012, 02:03 PM   #10
John H.
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
I would agree about the dynamic pulling dependencies in automatically, but the mystery is I didn't even have the termcap libs installed & the dynamic compile/link/execute of program all worked fine.

Will libtermcap* fix the static compile? I don't know, but I'm trying any option possible.

I'll let you know about the termcap-devel lib.

Thanks,
John
 
Old 02-20-2012, 02:51 AM   #11
John H.
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Update

I encompassed every library being linked with the -Wl,--start-group <lib1> <lib2> -Wl,--end-group and it still has the same problem.

My search for a package that actually has a static termcap library continues.

- JWH
 
Old 02-21-2012, 06:43 PM   #12
John H.
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Problem solved:

-lcurses -static doesn't cut it.

Either does -ltermcap.

What does is:

-lcurses -ltinfo -static

I'd guess libtinfo = terminfo library. terminfo replaced termcap.

John H.
 
1 members found this post helpful.
Old 02-22-2012, 02:24 AM   #13
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Quote:
Originally Posted by John H. View Post
I encompassed every library being linked with the -Wl,--start-group <lib1> <lib2> -Wl,--end-group and it still has the same problem.
You mean a list of all libraries you enclosed with the group statement, or each library in its own group?
 
Old 02-22-2012, 04:31 AM   #14
John H.
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
I threw all the libraries in one group. Didn't matter. As my last post said, the problem was solved by linking in libtinfo - no group statement.
 
  


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
undefined reference to `g_assertion_message_expr when trying to compile jpilot nowshining Linux - Software 1 04-28-2008 11:37 PM
ntpd - Undefined reference errors during install chris.zeman Linux - Software 1 08-03-2006 06:28 PM
linking problems - 'undefined reference' errors back2morrie Programming 1 06-14-2005 08:02 AM
Compile QT get Undefined reference jordban Linux - General 14 01-15-2005 06:58 PM
Undefined Reference errors during make. sheenak Programming 5 05-14-2004 06:14 AM

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

All times are GMT -5. The time now is 04:24 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