Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 06-28-2003, 01:14 PM   #1
LQ Newbie
Registered: Jun 2003
Posts: 1

Rep: Reputation: 0
Question G++ Linking Error "undefined reference"

I have a program which works on windows and I'm trying to run it on my mandrake linux 8.0 I am using g++ (version 2.96) to compile my c++ code to object code with the following command:
g++ -c *.cpp

When I try to link it with this command:
g++ *.o

I even created a makefile but that doesnt seem to help.

I get undefined reference errors to classes which i myself have created(I know that to link the math libray I need to add the -lm flag but I still get errors from my own classes) How would I get g++ to link my own files correctly? Any help is appreciated...
Old 06-28-2003, 01:40 PM   #2
Senior Member
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
let a.C and b.C contain classes a and b respectivly and let class b require class a. now if they get linked like this:

g++ b.C a.C

then all is well because the linker links b and is now looking for class a which it then finds, if however they are linked like this:

g++ a.C b.C

then the linker links class a and promptly forgets about it, then links class b which has a reference to class a it cant find, hence the unresolved external. so im guessing that *.o is picking out the files in lexographical order and some symbols are getting missed, provide the object files in the correct order and that might fix things.

Old 04-13-2004, 10:36 AM   #3
Registered: Apr 2002
Location: Austin, TX
Distribution: Red Hat 7.2
Posts: 15

Rep: Reputation: 0
more linker problems

Hello everyone...
I am having a more simple linker error with RedHat 7.2 g++... I have only one class and the program is just one file. To one function call I pass an array the class, and it works fine. To the next function, I pass it again, and I get unresolved external classname[i].memberfuntionname().

Any help would be much appreciated!



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
Several "undefined reference to" error when compiling a C programm acer_peri Programming 8 12-11-2008 06:45 AM
"undefined reference"linker error for static field w/ C++ astorm Programming 5 08-27-2008 04:00 AM
Undefined Screen " XFree86" reference by serverLayout "XFree86 Configured" comox *BSD 7 01-17-2005 06:47 PM
Kernel make bzImage error "undefined reference" w/ Prism2.5 USB driver under 2.6 joachimvb Mandriva 1 09-24-2004 08:43 PM
ncurses compile error: "undefined reference" Mr. Eek Linux From Scratch 1 05-12-2003 05:25 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:23 PM.

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