Search code examples
c++eclipse-cdtsimulatorplayer-stage

Code Building Error in Eclipse CDT for Player/Stage simulator


I am using Player/Stage for my thesis work. But, I am getting undefined reference error messages while I want to build this code in Eclipse CDT-

#include <iostream>
#include <playerc++.h>
#include <playerclient.h>
#include <clientproxy.h>
using namespace std;

int main()
{
PlayerClient robot("localhost",6665);
return 0;
}

The error message is:

08:40:02 **** Build of configuration Debug for project firstTest ****
make all
Building file: ../src/firstTest.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/player-3.0/libplayerc++ -include/usr/local/include/player-3.0/libplayerc++/playerc++.h -include/usr/local/include/player-3.0/libplayerc++/clientproxy.h -include/usr/local/include/player-3.0/libplayerc++/playerc++config.h -include/usr/local/include/player-3.0/libplayerc++/playerclient.h -include/usr/local/include/player-3.0/libplayerc++/playererror.h -include/usr/local/include/player-3.0/libplayerc++/utility.h -O0 -g3 -Wall -c -fmessage-length=0 `pkg-config --cflags playerc++` -MMD -MP -MF"src/firstTest.d" -MT"src/firstTest.d" -o "src/firstTest.o" "../src/firstTest.cpp"
Finished building: ../src/firstTest.cpp
Building target: firstTest
Invoking: GCC C++ Linker
g++ `pkg-config --libs playerc++` -o "firstTest" ./src/firstTest.o
./src/firstTest.o: In function `main':
/home/nafees/workspace/firstTest/Debug/../src/firstTest.cpp:19: undefined reference to `PlayerCc::PlayerClient::PlayerClient(std::string, unsigned int, int)'
/home/nafees/workspace/firstTest/Debug/../src/firstTest.cpp:19: undefined reference to `PlayerCc::PlayerClient::~PlayerClient()'
collect2: error: ld returned 1 exit status
make: *** [firstTest] Error 1

08:40:02 Build Finished (took 514ms)

I have followed this nice tutorial posted by Jenny- http://yorkroboticist.blogspot.com/2010/03/playerstage-on-eclipse.html

In this link you will get the snapshots of my Eclipse Project Properties: https://www.dropbox.com/sh/9hcmditufu0lt6v/AAChqD1-FMM9FhvTWpuOGMQ-a?dl=0

I have tried a lot of ways to remove this error. but, all in vein. Please help me to continue my thesis.

With thanks Nafees


Solution

  • I have figured out the "undefined reference" problem.....

    If anyone wants to use eclipse CDT for stage/player simulation, please follow these steps. I am assuming that you have installed the Player/Stage properly.

    1. Go to Project Properties.

    2. Expand C/C++ Build.

    3. Click on Settings.

    4. If you want to build C++ code, follow these steps-

      • Under GCC C++ Compiler, click on Miscellaneous tab.

      • There is a box named "Other flags". Paste this line(with ` symbols) on the box-

      `pkg-config --cflags playerc++`

      • caution: Never edit the existing lines in the box. Just paste the above line beside the existing line with an space. And keep in mind ' and ` is not same.

      • Then, go to includes/directories(name may vary according to eclipse version) tab. There is an "include paths(-I)" box. click on add button and navigate to- Computer > usr > local > include > Player- x.x and press ok.

    5. If you want to build C code, Skip number 4 instruction and follow these steps instead-

      • Under GCC C Compiler, click on Miscellaneous.

      • There is a box named "Other flags". Paste this line (with ` symbol) on the box-

      `pkg-config --cflags playerc`

      • caution: Never edit the existing lines in the box. Just paste the above line beside the existing one it with an space. And keep in mind ' and ` is not same

      • Go to includes/directories(names may vary according to eclipse version) tab. There is an "include paths(-I)" box. click on add button and navigate to- Computer > usr > local > include > Player- x.x and press ok.

    6. Now, The most important steps come here. Under GCC C++ Linker, click on Miscellaneous tab. There is a box named "Linker flags".

      • if you are using C++, paste the following line-

      `pkg-config --libs playerc++`

      • If you are using C, paste the following line instead of the above-

      `pkg-config --libs playerc`

      • Now, go to Libraries tab and there you will see "Libraries (-l)" box. Press add button and

      • If you are using C++, paste the line-

      playerc++

      • If you are using C, paste the following line instead of the above-

      playerc

      • Finally, there is a box named "Library search path (-L)" beneath. Click on add button and navigate to- Computer > usr > local > lib and click ok.

    Thats it....... Now try to compile and build an example code. :) :) :)