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

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.

Related

Missing "libiconv.h" when crosscompiling for Windows with mingw on Ubuntu

I have been working on a program in SDL and I would like to send it to my friends who only run a Windows environment. I have done some reading and found that I should use mingw to cross-compile for Windows. The binary I found and compiled was x86_64-w64-mingw32-g++, however I am getting some issues getting my program to compile. Using the following command I get the following error:
/usr/bin/x86_64-w64-mingw32-g++ sapphire.cpp `pkg-config --cflags --libs sdl2` -lSDL2_image -lSDL2_mixer -lSDL2_ttf -std=c++11
fatal error: iconv.h: No such file or directory
While I realize I should make a makefile eventually, I am not going to do that now.
I tried installing iconv (Version 1.15) from here and used the following commands to compile it:
./configure --prefix=/usr/local
make
make all
My iconv.h is located in /usr/include but if I include that I get another error for missing gnu/stubs.h and if I include that then I get a myriad of errors that I'm not sure how/if I could fix seen here. Does anyone know how I could perhaps fix this? I would appreciate any help!
Thanks in advance!
You can use pkg-config with mingw in a crosscompiler environment but you should take care to where pkg-config searches for his .pc files.
I'm assuming your mingw crosscompiler is installed in /usr/x86_64-w64-mingw32, change it to the installation path where his "include" and "lib" subdirectories are.
Provided SDL windows developement package is installed in the same prefix on your computer and the installation has a correct pkg-config .pc file you can do:
export PKG_CONFIG_PATH=/usr/x86_64-w64-mingw32/lib/pkgconfig
and then try pkg-config from the command line:
pkg-config sdl2 --cflags
This should point you to some path inside /usr/x86_64-w64-mingw32, if it does your compilation will be successful.
Please note that if you want to compile a package for crosscompile (like the iconv you tried to compile) you should add to the ./configure script parameters:
--host=x86_64-w64-mingw32 --prefix=/usr/xx86_64-w64-mingw32
... and this may work or not, depending the package support the mingw32 compiler or not.
The way you compiled iconv built another linux version of it in /usr/local!
NOTE: As far as I know Ubuntu does not provide a windows package for SDL2, while other linux distro do, so you'll need to cross-compile SDL2 with the option I gave before you can compile your code. SDL2 does support cross-compilation using mingw.

OS X - PKG_CONFIG_PATH results in empty pc_path, package not found

First off: I use OS X 10.10 Yosemite and I do everything from Terminal, no XCode IDE or other GUI involved. I installed pkg-config version 0.28 from Homebrew.
I want to build some software which depends on Ogre 1.8. I built and installed OGRE (via CMAKE_INSTALL_PREFIX) to a custom location in my home directory.
The layout is as follows:
~/install/bin contains binaries
~/install/include contains OGRE include headers
~/install/lib contains static libraries, e.g. libOgreMainStatic.a
~/install/lib/pkgconfig contains *.pc files for Ogre, e.g. OGRE.pc
Before I add the path to PKG_CONFIG_PATH I get this:
$ pkg-config --variable pc_path OGRE
Package OGRE was not found in the pkg-config search path.
Perhaps you should add the directory containing `OGRE.pc'
to the PKG_CONFIG_PATH environment variable
No package 'OGRE' found
This is expected behavior. I then added ~/install/lib/pkgconfig to my PKG_CONFIG_PATH like this:
$ export PKG_CONFIG_PATH=~/install/lib/pkgconfig
$ echo $PKG_CONFIG_PATH
/Users/myusername/install/lib/pkgconfig
Running
$ pkg-config --variable pc_path OGRE
<empty line while I expected the path to OGRE.pc>
again only shows an empty line but no error message however.
When I now run CMake for the software I want to build it says:
$ cmake .
<snip>
-- checking for module 'OGRE'
-- package 'OGRE' not found
What am I doing wrong? On Linux it works with the same commands.
The problem was that OGRE.pc referenced Freetype and a few other requirements which I had built from source. While Ogre was able to find them since they were in the path set by CMAKE_INSTALL_PREFIX pkgconfig wasn't because they didn't provide *.pc files.
I discovered this by using this command:
Before fix:
$ pkg-config --libs OGRE
Package zziplib was not found in the pkg-config search path.
Perhaps you should add the directory containing `zziplib.pc'
to the PKG_CONFIG_PATH environment variable
Package 'zziplib', required by 'OGRE', not found
After fix:
$ pkg-config --libs OGRE
-L/Users/myusername/install/lib -L/Users/myusername/install/lib/OGRE -lOgreMainStatic -lpthread -lboost-thread-mt -lfreeimage

A minimal way to install 'tesseract' for c++ development in linux?

According to this answer I would have to checkout entire repo of tesseract.
How do I install minimal packages of tesseract with c++ APIs for development and English language detection in linux (ubuntu)?
Update - Reason for using the large SVN repo is to enable g++ compilation.
When installed with apt-get:
bhp#Virtual-Machine:~/Desktop/bhp/opencv-tesseract$ pkg-config --cflags --libs tesseract
Package tesseract was not found in the pkg-config search path.
Perhaps you should add the directory containing `tesseract.pc'
to the PKG_CONFIG_PATH environment variable
No package 'tesseract' found
When built with source:
bhp#Virtual-Machine:~/Desktop/soft/tesseract-ocr$ pkg-config --cflags --libs tesseract
-I/usr/local/include/tesseract -L/usr/local/lib -ltesseract

Backslash on Include directories with pkg-config on Mac OS Lion

Good evening everybody,
I have virtually no experience with pkg-config but it seems that I will have to use it in working with openssl. Im on a Mac, which might be of some importance.
The problem is:
i compile my testing program with
cc test.cc `pkg-config --libs --cflags openssl` -o test
i have compiled openssl and installed it in ~/openssl afterwards adding ~/openssl/lib/pkgconfig to the PKG_CONFIG_PATH
since I want to use the newest version instead of the preinstalled one, I specify the options with every compilation
the result of running pkg-config --libs or pkg-config --cflags openssl is -L\~/openssl/lib -lssl -lcrypto
This begs the question for me why there is a backsash and whether my compiled version is used or the preinstalled one and if the first one is the case how i could possibly fix this...
Any kind of help is appreciated
The expansion of ~ to your home directory only occurs in certain circumstances. Basically, it's the shell that's doing it. If a program or a file API sees the tilde, it is interpreted as a literal; it's not expanded.
Use $HOME when setting PKG_CONFIG_PATH instead, as in $HOME/openssl.

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.