LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-27-2003, 06:04 PM   #1
WanglessOlasov
Member
 
Registered: Jul 2003
Distribution: Slackware 9.0
Posts: 45

Rep: Reputation: 15
trouble linking with g++


Hi, i'm trying to start on my science fair project, in which i'll be programming... a LOT. I've done a little c++ before, but never on linux, and i'm having some trouble compiling some sample code. I'm using the c++ libraries for player/stage, all of which can be found on playerstage.sourceforge.net. I installed player and stage, as well as all the libraries for c++. What i believe are the library files (like i said, i'm not too familiar with this stuff... they're binary files that end in ".a" so i'm assuming that they're libraries) are in /usr/local/lib/, and the header files are in /usr/local/include/. They gave me some sample code called forage.cc, but when i try to compile it with g++ -o forage forage.cc, it doesn't compile and i get this output (i don't know how much is really needed, so i'll post it all):

Code:
~g++ -o forage forage.cc                                                                                                     
/tmp/cc0PnmXM.o(.text+0x212): In function `main':
: undefined reference to `PlayerClient::PlayerClient[in-charge](char const*, int)'
/tmp/cc0PnmXM.o(.text+0x260): In function `main':
: undefined reference to `BlobfinderProxy::BlobfinderProxy[in-charge](PlayerClient*, unsigned short, unsigned char)'
/tmp/cc0PnmXM.o(.text+0x2d0): In function `main':
: undefined reference to `PlayerClient::Read()'
/tmp/cc0PnmXM.o(.text+0x2f0): In function `main':
: undefined reference to `PositionProxy::Print()'
/tmp/cc0PnmXM.o(.text+0x30f): In function `main':
: undefined reference to `GripperProxy::SetGrip(unsigned char, unsigned char)'
/tmp/cc0PnmXM.o(.text+0x4bf): In function `main':
: undefined reference to `GripperProxy::SetGrip(unsigned char, unsigned char)'
/tmp/cc0PnmXM.o(.text+0x74e): In function `main':
: undefined reference to `GripperProxy::SetGrip(unsigned char, unsigned char)'
/tmp/cc0PnmXM.o(.text+0x766): In function `main':
: undefined reference to `GripperProxy::SetGrip(unsigned char, unsigned char)'
/tmp/cc0PnmXM.o(.text+0x838): In function `main':
: undefined reference to `BlobfinderProxy::~BlobfinderProxy [in-charge]()'
/tmp/cc0PnmXM.o(.text+0x8aa): In function `main':
: undefined reference to `PlayerClient::~PlayerClient [in-charge]()'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN8GpsProxyD1Ev+0xb): In function `GpsProxy::~GpsProxy [in-charge]()':
: undefined reference to `vtable for GpsProxy'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN8GpsProxyD1Ev+0x16): In function `GpsProxy::~GpsProxy [in-charge]()':
: undefined reference to `ClientProxy::~ClientProxy [not-in-charge]()'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN8GpsProxyC1EP12PlayerClientth+0x32): In function `GpsProxy::GpsProxy[in-charge](PlayerClient*, unsigned short, unsigned char)':
: undefined reference to `ClientProxy::ClientProxy[not-in-charge](PlayerClient*, unsigned short, unsigned short, unsigned char)'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN8GpsProxyC1EP12PlayerClientth+0x3e): In function `GpsProxy::GpsProxy[in-charge](PlayerClient*, unsigned short, unsigned char)':
: undefined reference to `vtable for GpsProxy'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN12GripperProxyD1Ev+0xb): In function `GripperProxy::~GripperProxy [in-charge]()':
: undefined reference to `vtable for GripperProxy'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN12GripperProxyD1Ev+0x16): In function `GripperProxy::~GripperProxy [in-charge]()':
: undefined reference to `ClientProxy::~ClientProxy [not-in-charge]()'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN12GripperProxyC1EP12PlayerClientth+0x32): In function `GripperProxy::GripperProxy[in-charge](PlayerClient*, unsigned short, unsigned char)':
: undefined reference to `ClientProxy::ClientProxy[not-in-charge](PlayerClient*, unsigned short, unsigned short, unsigned char)'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN12GripperProxyC1EP12PlayerClientth+0x3e): In function `GripperProxy::GripperProxy[in-charge](PlayerClient*, unsigned short, unsigned char)':
: undefined reference to `vtable for GripperProxy'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN13PositionProxyD1Ev+0xb): In function `PositionProxy::~PositionProxy [in-charge]()':
: undefined reference to `vtable for PositionProxy'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN13PositionProxyD1Ev+0x16): In function `PositionProxy::~PositionProxy [in-charge]()':
: undefined reference to `ClientProxy::~ClientProxy [not-in-charge]()'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN13PositionProxyC1EP12PlayerClientth+0x32): In function `PositionProxy::PositionProxy[in-charge](PlayerClient*, unsigned short, unsigned char)':
: undefined reference to `ClientProxy::ClientProxy[not-in-charge](PlayerClient*, unsigned short, unsigned short, unsigned char)'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN13PositionProxyC1EP12PlayerClientth+0x3e): In function `PositionProxy::PositionProxy[in-charge](PlayerClient*, unsigned short, unsigned char)':
: undefined reference to `vtable for PositionProxy'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN13PositionProxy8SetSpeedEii+0x12): In function `PositionProxy::SetSpeed(int, int)':
: undefined reference to `PositionProxy::SetSpeed(int, int, int)'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN10SonarProxyD1Ev+0xb): In function `SonarProxy::~SonarProxy [in-charge]()':
: undefined reference to `vtable for SonarProxy'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN10SonarProxyD1Ev+0x16): In function `SonarProxy::~SonarProxy [in-charge]()':
: undefined reference to `ClientProxy::~ClientProxy [not-in-charge]()'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN10SonarProxyC1EP12PlayerClientth+0x32): In function `SonarProxy::SonarProxy[in-charge](PlayerClient*, unsigned short, unsigned char)':
: undefined reference to `ClientProxy::ClientProxy[not-in-charge](PlayerClient*, unsigned short, unsigned short, unsigned char)'
/tmp/cc0PnmXM.o(.gnu.linkonce.t._ZN10SonarProxyC1EP12PlayerClientth+0x3e): In function `SonarProxy::SonarProxy[in-charge](PlayerClient*, unsigned short, unsigned char)':
: undefined reference to `vtable for SonarProxy'
collect2: ld returned 1 exit status
I really have no experience with g++, and no idea how to fix this... but i really need help, becuase a big grade depends on me writing this really big program, and so far im' not even able to compile using the player/stage libraries... not a good thing. Please help.
 
Old 12-28-2003, 12:58 AM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
you need to give gcc the library to link to with the -l option. read up on 'man gcc' and the documents that came with your library. they should tell you the name of it. if they dont, have a look in the /usr/local/lib directory and find the name of the library file.
example:
libpthread.a is the file, so you give gcc this option 'gcc my_file.c -lpthread'
 
Old 12-28-2003, 11:40 AM   #3
WanglessOlasov
Member
 
Registered: Jul 2003
Distribution: Slackware 9.0
Posts: 45

Original Poster
Rep: Reputation: 15
I'm not sure i understand... the "-l" option takes a directory and a library, right? Well, these libraries are in /usr/local/lib/, but there are a lot of them, all called libplayer*.a, where "*" is just "client" or "packet" or something like that... there are about 5 or 6 of them. So you're saying that if this file is called "forage.cc", i would just do "g++ forage.cc -o forage -l/usr/local/lib/playerclient" ? See, what i don't understand is 1) there are more than one player libraries, so how do i know which one to name on the command line, and 2) if it's called "libplayerclient.a", do i just call it "playerclient" on the command line, or the full name of "libplayerclient.a"? Also, do i have to specify the directory, because you didn't, but the man page said it needed a directory... thanks for your help, but some elaboration would be appreciated. Like i said, i'm new to this, so i'm still sort of in the dark.
 
Old 12-28-2003, 12:18 PM   #4
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
i'd just play around with all those until you find what works. you only need to use the libraries that define symbols you need. so if your program uses a symbol from every lib you mentioned, then you're gonna have to link all of them, or read the docs for the lib more closely.
 
Old 12-28-2003, 12:19 PM   #5
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
http://www.linuxquestions.org/questi...hreadid=129226

^^like what i advised in there.
 
Old 12-28-2003, 12:25 PM   #6
WanglessOlasov
Member
 
Registered: Jul 2003
Distribution: Slackware 9.0
Posts: 45

Original Poster
Rep: Reputation: 15
YES! I got it! all i had to do was list the libraries, with no extra flags, after the source file, like this: "g++ forage.cc /usr/local/lib/libplayer* -o forage" and it worked! I have no idea why, but i'm not complaining. Thanks for your help.
 
  


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
Trouble: mounting, linking, permissions. crackery Linux - Newbie 2 01-28-2005 09:03 PM
g++ trouble linking against archive exitsfunnel Programming 3 01-05-2005 09:16 AM
Trouble linking with libmqueue on Linux 2.6.5 -mm illuminatedwax Programming 0 04-14-2004 07:55 AM
trouble ahead, trouble behind....trouble with mplayer Goonie Linux - Software 3 07-02-2003 02:29 AM
C++ linking? ugenn Programming 5 05-14-2002 01:33 AM

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

All times are GMT -5. The time now is 08:19 PM.

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