Compiler Errors when trying to build very simple gtkmm app: - c++

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.

Related

gtkmm: Simple example fails to compile: gtkmm.h: No such file or directory

I am working through the gtkmm documentation. I have started by trying to compile the "Simple Example". Here is the code. It can also be found here.
/// SimpleExample.cpp
#include <gtkmm.h>
int main(int argc, char *argv[])
{
auto app =
Gtk::Application::create(argc, argv,
"org.gtkmm.examples.base");
Gtk::Window window;
window.set_default_size(200, 200);
return app->run(window);
}
I have tried to compile this using
g++ SimpleExample.cpp -o SimpleExample `pkg-config gtkmm-3.0 --cflags --libs`
which should work according to the documentation. (See end of linked page.)
Running pkg-config gtkmm-3.0 --cflags --libs produces
Package gtkmm-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtkmm-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtkmm-3.0' found
I am running Debian 9 Stretch. I installed gtkmm with
sudo apt update && sudo apt install libgtkmm-3.0-dev
Running find /usr -name "gtkmm" produces
/usr/lib/x86_64-linux-gnu/pkgconfig/gtkmm-3.0.pc
/usr/lib/x86_64-linux-gnu/gtkmm-3.0
/usr/lib/x86_64-linux-gnu/gtkmm-3.0/include/gtkmmconfig.h
/usr/include/gtkmm-3.0
/usr/include/gtkmm-3.0/gtkmm
/usr/include/gtkmm-3.0/gtkmm.h
So why does the example not compile?
Updates:
New terminal
pkg-config gtkmm-3.0 --cflags --libs
Package gtkmm-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtkmm-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtkmm-3.0' found
Try
find /usr -name "*gtkmm-3.0*"
/usr/lib/x86_64-linux-gnu/pkgconfig/gtkmm-3.0.pc
/usr/lib/x86_64-linux-gnu/libgtkmm-3.0.so.1.1.0
/usr/lib/x86_64-linux-gnu/libgtkmm-3.0.so.1
/usr/lib/x86_64-linux-gnu/gtkmm-3.0
/usr/lib/x86_64-linux-gnu/libgtkmm-3.0.so
/usr/share/doc/libgtkmm-3.0-1v5
/usr/share/doc/libgtkmm-3.0-dev
/usr/include/gtkmm-3.0
Export location
export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig"
Re-run
pkg-config gtkmm-3.0 --cflags --libs
Package xproto was not found in the pkg-config search path.
Perhaps you should add the directory containing `xproto.pc'
to the PKG_CONFIG_PATH environment variable
Package 'xproto', required by 'xau', not found
(That's a different error this time.)
Try to find again
find /usr -name "*xproto*"
/usr/share/pkgconfig/xproto.pc
/usr/include/xcb/xproto.h
/usr/include/GL/glxproto.h
/usr/include/X11/extensions/lbxproto.h
Change export command
export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig;/usr/share/pkgconfig"
Re-run, back to square 1
pkg-config gtkmm-3.0 --cflags --libs
Package gtkmm-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtkmm-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtkmm-3.0' found
Problem resolved (sort ot)
I have discovered from reading this question that the path should be colon seperated.
export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig"
However this does not solve the problem of why this variable needs to be set at all. pkg-config is used because it is supposed to make compilation simpler, however this isn't any more simple than specifying the include paths manually, as multiple environment variables need to be set.
In addition, the lack of information about this issue online makes me suspect that this is an issue which most users do not encounter, and therefore is probably specific to Debian 9. (I would like to know if anyone else has encounted this problem, and on what OS.)
At first, it is normal that installing gtkmm is a bit complicated. As far as i can see, here in the Stackoverflow forum many users have problem with doing so. Even users in the Windows operating system are confronted with error messages, if they are trying to use gtkmm together with Visual Studio for developing a platform independent app ... But to your question. There are many options what can go wrong. A simple explanation would be, that the debian package “libgtk-3-dev” has to be installed, which is used for creating GTK+ apps in C, because gtkmm uses this package. So the first step is to try out, it the compilation of a C sourcecode for GTK+ works. A second explanation is, that the debian “package manager” is in general broken so switching the Linux distribution would be a good advice. For example, in Fedora a simple dnf install gtk3 gtk3-devel gtkmm30 gtkmm30-devel is enough for starting programming.

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.

Compilation error with gtkmm

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

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.

Problems compiling gtkmm

OS: Fedora 14
Compiler: g++ (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
I installed gtkmm24-devel from repository via yum. To make sure the install went as planned I decided to try one of the examples on the page.
#include <gtkmm.h>
int main(int argc, char *argv[]) {
Gtk::Main kit(argc, argv);
Gtk::Window window;
Gtk::Main::run(window);
return 0;
}
I ran the example, and, hey! It said it couldn't find gtkmm.h, no problem, I just forgot to link the library. I added /usr/include/gtkmm-2.4 to my library search through Eclipse. No bueno, g++ still can't find it!
fatal error: gtkmm.h: No such file or directory
I then try to include gtkmm by using #include <gtkmm-2.4/gtkmm.h> and recompile, another error! :(
/usr/include/gtkmm-2.4/gtkmm.h:87:20: fatal error: glibmm.h: No such file or directory
Thanks for reading.
Short answer
Use the output of 'pkg-config gtkmm-2.4 --cflags' for include paths and 'pkg-config gtkmm-2.4 --libs' for libraries to link.
Long answer
It said it couldn't find gtkmm.h, no problem, I just forgot to link the library.
Building a C/C++ program is done in two separate steps. First the source files are compiled, outputting object files; and then the object files are linked together. The error you are getting comes from the compiling step.
On Linux, most libraries come with pkgconfig files to make it easier for other programs to use the libraries. gtkmm also comes with its own pkgconfig files.
You are trying to manually specify /usr/include/gtkmm-2.4 for include path; this is wrong. Instead, use the output of pkgconfig to figure out where the header files are located. To get all the include directories needed for gtkmm, use the following command:
pkg-config gtkmm-2.4 --cflags
For linking, use the following pkgconfig command to get the libraries you need to link with:
pkg-config gtkmm-2.4 --libs
You can test it on the command line by invoking g++ directly.
g++ myfirstprogram.cpp -o myfirstprogram `pkg-config gtkmm-2.4 --cflags --libs`
For more information, see the gtkmm docs: http://library.gnome.org/devel/gtkmm-tutorial/unstable/sec-basics-simple-example.html.en
These steps usually help resolving this problem:
Search your computer for glibmm.h
If found - add its directory to the include path list
If not found - Google for glibmm.h and find out which library it is contained in. You will find out in this case it's (surprise!) glibmm. Install it using your package manager.
The problem, as noted in comments, is a compiler error and the compiler is arguing about a missing (header) file. The steps I described above either find the location of the missing file or help you to install a library that the header file belongs to.