Compilation error with gtkmm - c++

I'm trying to compile a simple helloworld programme on eclipse using gtkmm and compiling with mingw32 through mingw32.
I followed these instructions to "install" gtkmm:
https://wiki.gnome.org/Projects/gtkmm/MSWindows
I also read a lot of threads about that topic but couldn't understand why i'm not able to compile this simple program:
#include <gtkmm.h>
int main(int argc, char** argv)
{
auto app = Gtk::Application::create(argc, argv);
Gtk::Window window;
window.set_default_size(600,400);
return app->run(window);
}
Through eclipse IDE i used the
project=>properties=>C/C++build=>settings=>pkg-config
and i enabled gtkmm-3.0.
Then i compile and i get the error:
Info: Configuration "Debug" uses tool-chain "MinGW GCC" that is unsupported on this system, attempting to build anyway.
Info: Internal Builder is used for build
g++ -I/mingw32/include/gtkmm-3.0 -I/mingw32/lib/gtkmm-3.0/include -I/mingw32/include/atkmm-1.6 -I/mingw32/include/gdkmm-3.0 -I/mingw32/lib/gdkmm-3.0/include -I/mingw32/include/giomm-2.4 -I/mingw32/lib/giomm-2.4/include -I/mingw32/include/pangomm-1.4 -I/mingw32/lib/pangomm-1.4/include -I/mingw32/include/glibmm-2.4 -I/mingw32/lib/glibmm-2.4/include -I/mingw32/include/gtk-3.0 -I/mingw32/include/cairo -I/mingw32/include -I/mingw32/include/pango-1.0 -I/mingw32/include/atk-1.0 -I/mingw32/include/cairomm-1.0 -I/mingw32/lib/cairomm-1.0/include -I/mingw32/include/pixman-1 -I/mingw32/include/freetype2 -I/mingw32/include/libpng16 -I/mingw32/include/harfbuzz -I/mingw32/include/glib-2.0 -I/mingw32/lib/glib-2.0/include -I/mingw32/include/sigc++-2.0 -I/mingw32/lib/sigc++-2.0/include -I/mingw32/include/gdk-pixbuf-2.0 -I/mingw32/includ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -o main.o "..\\main.cpp"
..\main.cpp:1:19: fatal error: gtkmm.h: No such file or directory
compilation terminated.
What is strange is that i can see in the compile log that it include everything needed for this program.
i also tried to add in
project=>properties=>C/C++build=>settings=>tool settings=> gcc c++
compiler and mingw linker
the result of pkg-config gtkmm-3.0 --cflags --libs but i get the exact same error.
It makes 2 days that i'm reading and trying the same propositions i found everywhere but coudn't get a result.
So please can someone try to help me to found a way to get this simple example to work.
thank you a lot
(ps: sorry for my mistakes)

I had the same problem, i solved it by manually adding all this path to include (Project Prorepties > C/C++ Build > Settings > GCC C++ Compiler > Includes > Include Paths (-I)):
"C:\msys64\mingw32\include\gtkmm-3.0"
"C:\msys64\mingw32\lib\gtkmm-3.0\include"
"C:\msys64\mingw32\include\glibmm-2.4"
"C:\msys64\mingw32\lib\glibmm-2.4\include"
"C:\msys64\mingw32\include\glib-2.0"
"C:\msys64\mingw32\lib\glib-2.0\include"
"C:\msys64\mingw32\include\sigc++-2.0"
"C:\msys64\mingw32\lib\sigc++-2.0\include"
"C:\msys64\mingw32\include\giomm-2.4"
"C:\msys64\mingw32\lib\giomm-2.4\include"
"C:\msys64\mingw32\include\gdkmm-3.0"
"C:\msys64\mingw32\lib\gdkmm-3.0\include"
"C:\msys64\mingw32\include\pangomm-1.4"
"C:\msys64\mingw32\include\gtk-3.0"
"C:\msys64\mingw32\include\pango-1.0"
"C:\msys64\mingw32\lib\pangomm-1.4\include"
"C:\msys64\mingw32\include\cairo"
"C:\msys64\mingw32\include\gdk-pixbuf-2.0"
"C:\msys64\mingw32\include\cairomm-1.0"
"C:\msys64\mingw32\include\freetype2"
"C:\msys64\mingw32\include\atkmm-1.6"
"C:\msys64\mingw32\include\atk-1.0"
"C:\msys64\mingw32\include\gtkmm-3.0"
"C:\msys64\mingw32\include\glibmm-2.4"
(You shoud replace "C:\msys64\mingw32" with your mingw32 path)
Also add -std=c++11 flag (Project Prorepties > C/C++ Build > Settings > GCC C++ Compiler > Miscellaneous > Other flags) and
glibmm-2.4
gtkmm-3.0
to (Project Prorepties > C/C++ Build > Settings > MinGW C++ Linker > Libraries (-l))

Related

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
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. :) :) :)

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.

Compiler Errors when trying to build very simple gtkmm app:

I installed gtkmm 3 on Ubuntu 13.04 using aptitude (I like aptitude because it remembers what was installed when you want to remove it):
sudo aptitude install libgtkmm-3.0-dev --with-recommends
Using codelite 5.1.2 and the default gtk++ tool chain, in my compiler include paths I added:
/usr/include/gtkmm-3.0 - the path to gtkmm.h
I tried to build the first sample app in Programming with GTKMM:
#include <gtkmm.h>
int main ( int argc, char *argv[] )
{
Gtk::Main kit ( argc, argv );
Gtk::Window window;
Gtk::Main::run ( window );
return 0;
}
After chasing down a few 'include file not found' errors coming from gtkmm.h, which includes the entire gtkmm framework, my compiler include path now looks like this:
/usr/include/gtkmm-3.0
/usr/include/glibmm-2.4
/usr/lib/i386-linux-gnu/glibmm-2.4/include
/usr/include/glib-2.0
And all hell is breaking loose from glib.h:
/bin/sh -c 'make -j 4 -e -f "Calendars_wsp.mk"'
----------Building project:[ CalendarsGUI - Debug ]----------
........
/gtkmm-3.0 -I/usr/include/glibmm-2.4 -I/usr/lib/i386-linux-gnu/glibmm-2.4/include -I//usr/include/glib-2.0
In file included from //usr/include/glib-2.0/glib/gtypes.h:36:0,
from //usr/include/glib-2.0/glib/galloca.h:34,
from //usr/include/glib-2.0/glib.h:32,
from /usr/include/glibmm-2.4/glibmm/thread.h:46,
from /usr/include/glibmm-2.4/glibmm.h:87,
from /usr/include/gtkmm-3.0/gtkmm.h:87,
from main.cpp:16:
***//usr/include/glib-2.0/glib/gversionmacros.h:179:2: error: #error "GLIB_VERSION_MIN_REQUIRED must be >= GLIB_VERSION_2_26"***
In file included from //usr/include/glib-2.0/glib/galloca.h:34:0,
from //usr/include/glib-2.0/glib.h:32,
from /usr/include/glibmm-2.4/glibmm/thread.h:46,
from /usr/include/glibmm-2.4/glibmm.h:87,
from /usr/include/gtkmm-3.0/gtkmm.h:87,
from main.cpp:16:
***//usr/include/glib-2.0/glib/gtypes.h:448:2: error: #error unknown ENDIAN type
.......
make: *** [All] Error 2
2 errors, 2 warnings***
(I also had the same problems when trying to use gtkmm 2.4)
Obviously I am missing something here. What am I doing wrong? What else do I need to do to build gtkmm projects?
When using gtkmm, its advised to use the pkg-config tool.
You can do this from codelite as well:
Right click on your project: Settings -> Common Settings -> Compiler -> C++ Compiler options:
and add:
$(shell pkg-config gtkmm-3.0 --cflags)
If you have another options, they should be semi-colon delimited
Next, add the following to the linker options:
Right click on your project: Settings -> Common Settings -> Linker -> Options:
$(shell pkg-config gtkmm-3.0 --libs)
again, if you have another options, they should be semi-colon delimited
Remove all the hard coded include paths you added the above 2 should suffice
Note:
This exact question was also answered on codelite's forum:
http://forums.codelite.org/viewtopic.php?f=11&t=1396&p=6416&hilit=gtkmm#p6410
Eran
Don't fiddle with includes, use pkg-config instead:
g++ foo.cc -o foo `pkg-config gtkmm-3.0 --cflags --libs`
btw, your example compiles and runs just fine.

How to make CDT/Eclipse work with C++11 threads?

I tried to test an example of C++11 threads in Eclipse. But I got this message when running the program:
terminate called after throwing an instance of 'std::system_error'
what(): Operation not permitted'
My system: ubuntu + gcc 4.7
Program:
#include <iostream>
#include <thread>
void worker()
{
std::cout << "hello from worker" << std::endl;
}
int main(int argc, char **argv)
{
std::thread t(worker);
t.join();
}
...and yes, I put -std=c++11 and -pthread inside C/C++ Build -> Settings -> Tool Settings -> Cross G++ Compiler -> Miscellaneous -> Other Flags.
Any comments?
The problem was solved by the comment of Jonathan Wakely.
I added -pthread to C/C++ Build -> Settings -> Tool Settings -> Cross G++ **Linker** -> Miscellaneous -> Other Flags and the program worked correctly.
Thank you Jonathan.
To work C++11 std::thread in Eclipse, one needs to give -pthread option while compiling. However that's not enough. In my Ubuntu 14.04, with Eclipse Kepler and g++4.9 below makes it work:
Right click on Project and select 'Properties'
Go to 'C/C++ Build' > 'Settings' > (tab) 'Tool Settings'
First select 'Cross G++ Compiler' > 'Miscellaneous' > 'Other flags';
and add
-pthread after -std=c++11
Second select 'Cross G++ Linker' > 'Libraries';
and add pthread (which is equivalent
to command line -lpthread)
Finally re-compile the project; the error should go.
Also remember that if you use, std::thread then its object must be join() somewhere. Else you may get below runtime error:
terminate called without an active exception
Go to Project > Properties > C/C++ General > Preprocessor include paths, etc > Providers > CDT GCC Builtin Compiler Settings and append -std=c++11 to the compiler specs.
You can also do this for all projects going to Window > Preferences > C/C++ > Build > Settings > Discovery and append -std=c++11 to the CDT GCC Builtin Compiler Settings specs.
${COMMAND} ${FLAGS} -E -P -v -dD -std=c++11 "${INPUTS}"
Project Properties > C/C++ Build > Settings > Tool Settings > GCC C++ Compiler > Miscellaneous > Other flags, add -pthread -std=c++11 -Wl,--no-as-needed:
-c -fmessage-length=0 -pthread -std=c++11 -Wl,--no-as-needed
Project Properties > C/C++ Build > Settings > Tool Settings > GCC C++ Linker > Miscellaneous > Linker flags, add -pthread -std=c++11 -Wl,--no-as-needed
-pthread -std=c++11 -Wl,--no-as-needed

Configure Eclipse CDT to use g++

I have cygwin installed, and I want to use Eclipse with CDT for development under Windows 7. However, I get following error:
**** Build of configuration Default for project hello_cpp ****
make all
g++ -O2 -g -Wall -fmessage-length=0 -c -o hello_cpp.o hello_cpp.cpp
process_begin: CreateProcess(C:\cygwin\bin\g++.exe, g++ -O2 -g -Wall -fmessage-length=0 -c -o hello_cpp.o hello_cpp.cpp, ...) failed.
make (e=5): Access denied.
make: *** [hello_cpp.o] Error 5
**** Build Finished ****
I'm able to use g++ as standalone compiler.
cygwin /bin folder is
added to path.
After googling I found out that C:\cygwin\bin\g++.exe is a cygwin symbolic link and Windows doesn't understand it and I need to point to the g++-3 location directly. How do I do it?
I think you've done something wrong and need to start over again. Just installed Cygwin and Eclipse CDT (Indigo) on my Windows 7 and all works fine and auto-magicaly for me.
Here's what I did and I think you need to do:
Get the latest Cygwin (yes, get it again! get rid of the old one just to be sure)
During the installation make sure to select gcc, gcc-g++ and make (I additionally installed couple of other things like gcc4, w32api but it's optional)
Start Cygwin terminal to init all configuration files, etc. See if g++ executes and close the terminal.
Add C:\cygwin\bin (or wherever else you installed it) to your Environment PATH variable
Get Eclipse CDT, extract it somewhere and start it up.
Go to File -> New Project -> C++ Project and select Hello World C++ Project. You should see the Cygwin GCC in the Toolchains list.
Create the Project, build and run it!
Done!
Build output:
**** Build of configuration Debug for project TestApp ****
make all
Building file: ../src/TestApp.cpp
Invoking: Cygwin C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/TestApp.d" -MT"src/TestApp.d" -o "src/TestApp.o" "../src/TestApp.cpp"
Finished building: ../src/TestApp.cpp
Building target: TestApp.exe
Invoking: Cygwin C++ Linker
g++ -o "TestApp.exe" ./src/TestApp.o
Finished building target: TestApp.exe
**** Build Finished ****
You can go to
Project Properties Page > C / C++ Build > Settings > Tool Settings
And change the command as you want. Documentation here.
Refer this link, it shows how to setup eclipse for native development with ease. everything is done in eclipse except setting environment variables.