ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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'
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.