LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 09-22-2005, 11:48 AM   #1
Liche
LQ Newbie
 
Registered: Sep 2005
Posts: 5

Rep: Reputation: 0
gcc Linker error - please help!


Am starting out in gcc/linux and am porting an application from MSVCPP6 into gcc (yes, I've finally seen the light...). I've hit a number of problems and figured them out, but this one has me stumped.

The program compiles fine, but on linking I get a ton of errors like this:
Code:
/tmp/cckguNaH.o(.gnu.linkonce.t._ZNSt4listIP11HornElementSaIS1_EEaSERKS3_+0x67): In function `std::list<HornElement*, std::allocator<HornElement*> >::operator=(std::list<HornElement*, std::allocator<HornElement*> > const&)':

: undefined reference to `int operator!=<std::_List_iterator<HornElement*, HornElement*&, HornElement**> >(std::_List_iterator<HornElement*, HornElement*&, HornElement**> const&, std::_List_iterator<HornElement*, HornElement*&, HornElement**> const&)'
(HornElement is a class in the program). All the errors refer to 'list' in some way - I'm using the STL list template. I've tried linking in with -lstdc++ and --static -lstdg++ but this makes no difference.

The application requries GALib (standard genetic algorithm library), which I'm linking to - its examples run fine, and I've checked the include/link phases with short test programs and they compile/link/build/run fine - I don't think the problem is here but thought I'd mention it. This is what the -lga command links in. (I installed and 'make'd this myself, and this is a new concept for me so it is conceivable that I got it wrong, but I don't think so as I've successfully linked things to libga.a)

Here is the build command:

g++ main.cpp -Wall -I../include -L../lib -lga -lm

(The -I and -L paths are correct and have been verified separately). I should mention that the program is spread over a number of other .h/.cpp files I wrote which are #included in main.cpp - this all compiles fine.

'g++ -v' gives:

Code:
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-52)
Running
g++ main.cpp -shared -Wall -I../include -L../lib -lga -lm
compiles and links, but on running ./a.out immediately crashes with 'Segmentation Fault''

I'm utterly stuck on this and will be very grateful for any help; I'll gladly provide any more information that I have omitted here.

Thanks

 
Old 09-22-2005, 03:48 PM   #2
JCipriani
Member
 
Registered: Aug 2005
Location: Pittsburgh, PA, USA
Distribution: Redhat 9, OS X 10.4.x, Win2K
Posts: 85

Rep: Reputation: 15
Looks like you have a != operator declared somewhere that you aren't actually defining. Did you write HornElement? Are you using it in a way where you have to explicitly instantiate a HornElement but you aren't, because the MS compiler let it slide?

Also, check this out. It's a handy utility that will take weird error messages involving templates and STL objects and "decode" them into more easily readable messages.

Quote:
Am starting out in gcc/linux and am porting an application from MSVCPP6 into gcc (yes, I've finally seen the light...).
PS: Don't get your hopes up just yet. VS 6 has, honestly, one of the best C/C++ IDE's that I've ever worked with. Mostly because it's debugger beats gdb+ddd any day. Too bad the editor isn't like xemacs though
 
Old 09-23-2005, 03:03 AM   #3
Liche
LQ Newbie
 
Registered: Sep 2005
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for your response. The error messages all refer to either != or == operators on _List_iterator; the program implements list<HornElement*>. I have tried adding an explicit instantiation
Code:
 template class list<HornElement*>
in various places (can't say I fully understand what I'm doing with this) but it doesn't seem to help. HornElement is my code - exactly when would it 'need' instantiation? Exactly how should I go about doing this?

Many thanks.
 
Old 09-24-2005, 11:17 PM   #4
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 51
the -shared flag tells the linker to create a shared library (*.so) not an executable
Quote:
I should mention that the program is spread over a number of other .h/.cpp files I wrote which are #included in main.cpp - this all compiles fine.
this is what's comfusing
you need to compile them other .cpp files into objects
and then link them all together
g++ -c main.cpp
g++ -o programname main.o otherobject.o otherobject2.o -I../include -L../lib -lga -lm

time to write yourself a Makefile !
 
Old 09-26-2005, 06:11 AM   #5
Liche
LQ Newbie
 
Registered: Sep 2005
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the tip - have tried compiling piecemeal and linking the objects together, but the error messages remain.

I now don't think this is directly a problem with linking; I suspect there is some error in my STL usage that is thrown during linking.

Do I need to define != and == operators on T to use std::_List_iterator<T> ? If so, where?

(none of this came up with MSVCPP6 )

Last edited by Liche; 09-26-2005 at 06:14 AM.
 
Old 09-26-2005, 07:14 AM   #6
Liche
LQ Newbie
 
Registered: Sep 2005
Posts: 5

Original Poster
Rep: Reputation: 0
Have fixed the problem. Turns out there was some wierd conflict with GALib - including certain header files affected how gcc treated list<T>::iterator and const_iterator in const functions. Don't fully understand the exact reason for the problem but appear to have fixed it satisfactorily. Thanks for your help.

Last edited by Liche; 09-26-2005 at 08:31 AM.
 
  


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
ld linker error Ankit mittal Programming 2 09-30-2005 07:40 AM
the linker is not working (gcc ) abd_bela Ubuntu 1 09-13-2005 03:51 PM
gcc linker question alenD Programming 2 08-01-2005 09:31 PM
Linker error eddydw Linux - General 0 09-20-2004 01:21 PM
Linker Error dim79 Programming 2 06-28-2003 09:53 AM


All times are GMT -5. The time now is 11:24 PM.

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