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&)': 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 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 :newbie: |
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:
|
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*> Many thanks. |
the -shared flag tells the linker to create a shared library (*.so) not an executable
Quote:
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 ! |
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 ):confused: |
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.
|
All times are GMT -5. The time now is 12:58 PM. |