I have a config file that contains:
#include "libconfig.h++"
I have installed libconfig via homebrew and I am trying to compile my c++ program so that I can use the library but I am having trouble linking to it.
The location of the libconfig .a files is located at /usr/local/Cellar/libconfig/1.4.9/lib/
The documentation says: To link with the library, specify ‘-lconfig++’ as an argument to the linker.
So I have been trying variations on g++ config.cpp -L /usr/local/Cellar/libconfig/1.4.9/lib -lconfig++ -o out.o
But I getting the same error message:
config.cpp:4:10: fatal error: 'libconfig.h++' file not found
#include "libconfig.h++"
Can someone please explain what I am doing wrong?
There is nothing about linker. The compiler says that it can't find the file you include in your cpp. If you have installed libconfig correctly, changing #include "libconfig.h++" to #include <libconfig.h++> will solve the problem. If it does not help, it would mean that there is no "libconfig.h++" in your include path.
Related
I'm stuck in a very simple problem: I cannot manage to make work my simple code example in C++.
I want to include the "curl" library but when I compile with the command:
g++ -o myprog.out myprog.cpp -L/curl/include/ -lcurl
I get the following error message:
myprog.cpp:3:71: fatal error: /curl/include/curl/curl.h: No such file
or directory
My folder contains:
myprog.cpp (the file I want to compile)
curl -> include -> curl -> curl.h (path in which the curl.h file is located).
My headers file are configured in this way:
include<iostream>
include<string>
include<curl.h>
What I'm doing wrong? It's probably a very simple problem but it's driving me crazy :-/
Change #include <curl.h> to #include <curl/curl.h>.
Change -L/curl/include/ to -I/curl/include.
Add -L/curl/lib -Wl,-rpath=/curl/lib (or whatever the path to curl built libraries).
I am trying to compile the following code which has the headers:
#include <SDL2/SDL.h>
#include <SDL2_image/SDL_image.h>
However after running the following makefile:
g++ -std=c++11 src/main.cpp -lSDL2 -lSDL2_image
I get the following error:
fatal error: SDL2_image/SDL_image.h: No such file or directory
#include <SDL2_image/SDL_image.h>
Any suggestions? Not entirely sure about my installation of SDL_image. I am running this on Ubuntu.
This problem can be solved through installing libsdl2-image-dev package:
apt install libsdl2-image-dev
Run apt-file search SDL_image.h
The result will tell you the location of the include file.
For instance, /usr/include/SDL2/SDL_image.h was returned.
So, when you want to include SDL_image.h, write everything after the include/ in between < >.
Thus, includes should look like the following:
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
See the question's comments for the original discussion regarding this solution.
From SDL documentation, it says that add 'lSDL_image' to the end of the compile line.
cc -o myprogram mysource.o `sdl-config --libs` -lSDL_image
or
gcc -o myprogram mysource.c `sdl-config --libs` -lSDL_image
Here is the reference -> https://www.libsdl.org/projects/docs/SDL_image/SDL_image.html
Section 2.2 Compiling.
So for SDL2, you just need to change 'lSDL_image' to 'lSDL2_image'.
For Windows + SDL2-2.0.8 + SDL_image-2.0.4 + Codeblocks you've got the add both Runtime Binaries and Development Libraries to the compiler and linker. Or else, you'll get the error SDL2_image not found, even with having the dll in your program's directory, this occurs. Hopefully others find this helpful; I had to figure it out myself. Example: If your resources are separate, you'll be adding the two plus your standard SDL2 paths to your compiler and linker. Warning: SDL2_image.h has it's headers assuming that the headers are in the same folder as the SDL2 framework. If you get errors about the image header, include the sub-folder SDL2 from SDL framework in the path and then you should be including SDL2 in the program as: include <SDL.h> rather than include <SDL2/SDL.h>.
On my xcode project, I added the dylib of freetype to the project Link Binary phase.
I ensure /usr/local/include and /usr/local/lib are in search paths in the build settings.
I then include:
#include <freetype2/ft2build.h>
#include FT_FREETYPE_H
But i get an error that freetype.h was not found. Any ideas? I tried including <freetype2/freetype.h> directly, but that leads to more compile problems with include paths in other freetype files.
Looking at the demo programs in "freetype2-demos", I see:
#include <ft2build.h>
#include FT_FREETYPE_H
Also, I think you need your compiler command-line to include -I (path to freetype includes).
For example...
g++ -I (...)/freetype2 myfile.cpp
Here are the instructions. The suggestion there is to compile with something like...
g++ $(freetype-config --cflags) myfile.cpp
...which, if you system is configured correctly, will incorporate the -I option that I previously mentioned.
Earlier I succesfully compiled Stasm using cmake on Ubuntu 13.10. It gave me the static library libstasm.a.
However, I'm trying to build my own program using Stasm code but every time I try g++ gives me this:
hanna#hanna-HP-650-Notebook-PC:~/Desktop$ g++ -Wall -L/home/hanna/Downloads/stasm4.1.0/build -lstasm stasmtest.cpp -o stasmtest
stasmtest.cpp:7:23: fatal error: stasm_lib.h: No such file or directory
#include "stasm_lib.h"
^
compilation terminated.
I tried compiling the Minimal.cpp example in the external library because that is supposed to show how to use Stasm in my own programs but still I get the same error.
Can someone please tell me what command I should use to link the Stasm library to my program?
Thanks in advance!
You get a compilation error, not a linking one. g++ cannot find the "stasm_lib.h" header. Use -I/path/to/stasm_lib.h as parameter to g++.
I'm trying to compile a program running on an HP UX server on a Red Hat Linux.
It uses xerces-c library to parse xml files. Compilation is ok, but when i try to run it, I get the following message
./a.out: error while loading shared
libraries: libxerces-c.so.28: cannot
open shared object file: No such file
or directory
I wrote a very simple program to try and understand whats going on:
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/TransService.hpp>
#include <xercesc/parsers/SAXParser.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>
int main(int argc, char* argv[])
{
return 0;
}
And compiled it like this:
g++ test.cpp
-L./xml/xerces-c_2_8_0/lib -lxerces-c -I./xml/xerces-c_2_8_0/include
Surprisingly the file is actually there:
lib]$ ls
libxerces-c.a libxerces-c.so.28 libxerces-depdom.a libxerces-depdom.so.28
libxerces-c.so libxerces-c.so.28.0 libxerces-depdom.so libxerces-depdom.so.28.0
Any thoughts ? I feel i'm missing something, but don't know what.
Thanks in advance.
run ldd a.out and see if the linker can resolve the right .so file
export LD_LIBRARY_PATH to include the current folder (in the same manner as the PATH variable) and check ldd again
the good way to do what you want is the following one:
g++ test.cpp -Xlinker -R ./xml/xerces-c_2_8_0/lib -lxerces-c -I./xml/xerces-c_2_8_0/include
or
g++ test.cpp -Wl,-rpath ./xml/xerces-c_2_8_0/lib -lxerces-c -I./xml/xerces-c_2_8_0/include
Xlinker or Wl options allow you to use specific linking options, you do not need to modifiy
LD_LIBRARY_PATH
You need to tell the runtime c library where to find the various symbols that arent compiled statically in your code and arent in the usualy /lib and /usr/lib locations.
You do this by adding the path to your shared library to LD_LIBRARY_PATH. In this case, this will be what you have been putting for the -L argument to the compiler.