Code Building Error in Eclipse CDT for Player/Stage simulator - c++

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

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.
Go to Project Properties.
Expand C/C++ Build.
Click on Settings.
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.
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.
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. :) :) :)

Related

Using CodeLite IDE for OpenCV in Ubuntu 16.04 LTS

I can compile a sample C++ Code (including OpenCV) using both CMake and following command line:
g++ cv.cpp -o cvapp pkg-config --cflags --libs opencv
But I want to use CodeLite IDE for this purpose. I have added
/usr/include/opencv;/usr/include/opencv2
in the Include Paths under compiler tab in project settings. And added
/usr/local/lib
in Libraries Search Path under Linker tab.
But still, I am getting errors shown in this screenshot for a sample code.
Now is it possible to use CodeLite for OpenCV coding environment? If yes then how?
To use opencv in codelite the simplest option is to continue using pkg-config, you can do this as follows:
Right click on the project name and select settings...
2.Open the following dialog and select the Linker tab, in that window add pkg-config --cflags --libs opencv in linker-options:
Press the apply button and Ok and then compile the project.

how do I eliminate linker error mingw32/bin/ld.exe: cannot find -lSDL

I am trying to build SDL for use with Eclipse. I am trying to remove this linker error:
Beginning Compilation
21:15:53 **** Incremental Build of configuration Debug for project CMD ****
Info: Internal Builder is used for build
g++ "-IC:\\MinGW\\include\\SDL2" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\CMD.o" "..\\src\\CMD.cpp"
g++ -o CMD.exe "src\\CMD.o" -lmingw32 -lSDL -lSDL2main -lSDL2
ERROR(s):
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lSDL
collect2.exe: error: ld returned 1 exit status
21:15:54 Build Finished (took 1s.36ms)
The most pertinent SO archive source I researched didn't seem to have an actionable answer for my problem, though it had the exact same problem/error:
title --
producing the same error message:
c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../../mingw32/bin/ld.exe: cannot find -lSDL.
If you click to the authors "solution" for the same error as mine its not clear to me how he solved it.
Any help?
Problem solved, SDL2 awesome. Ok:
c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../../mingw32/bin/ld.exe: cannot find -lSDL.
Reinstallation of SDL2 avoiding binary conflict between SDL files and SDL2 files
as keltar mentioned resolved the immediate problem, and the problem built with no errors!Fixing what was in the braces unmasked new problem: crashing. I stripped the program to bare bones and concluded the crashing was outside of the code since it was occurring even without code.
To solve the new problem would need to go the SDL2 distribution file (the one copied to MinGW) and copy the SDL2.dll from it [DLL from distributable][1]--- by dragging the file over your debug and/or release folders where the .exe file lives.(.exe + dll -> right?) moving dll to exes. Build/Run the program
it should work!
You should see a Welcome message!
https://www.caveofprogramming.com/c-for-complete-beginners/setting-up-sdl-windows.html

C++ Not Finding Installed Library

I am desperately trying to install WebKitGTK+, but I have hit a two-hour impasse.
For one, the tarball provided on the website does not seem to follow any of the typical "build from source" conventions, and there are no instructions anywhere. Any build-from-source instructions they provide involve the unstable repository version, which I do not want to use...and anyhow, those do not seem to work.
I can find both the Webkit (libwebkitgtk-3.0-dev) and Webkit2 (libwebkit2gtk-3.0-dev) versions on the repository (I love Synaptic Package Manager), but though I've installed them, C++ (CodeBlocks) fails on...
#include <webkit/webkit.h>
It is worth noting that one of my employees installed the same package (libwebkitgtk-3.0-dev) successfully from the Debian Wheezy repositories, and he can use them in his code just fine, with the same import statement.
I added the path to /usr/include/webkitgtk-3.0/webkit under Global Compiler Settings --> Search Directories --> Compiler. My employee and I both have the exact same paths to this library added - his work, mine don't.
I'm losing my mind now. Help?
In Codeblocks go to the Project Build Options settings. You can get there by right clicking on the project in the "Projects Management" panel on the left side of the screen and choosing 'Build Options' then clicking on the project itself(NOT just the debug/release options) in the window that shows up. Click the "Search Directories" tab and in the compiler subtab you will need to enter the following path:
/usr/include/webkitgtk-3.0/
When adding them make sure you DO NOT add it as a relative path. Additionally in the "Compiler Settings" -> "Other Options" tab you might need to add one or more of:
`pkg-config --cflags gtk+-3.0 `
`pkg-config --cflags glib-2.0 `
`pkg-config --cflags pango `
`pkg-config --cflags cairo `
`pkg-config --cflags gdk-pixbuf-2.0 `
`pkg-config --cflags atk `
`pkg-config --cflags libsoup-2.4 `
On my system I could not get pkg-config to work for webkitgtk itself.

Setting up GTKmm in Eclipse for C++

I am trying to create a GUI using GTKmm in Eclipse, however I can't get the configuration working. For reference, here is my actual code:
#include <gtkmm.h>
using namespace std;
int main(int argc, char **argv) {
Gtk::Main kit(argc,argv);
Gtk::Window frmMain;
kit.run(frmMain);
return 0;
}
These are the settings I have entered under the GCC C++ Compiler section.
All options:
-I/usr/include/gtkmm-3.0 -I/usr/include/gdkmm-3.0 -I/usr/include/gtk-3.0 -O0 -g3 -Wall
and for Command Line Pattern:
${COMMAND} `pkg-config gtkmm-3.0 --cflags` ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}
Finally, under the GCC G++ Linker section, I have this entered for the Command Line Pattern:
${COMMAND} `pkg-config gtkmm-3.0 --libs` ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} ${FLAGS}
Here is a link to my compile log:
http://pastebin.com/tfqv97w6
I can't put this in the comments they are too restrictive. These are the steps I have just gone through to make a gtkmm program in my eclipse. I followed the procedure twice and it worked both times.
Create Project:
File -> New -> C++ Project
Project Type: Executable -> Hellow World Gtkmm Project
Toolchains: Linux GCC
Project Properties:
C/C++ Build -> Settings -> Pkg-config -> gtkmm-3.0
See if that works for you.
I have a brief article about this (with screenshots), see it here:
http://www.hamedandobaideh.com/index.php/9-uncategorised/73-gtkmm-with-eclipse
I performed two test. One with your source instance and one with an instance from a simple file from the site. Both worked flawlessly the first time using the steps below.
A Hello World example from the gtkmm website with Success:
https://git.gnome.org/browse/gtkmm-documentation/tree/examples/book/helloworld
First I installed the pkg-config Eclipse Plugin:
https://code.google.com/p/pkg-config-support-for-eclipse-cdt/
Then:
Created a new empty C++ project in Eclipse
Added three files to the project (helloworld.cpp, helloworld.h,
main.cc)
Added pkg-config-support to the project: [(right click on Project) -> Properties -> C++
Build -> Settings -> Pkg-config -> (checkmark) gtkmm-3.0 -> OK
From Eclipse I Cleaned, then Build all, then was able to Run the
example.

MinGW .exe requires a few gcc dll's regardless of the code?

When compiling with MinGW, I have to copy over certain dll files from the MinGW bin directory before the exe will run (Even when using "-static" and/or "-static-libstdc++".)
How do I change that? Is there a special build of MinGW that I have to use? Ultimately I want to be able to run the program with nothing but the exe in the directory (and no windows environment variables set.) These File's are:
libstdc++-6.dll
libgcc_s_seh-1.dll
libwinpthread-1.dll
And here is the complete list of step's I fallow:
Open Up Code::Blocks
Select "File->New->Project->Console"
Fill out the project settings for project "Hello World"
Right click Project->Build Options...->Hello World (Root target)->Other Options
Enter "-static" (or "-static-libstdc++") under the already set "-fexceptions"
CTRL-F9 : Build Project (Without executing)
Navigate to, in Windows Explorer, and run the built "Hello World.exe" file.
Click "OK" when a message pop's up saying "Error: libstdc++-6.dll is missing from your computer."
Copy "libstdc++-6.dll" from the /MinGW/bin/ directory, into the "Hello World.exe" directory.
Run "Hello World.exe"
Click "OK" for the message saying "Error: libgcc_s_seh-1.dll is missing from your computer."
Copy "libgcc_s_seh-1.dll" into the "Hello World.exe" directory.
Repeat and end up copying "libwinpthread-1.dll" over aswell.
View the message
Hello World!
Edit:
My command line is:
g++.exe -Wall -fexceptions -static -static-libgcc -static-libstdc++ -g -static-libgcc -static-libstdc++ -L. -c "C:\Users\______\Desktop\Hello World\main.cpp" -o obj\Debug\main.o
g++.exe -o "bin\Debug\Hello World.exe" obj\Debug\main.o
With all the dll files mentioned above required. And, just to be safe, the code is:
// main.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
Your commands are wrong !
Go to the directory where your main.cpp file is, and try the following.
g++.exe -Wall -c -g main.cpp -o obj\Debug\main.o
g++.exe -static -static-libgcc -static-libstdc++ -o "bin\Debug\Hello World.exe" obj\Debug\main.o
then you'll no longer need to copy the DLLs (for your Hello World program).
Other notes:
The MinGW installation instructions recommends setting
c:\minGW;c:\MinGW\bin;
to the PATH environment variable.
Normally the
-static -static-libgcc -static-libstdc++
linker options should work (try all 3 of them at once). But not for libwinpthread-1.dll.
Also, try to clean before recompiling.
There's no "-static-something" command.
Only standard libraries libgcc and libstdc++ can be set to static linking.
For other libraries, you first switch to static linking with "-static" and then list the libraries to include with separate commands, i.e. "-lpthread".
Cmake users should try adding:
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ -lwsock32 -lws2_32 ${CMAKE_CXX_STANDARD_LIBRARIES}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")
-static-libgcc may be a bad idea if exceptions are used. link options documentation states that
There are several situations in which an application should use the
shared libgcc instead of the static version. The most common of these
is when the application wishes to throw and catch exceptions across
different shared libraries. In that case, each of the libraries as
well as the application itself should use the shared libgcc.
The comments to the answer above contain the full solution, so I would like to merely add the CodeBlocks perspective. I verified it on Windows7 x64 with CodeBlocks16 and MinGW-W64 8.1.0 ''i686-posix-dwarf''.
This solves the OPs question
Create new project and name it "Hello World"
accept all defaults in the wizard
select Project/BuildOptions/ and select "Hello World". Out edits will be valid for both Debug and Release
add the following at "Other linker option" in the "Linker" Tab
-static
-static-libgcc
-static-strc++
-lwinpthread
On the Toolbar select "Debug" and press Build (the yellow gear icon)
Press the green run icon and confirm that the build was ok
Testing
open a terminal window and go to the HelloWorld\bin\debug folder
start hello world there.
Confirm it works without asking for any DLLs.
You could also start it from an explorer window and confirm that it also does not ask for DLLs.
Note: On my Win7x64 system when starting the HelloWorld.exe from the explorer adding the "-lwinpthread" line causes CodeBlocks to ignore the setting in "Projects/Properties/Tab_BuildTargets/ "Pause when execution ends". So the "Hello World" output is hardly visible because the window immediately closes after execution (mabye someone knows why)
Note that if you do not have the winpthread.dll not found problem of the OP then you likely do not use a MinGW-W64 compiler with a 'posix' thread model. Both Code blocks MinGW-W64-bundled install packages use such versions. For CB20.03 the relevant downloads from MinGW-W64 download page would be
32bit: 8.1.0 ''i686-posix-dwarf''
64bit: 8.1.0 ''x86_64-posix-seh''
For example if I set setup compilers with Codeblocks direcly and chose the 32-bit compiler package ''i686-win32-dwarf'', only the first 2 DLLs would go missing. In that case the fix is to set the linker options only to
-static-libgcc
-static-strc++