'"SDL.h" no such file or directory found' when compiling - c++

Here's a piece of my current Makefile:
CFLAGS = -O2 -Wall -pedantic -std=gnu++11 `sdl-config --cflags --libs` -lSDL_mixer
I have libsdl installed properly, SDL.h is in /usr/include/sdl where it belongs, but it just won't compile. I also have the line #include "SDL.h" in my .h files, but still no go.
Anyone knows why?

For Simple Direct Media Layer 2 (SDL2), after installing it on Ubuntu 16.04 via:
sudo apt-get install libsdl2-dev
I used the header:
#include <SDL2/SDL.h>
and the compiler linker command:
-lSDL2main -lSDL2
Additionally, you may also want to install:
apt-get install libsdl2-image-dev
apt-get install libsdl2-mixer-dev
apt-get install libsdl2-ttf-dev
With these headers:
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>
and the compiler linker commands:
-lSDL2_image
-lSDL2_ttf
-lSDL2_mixer

If the header file is /usr/include/sdl/SDL.h and your code has:
#include "SDL.h"
You need to either fix your code:
#include "sdl/SDL.h"
Or tell the preprocessor where to find include files:
CFLAGS = ... -I/usr/include/sdl ...

header file lives at
/usr/include/SDL/SDL.h
__OR__
/usr/include/SDL2/SDL.h # for SDL2
in your c++ code pull in this header using
#include <SDL.h>
__OR__
#include <SDL2/SDL.h> // for SDL2
you have the correct usage of
sdl-config --cflags --libs
__OR__
sdl2-config --cflags --libs # sdl2
which will give you
-I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
-L/usr/lib/x86_64-linux-gnu -lSDL
__OR__
-I/usr/include/SDL2 -D_REENTRANT
-lSDL2
at times you may also see this usage which works for a standard install
pkg-config --cflags --libs sdl
__OR__
pkg-config --cflags --libs sdl2 # sdl2
which supplies you with
-D_GNU_SOURCE=1 -D_REENTRANT -I/usr/include/SDL -lSDL
__OR__
-D_REENTRANT -I/usr/include/SDL2 -lSDL2 # SDL2

Most times SDL is in /usr/include/SDL. If so then your #include <SDL.h> directive is wrong, it should be #include <SDL/SDL.h>.
An alternative for that is adding the /usr/include/SDL directory to your include directories. To do that you should add -I/usr/include/SDL to the compiler flags...
If you are using an IDE this should be quite easy too...

the simplest idea is to add pkg-config --cflags --libs sdl2 while compiling the code.
g++ file.cpp `pkg-config --cflags --libs sdl2`

Having a similar case and I couldn't use StackAttacks solution as he's referring to SDL2 which is for the legacy code I'm using too new.
Fortunately our friends from askUbuntu had something similar:
Download SDL
tar xvf SDL-1.2.tar.gz
cd SDL-1.2
./configure
make
sudo make install

Related

How to use LLVM library in c++ Xcode project?

I'm loosely following the tutorial to implement Kaleidoscope on the LLVM website, and I'm at the point where I need to actually use the LLVM library for code generation. I've installed LLVM 13 using homebrew (brew install llvm), but I can't figure out how to use it in a c++ project in Xcode. I just get the error 'llvm/whatever/whatever' file not found for every file I try to include:
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
I've tried adding the include folder (/opt/homebrew/Cellar/llvm/13.0.1_1/include for me) to the header search paths in Xcode, which seems to do something but I end up with the error Undefined symbol: llvm::DisableABIBreakingChecks, and hundreds of different warnings.
All I want is to be able to use LLVM code generation in a small c++ project. Is there any simple way to do this?
I'm also doing that tutorial. I'll tell you how I got it to work, but since I'm not an LLVM expert, I don't know if this is the best way.
I checked out and built LLVM from source, as described here. Installing with brew like you did should also work fine.
Next, I looked at the build command they give in the tutorial:
clang++ -g -O3 toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core`
-o toy
I can run that llvm-config command from my build directory and it gives me the flags that I need to somehow give to Xcode.
> bin/llvm-config --cxxflags --ldflags --system-libs --libs core
-I/Users/rob/Foo/llvm-project/llvm/include
-I/Users/rob/Foo/llvm-project/build/include
-std=c++14 -fno-exceptions -fno-rtti
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-L/Users/rob/Foo/llvm-project/build/lib
-Wl,-search_paths_first -Wl,-headerpad_max_install_names
-lLLVMCore -lLLVMRemarks -lLLVMBitstreamReader
-lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle
-lm -lz -lcurses -lxml2
I put those -I paths in the HEADER_SEARCH_PATHS build setting, and the -L path in LIBRARY_SEARCH_PATHS. In Xcode those values are a list of paths, so you add the paths without the -I or -L part. I then put the -l library arguments in OTHER_LDFLAGS, and the -D arguments in OTHER_CPLUSPLUSFLAGS.
After that, it compiled and ran from Xcode. I did not yet translate all of the output from llvm-config into Xcode build settings. For example, I did nothing about these:
-std=c++14 -fno-exceptions -fno-rtti
-Wl,-search_paths_first -Wl,-headerpad_max_install_names
Remains to be seen if that will cause problems later.

Compiler and linker flags in Rcpp: Magick++

I have an R script, which loads an Rcpp file. The Rcpp file needs the magick++ library, so I used:
#include <Rcpp.h>
#include <Magick++.h>
However when I run the script, I get:
fatal error: Magick++.h: No such file or directory
The library libmagick++-dev is installed.
How can I include Magick++ in an Rcpp file? How can I compile it with flags? For instance:
-DHAVE_CONFIG_H, -DMAGICKCORE_QUANTUM_DEPTH=16, -DMAGICKCORE_HDRI_ENABLE=0
A minimal working example:
mwe.r
library(Rcpp)
sourceCpp("./mwe.cpp")
mwe.cpp
#include <Rcpp.h>
#include <Magick++.h>
//[[Rcpp::plugins(cpp11)]]
As #hrbrmstr mentions, there is a CRAN package magick that provides ImageMagick functionality already; maybe that avoids the need to do anything yourself?
From these ImageMagick instructions you can see that a C++ program needs to know about compiler flags (the output of Magick++-config --cppflags --cxxflags) and linker flags (Magick++-config --ldflags --libs).
The best way to compile Rcpp code with complicated compilation and linkage steps is (I'm no expert here...) to create an Rcpp package
/tmp$ Rdev --vanilla -e "Rcpp::Rcpp.package.skeleton('Magick')"
/tmp$ cd Magick
I edited Magick/src/rcpp_hello_world.cpp to
#include <Rcpp.h>
#include <Magick++.h>
using namespace Rcpp;
// [[Rcpp::export]]
LogicalVector rcpp_hello_world()
{
Magick::InitializeMagick("RcppMagick");
return true;
}
And added package pre-processing, compilation, and linkage commands (following Writing R Extensions, available via RShowDoc("R-exts")) to a new file Magick/src/Makevars like
PKG_CPPFLAGS = `Magick++-config --cppflags`
PKG_CXXFLAGS = `Magick++-config --cxxflags`
PKG_LIBS = `Magick++-config --ldflags --libs`
I then updated the attributes of my package, installed it, and verified that it could be used
/tmp/Magick master$ Rdev --vanilla -e "Rcpp::compileAttributes()"
> Rcpp::compileAttributes()
>
>
/tmp/Magick master$ Rdev --vanilla CMD INSTALL .
* installing to library ...‘/home/mtmorgan/R/x86_64-pc-linux-gnu-library/3.5-Bioc-3.7’
* installing *source* package ‘Magick’ ...
** libs
g++ -I"/home/mtmorgan/bin/R-devel/include" -DNDEBUG `Magick++-config --cppflags` -I"/home/mtmorgan/R/x86_64-pc-linux-gnu-library/3.5-Bioc-3.7/Rcpp/include" -I/usr/local/include `Magick++-config --cxxflags` -fpic -g -O3 -Wall -pedantic -c RcppExports.cpp -o RcppExports.o
g++ -I"/home/mtmorgan/bin/R-devel/include" -DNDEBUG `Magick++-config --cppflags` -I"/home/mtmorgan/R/x86_64-pc-linux-gnu-library/3.5-Bioc-3.7/Rcpp/include" -I/usr/local/include `Magick++-config --cxxflags` -fpic -g -O3 -Wall -pedantic -c rcpp_hello_world.cpp -o rcpp_hello_world.o
g++ -shared -L/usr/local/lib -o Magick.so RcppExports.o rcpp_hello_world.o -L/usr/lib -L/usr/lib/X11 -lGraphicsMagick++ -lGraphicsMagick -ljbig -lwebp -llcms2 -ltiff -lfreetype -ljasper -ljpeg -lpng12 -lwmflite -lXext -lSM -lICE -lX11 -llzma -lbz2 -lxml2 -lz -lm -lgomp -lpthread
installing to /home/mtmorgan/R/x86_64-pc-linux-gnu-library/3.5-Bioc-3.7/Magick/libs
...
/tmp/Magick master$ Rdev --vanilla -e "Magick::rcpp_hello_world()"
> Magick::rcpp_hello_world()
[1] TRUE
I had to figure out what system package to install to get Magick++-config. When I first tried to install my package R complained that it didn't know about -lwebp, so I installed that system dependency too (libwebp-dev). The package would be good enough for personal use, but would need to be more robust for cross-platform or production use. There could be many problems encountered while trying to integrate this complicated library into R.

compiling c++ projects with dlib library on linux

I want to use dlib library for my c++ projects in linux. I have installed it successfully and able to compile and run the .cpp samples files given under the dlib. I have compiled the sample files through the
"g++ -std=c++11 -O3 -I.. ../dlib/all/source.cpp -lpthread -lX11 example_program_name.cpp" given in [http://dlib.net/compile.html][1]
but I am unable to use the same command to run .cpp files which are the outside dlib-18.18/examples directory
Can someone help me out with compiling c++ file (with dlib library usage) from any user directory in linux?
I came to know that we have to include the path of dlib installation folder while trying to compile it from any other user directory. So I tried the command
" g++ -O3 -I/home/praneeth/computervision/.. ../dlib/all/source.cpp -lpthread -lX11 project3_face.cpp -o project_face pkg-config --cflags opencv pkg-config --libs opencv"
but it gave me the result:
g++: error: ../dlib/all/source.cpp: No such file or directory
Note: dlib-18.18 folder is present in my /home/praneeth/computervision/
I don't know how correct is this but it got compiled when I ran the command like: g++ -O3 -I/home/praneeth/computervision/dlib-18.18 /home/praneeth/computervision/dlib-18.18/dlib/all/source.cpp -lpthread -lX11 project3_face.cpp -o project_face pkg-config --cflags opencv pkg-config --libs opencv any comments on this regarding why this works?
g++ -Wl,-V -std=c++11 -o3 -I/home/user/dlib-19.6 /home/user/dlib-19.6/dlib/all/source.cpp -lpthread -lX11 -o Test Test.cpp pkg-config opencv --cflags --libs

Graphicsmagick C++ API

I want to use the C++ API for graphicsmagick
I need to convert image data directly from OpenCV and use graphicsmagick to save the file as tiff with group 4 compression
The command line
gm convert input -type bilevel -monochrome -compress group4 output.tif
Could anyone provide some code (see the above command line) to simply convert the output from OpenCV to tiff with group 4 compression
I'm new to C++ :)
testing graphicsmagick
I'm trying to make graphicsmagick work. Found a very simple code in the docs
I can't find Magick++.h
locate /Magick++.h returns nothing
but graphicsmagick is installed
# gm -version
GraphicsMagick 1.3.20 2014-08-16 Q8 http://www.GraphicsMagick.org/
code
/*
* Compile
* g++ gm_test.cpp -o gm_test `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs`
*/
#include <Magick++.h>
using namespace std;
using namespace Magick;
int main(int argc, char **argv){
InitializeMagick(*argv);
Image image( "100x100", "white" );
image.pixelColor( 49, 49, "red" );
image.write( "red_pixel.png" );
return 0;
}
compile
# g++ gm_test.cpp -o gm_test `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs`
-bash: GraphicsMagick++-config: command not found
gm_test.cpp:6:22: fatal error: Magick++.h: No such file or directory
#include <Magick++.h>
^
compilation terminated.
Updated Answer
Try looking for a file called GraphicsMagick-config under the directory where you installed GraphicsMagick like this:
find /usr -name "GraphicsMagick-config"
When you find that, you can ask it to tell you the compiler include flags and linker flags like this:
/usr/some/path/GraphicsMagick-config --cflags --libs
Then you can compile with:
gcc $(/usr/some/path/GraphicsMagick-config --cflags --libs) somefile.c -o somefile
Original Answer
Look in the directory where you installed GraphicsMagick for a file ending in .pc, which is the pkg-config file, e.g.
find /usr/local -iname "graphic*.pc"
Then pass this file to pkg-config to get the CFLAGS and LIBS you should use for compiling. So, if your graphicsmagick.pc is in /usr/local/Cellar/graphicsmagick/1.3.23/lib/pkgconfig/GraphicsMagick.pc, use:
pkg-config --cflags --libs /usr/local/Cellar/graphicsmagick/1.3.23/lib/pkgconfig/GraphicsMagick.pc
which will give you this:
/usr/local/Cellar/graphicsmagick/1.3.23/lib/pkgconfig/GraphicsMagick.pc
-I/usr/local/Cellar/graphicsmagick/1.3.23/include/GraphicsMagick -L/usr/local/Cellar/graphicsmagick/1.3.23/lib -lGraphicsMagick
Then you would compile with:
gcc $(pkg-config --cflags --libs somefile.c -o somefile
i don't know if it's helpful, last day i have the same error :no magick++.h when i compile ImageMagick (not graphicsmagick).
so i follows the steps in a official website to reinstall ImageMagick and finally i succeed.web:
1 http://www.imagemagick.org/script/install-source.php
2 http://www.imagemagick.org/script/magick++.php
i download the latest source code(ImageMagick6.9) in centOS-6.5
and then ./configure, make, make install.
i hope it's helpful.
On Ubuntu the GraphicsMagick++-config program you are using to get compile flags is correctly part of the same package which includes Magick++.h. Trying to run it tell you where to find it:
$ g++ gm_test.cpp -o gm_test `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs`
The program 'GraphicsMagick++-config' is currently not installed. You can install it by typing:
sudo apt-get install libgraphicsmagick++1-dev
gm_test.cpp:6:22: fatal error: Magick++.h: No such file or directory
compilation terminated.
So do what it says:
$ sudo apt-get install libgraphicsmagick++1-dev
Try the compile again and you will get a different error because GraphicsMagick++-config is linking to an uninstalled and unneeded library:
$ g++ gm_test.cpp -o gm_test `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs`
/usr/bin/ld: cannot find -lwebp
collect2: error: ld returned 1 exit status
You can manually specify the libs and the compile and link works:
$ g++ gm_test.cpp -o gm_test -I/usr/include/GraphicsMagick -Wall -g -fno-strict-aliasing -O2 -pthread -lGraphicsMagick++ -lGraphicsMagick -ljbig
$ ./gm_test
Or you can install the required library:
$ sudo apt-get install libwebp-dev

libxml++/libxml++.h: No such file or directory

I am using ubuntu 12.4 g++ i'm working on libxml++ library I have included this library in my program but I am getting an error saying
libxml++/libxml++.h: No such file or directory
i also tried compiling using g++ main.cc -o main pkg-config --cflags --libs libxml++-2.6 but it is not working. I have installed the latest libraries using sudo apt-get install libxml++.
While compiling for libxml we have to use these options. pkg-config --cflags --libs libxml++-2.6 this should be in single quotation mark / Backticks ("`", grave accents), .
So the command should be like this.
$ g++ main.cc -o program `pkg-config --cflags --libs libxml++-2.6`
or go through this once. http://developer.gnome.org/libxml++/stable/