I've been struggling for hours to include the GTK library for manjaro in C++. I'm using VS Code, I have installed the GTK-4.0 package with the command sudo pacman -Syu gtk4 and I'm including the file /usr/include/gtk-4.0/gtk/gtk.h in my C++ program with the line #include <gtk-4.0/gtk/gtk.h>. It's throwing the error
gtk/css/gtkcss.h: No such file or directory
even though there is a file named gtkcss.h at the path /usr/include/gtk-4.0/gtk/css/gtkcss.h
I've looked all over google and I can't find anyone having the same problem, especially on the same OS. Any help is much appreciated!
You are missing an include path.
Gtk requires* pkg-config to set the include path. see https://developer.gnome.org/gtk4/unstable/gtk-compiling.html
So while you have included it with a complete path, the files inside the library still require the include path to be set.
I don't know which build system you are using, but in general gtk requires something like:
g++ $(pkg-config --cflags) -c main.cpp
This will expand to the right flags to set the include path.
*You might also do this manually by adding a -I flag. But that is prone to break if you want to compile on a different machine.
Related
I am writing a c++ program from the windows cmd prompt, and compiling with mingw (g++). This program needs a non-linear optimiser and NLOpt looks like a good choice. I learnt c++ for a uni course, so the environment I was using was already set up, I have no experience in setting up libraries etc.
So far my steps have been;
Download the precompiled DLLs for 64-bit windows (which is what I'm running) from here.
Run the command dlltool --input-def libnlopt-0.def --dllname libnlopt-0.dll --output-lib libnlopt-0.lib (from the same page), which ran without errors.
This creates an .hpp file, however, when I try to #include the file I get
In file included from optimiseDogs.cc:9:0:
C:\Files|Development\NLOpt2.4.2\nlopt.hpp:29:19: fatal error: nlopt.h: Nosuch file or directory
#include <nlopt.h>
nlopt.h and nlopt.hpp are in the same directory as each other. My program is in a different folder.
This is probably really basic, sorry to trouble you with it. Perhaps I am not completely alone in my ignorance and this will help someone else too. Also, I have seen this question, but it deals with installing on visual basic, and I'm not using a GUI, just notepad++ and the cmd prompt.
Thank you for your help.
If you are in windows and using mingw: downloaded zip archive already contains .dll and .lib files. So you dont need to run dlltool which creates these .lib,.dll from .def. I think your problem is compiling command using g++ adding include and library path directives.
C:\Files\Development\NLOpt2.4.2>g++ <path_of_source>.cc -o program.exe -L. -lnlopt -lm -I. -I<path_of_your_headers>
I encounted in the past that order of -I and -L may matter so try changing if not working.
Please see this tut and that tut to understand the concept.
Is it possible to customize or specify the command for compiling in codeblocks or any of the other IDEs like NetBeans and Eclipse C++?
I'm asking this because I tried all those IDEs and no one can find the libraries even though it's there listed in the code assistance list (NetBeans 7.2). However, when I compile it in shell in Ubuntu 12.04 LTS, the libraries are located and the program can be compiled.
I use one of the commands:
gcc -lGL -lglut filetoCompile.cpp -o compiled.sh
g++ -lGL -lglut filetoCompile.cpp -o compiled.sh
to compile. I'm trying to use glut for open GL stuff and this is the library it can't find. I assume it may be the same for other third party libraries I may add in the future that's why I really need to get this fixed that's why my plan is to have the IDE use that command instead because it might work.
What's also odd is that my /usr/local/lib directory only contains 2 folders: python 2.7 and python 3.2. I'm not sure if this has an effect but is this normal? Shouldn't the libraries somehow be found here and the headers are in /usr/local/include?
The header files are located in /usr/include. Is this the correct location?
Generally speaking, yes this is possible.
In Eclipse CDT, you can set the directory where the header files are in this window:
Right click on project name; Properties; C/C++ General; Paths and symbols; Includes;
In window you must add all directories that contain header files for the functions/classes you want auto completion for. For example, my configuration is:
/usr/include/c++/4.4.5
/usr/local/include
/usr/lib/gcc/i486-linux-gnu/4.4.5/include
to find which folder contain an header file you can use the find or locate command, and set the IDE properly.
I develop C++ programs using a Cygwin installation on top of Windows XP.
I also have MinGW installed, because I want to use it's version of g++, not the one that comes with Cygwin.
That part seems to be set up correctly. When I start a Cygwin session I see this:
$ which g++
/cygdrive/c/MinGW/bin/g++
This is correct, g++ is pointing to my MinGW install.
What I don't understand is when I write code that includes library code (for example, header files from the `Winsock/BerkleySockets API), how can I tell where the compiler is finding that header file?
For example, if I have #include "winsock.h" in my code, where does the compiler find that header file?
If I do a general search for winsock.h on my computer, I get this:
C:\MinGW\include
C:\cygwin\usr\include\w32api
Both have a copy of winsock.h (though the file sizes of these aren't exactly the same, so they can't be identical).
Thanks for the help.
I should also point out, I have the C:\MinGW\bin in my Windows PATH Environment Variable, as well as that same path configured in my/etc/profile file within Cygwin.
I'm guessing the g++ compiled for MingW has the same command line arguments as the standard g++. Check out the g++ manual page.
To add include paths to your compilation, use the -I flag.
g++ -I/include/path/here -I/another/include/path -o prog src.cpp
To add library paths to your linking, use the -L flag.
g++ -L/lib/path/here -L/another/lib/path -o prog src.cpp
The MingW site explains how the include file search works on MingW, and how to modify it.
The site also says that if you want to view the include file search while it happens during the compilation, pass the verbose flag (-v) to the compiler.
g++ -v -o prog src.cpp
I believe it's referring to the one in MinGW/include. Take a look at the Minigw documentation for include paths.
If you are using an eclipse environment you can specify the include paths in the project settings along with specifying your choice of compiler i.e mingw in your case. Let us know if you still have a problem.
I am learning concert technology, I am still at the beginning. I tried to open one of the examples (Ilolpex1.ccp) but when I run it the program says:
#include <ilcplex/ilocplex.h> : cannot open this source file
how can I solve this problem?
Assuming your C++11 compiler is GCC (on Linux), i.e. g++ command, you could run it as g++ -H to understand what headers are included, and you should add appropriate -I options to give relevant include directories.
Maybe you just need to add e.g. -I /usr/local/include
You might need to add the developer package of your libraries. (e.g. some libfoo-dev package on Debian or Ubuntu)
In practice, you'll better edit some variable in your Makefile, perhaps some CXXFLAGS
The message you are seeing is during compilation, not running the program. You need to add the concert and cplex include directories to your include path. The examples are in the directory
<cplex_root_dir>/cplex/examples/src/cpp/
The include files are in
<cplex_root_dir>/cplex/include
<cplex_root_dir>/concert/include
The problem occurs maybe because you have installed a 32bit version of IBM ILOG CPLEX Optimization Studio on a 64bit Windows. So Visual Studio can't find related header files like "ilcplex".
I'm trying to implement soci in my program but I don't know how. I'm using C++ on Linux, on a project using netbeans. I have followed the steps in: http://soci.sourceforge.net/doc/structure.html to install it, and I tried to copy the files soci.h from /src/core and soci-mysql.h from /src/backends/mysql in my project but it gives a compilation error (these files include other soci files, but it's illogical to copy all files into the directory...). I have read the guide several time but I don't understand what I'm doing wrong. The examples only include these files.
Thanks.
Edit: I have given more information in a comment below the answer. I don't know what steps I have to follow to implement soci.
The relevant bit on that page is
When the configure script is run without parameters, the remaining part of the process will use /usr/local/include/soci as a default destination for SOCI header files and /usr/local/lib as a default destination for library files
Now /usr/local/include ought to be in your default include path (e.g. try something like gcc -c -v -x c++ /dev/null -o /dev/null to see the list your install uses) and so you can include these using
#include <soci/soci.h>
#include <soci/soci-mysql.h>
You then need to add the libraries to your link step. It looks like you'll have both static and shared versions of the libraries. You'll need to add -lsoci_core -lsoci_mysql to your link step; however if that doesn't work then you'll also need to specify /usr/local/lib as a search directory i.e. -L/usr/local/lib -lsoci_core -lsoci_mysql. (Again it's probably there already but you can see using gcc -print-search-dirs.) However, the issue then is that if you're using the shared version and /usr/local/lib isn't in your distributions library search path (see /etc/ld.so.conf and/or /etc/ld.so.conf.d/*) then it won't be able to find the shared library at runtime. You'll need to either hard-code in the path to the library with the linker switch -rpath or add /usr/local/lib to the system-wide search path as before or in your environment (variable LD_LIBRARY_PATH). I'm not sure what the best way to do this is - I'd suggest -rpath to avoid modifying the system in general, although if you're building a lot of libraries into /usr/local/lib it might make sense to add it.
I got the same doesn't load backend error on my C++ program when I execute session sql("mysql://db=...)
I found a solution (at least on my Ubuntu 11.04). Just do:
sudo -i ln -s /usr/lib/libsoci_mysql-gcc-3_0-3.0.0.so /usr/lib/libsoci_mysql.so
It seem that the SOCI library search for the file /usr/lib/libsoci_mysql.so that is not in the system, buy if you make a link to the library /usr/lib/libsoci_mysql-gcc-3_0-3.0.0.so that it's in the system it works (I think debian/ubuntu makes a file name change from the original name, but it have side effects because the SOCI library search inside for the original name).
I found the error using the bash environment variable LD_DEBUG=files and running my C++ binary.
Hope it helps.