For a C++ project I'd like to use ImageMagick to manipulate images. To test is out, my test1.cpp is just bare-bones :
#include <iostream>
#include <Magick++.h>
using namespace Magick;
int main(int argc, char * argv[]){
return 0;}
And I've been trying to compile it in the terminal by using :
g++ `Magick++-config --cxxflags --cppflags` -O2 -Wall -o test1 test1.cpp `Magick++-config --ldflags --libs`
and I get :
fatal error: 'Magick++.h' file not found
I've installed the latest version of ImageMagick (convert and identify work when called from the terminal) and the first lines of my .bash_profile look like this :
export MAGICK_HOME="/opt/ImageMagick-6.8.9"
export PATH="/System/Library/Frameworks:$MAGICK_HOME/bin:$PATH"
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/opt/X12/lib/pkgconfig/:$MAGICK_HOME/lib/pkgconfig"
All path are correct and I have already used pkg-config to successfully link a c++ program to cairo.
What am I doing wrong ? What's the simpler way to use ImageMagick in a c++ program ?
(I use vim and the terminal and do not wish to use an IDE at this point).
Thanks in advance for any help !
-- EDIT --
Here's what's returned by Magick+-config (--cxxflags and --cppflags) :
-DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -I$MAGICK_HOME/include/ImageMagick-6
And by --ldflags and --libs :
-L$MAGICK_HOME/lib -lMagick++-6.Q16 -lMagickWand-6.Q16 -lMagickCore-6.Q16
Related
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.
I'm trying to make a C++ script that will run some simple Python code:
// t.cpp
#include <Python.h>
int main(int argc, char* argv[])
{
Py_Initialize();
PyRun_SimpleString("print('TEST PASSED')");
Py_Finalize();
return 0;
}
Upon running g++ t.cpp, I get the error:
t.cpp:1:20: fatal error: Python.h: No such file or directory
compilation terminated
I've found many similar questions, all specific to an IDE or other development software, or were solved by installing python3-dev. The python3-dev package is already installed, and I even tried manually including the header when attempting to compile:
g++ t.cpp -I ~/.virtualenvs/MainEnv/include/python3.5m/Python.h
g++ t.cpp -I /usr/include/python3.5m/Python.h
Neither changes anything.
How can I fix this error?
UPDATE: I found that using g++ t.cpp -I /usr/include/python3.5/ seems to include the header, but then it runs into more errors:
t.cpp:(.text+0x10): undefined reference to `Py_Initialize'
t.cpp:(.text+0x1f): undefined reference to `PyRun_SimpleStringFlags'
t.cpp:(.text+0x24): undefined reference to `Py_Finalize'
collect2: error: ld returned 1 exit status
I've set up a similar example on my github
g++ t.cpp is missing a few things:
Tell g++ where the headers are for cpython (by -I/path/to/headers/)
Tell g++ to link against libpython (by -lpython3.5m)
You can also retrieve these flags with pkg-config
$ pkg-config python-3.5 --libs --cflags
-I/usr/include/python3.5m -I/usr/include/x86_64-linux-gnu/python3.5m -lpython3.5m
Your commandline should look something like g++ -I/usr/include/python3.5m t.cpp -lpython3.5m
#include <...> is for includes that come with the compiler.
Use #include "Python.h" for any other includes.
Run the following commands to compile your code:
mytest.cpp:
#include <Python.h>
int main(int argc, char* argv[])
{
Py_Initialize();
PyRun_SimpleString("print('TEST PASSED')");
Py_Finalize();
return 0;
}
Compile:
$ g++ mytest.cpp `pkg-config python3-embed --libs --cflags` -o mytest
$ ./mytest
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
I have read all of the related questions with no success trying anything mentioned anywhere. I am new to cross-compiling and have been working on this for over a week with no progress. So please forgive me if you think I am stupid or have overlooked something.
So I have an application running in C++ that works great on my development computer running Ubuntu 14.04 x64. I am trying to cross compile for my Banana Pro running Lubuntu. Based on the documentation from Lemaker I am supposed to cross compile using "arm-linux-gnueabihf-"
So far the farthest I have been able to get is to :
/usr/local/opencv-arm/usr/local/lib/libopencv_calib3d.so: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
I get this error regardless of what command I run, Here is a list of commands I have tried:
arm-linux-gnueabihf-g++ `arm-linux-gnueabihf-pkg-config arm-opencv --cflags` -Wall test.cpp -o vis-300 `arm-linux-gnueabihf-pkg-config arm-opencv --libs`
arm-linux-gnueabihf-g++ `pkg-config arm-opencv --cflags` -Wall test.cpp -o vis-300 `pkg-config arm-opencv --libs`
arm-linux-gnueabihf-gcc `pkg-config arm-opencv --cflags` -Wall test.cpp -o vis-300 `pkg-config arm-opencv --libs`
arm-linux-gnueabihf-g++ `pkg-config arm-opencv --cflags` test.cpp -o vis-300 `pkg-config arm-opencv --libs`
And there have been many more commands before those with different errors such as:
arm-linux-gnueabihf-gcc: error trying to exec 'cc1plus': execvp: No such file or directory
arm-linux-gnueabihf-cpp fatal error too many input files
I have tried with just normal arm-linux-gnueabihf-gcc/g++, 4.6, 4.7, and 4.8
I have built opencv making small changes for hf using these 2 guides and both produced the same results:
http://processors.wiki.ti.com/index.php/Building_OpenCV_for_ARM_Cortex-A8
http://www.ridgesolutions.ie/index.php/2013/05/24/building-cross-compiling-opencv-for-linux-arm/
and not included in either I install it using this command because it will conflict with my current x86_64 install:
sudo make install DESTDIR=/usr/local/opencv-arm
Also the above pkg-config lines point to my custom pkg config file named arm-opencv.pc
# Package Information for pkg-config
prefix=/usr/local/opencv-arm/usr/local
exec_prefix=${prefix}
libdir=
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include
Name: OpenCV-arm
Description: Open Source Computer Vision Library
Version: 2.4.10
Libs: ${exec_prefix}/lib/libopencv_calib3d.so ${exec_prefix}/lib/libopencv_contrib.so ${exec_prefix}/lib/libopencv_core.so ${exec_prefix}/lib/libopencv_features2d.so ${exec_prefix}/lib/libopencv_flann.so ${exec_prefix}/lib/libopencv_gpu.so ${exec_prefix}/lib/libopencv_highgui.so ${exec_prefix}/lib/libopencv_imgproc.so ${exec_prefix}/lib/libopencv_legacy.so ${exec_prefix}/lib/libopencv_ml.so ${exec_prefix}/lib/libopencv_nonfree.so ${exec_prefix}/lib/libopencv_objdetect.so ${exec_prefix}/lib/libopencv_ocl.so ${exec_prefix}/lib/libopencv_photo.so ${exec_prefix}/lib/libopencv_stitching.so ${exec_prefix}/lib/libopencv_superres.so ${exec_prefix}/lib/libopencv_ts.a ${exec_prefix}/lib/libopencv_video.so ${exec_prefix}/lib/libopencv_videostab.so -lrt -lpthread -lm -ldl
Cflags: -I${includedir_old} -I${includedir_new}
Anyways I have tried a lot of stuff short of just installing everything on the board itself and compiling there. Any help is much appreciated and keep in mind I have never successfully cross-compiled before. I always give up and compile on the board.
I've compiled Qt on OSX Lion using the instructions provided at this official guide. I've then tried compiling the following Hello World with gcc hello_world.cpp -o hello_world
#include <QApplication>
int main(int argc, char **argv)
{
QApplication app (argc, argv);
return app.exec();
}
I've got the following error:
hello_world.cpp:1:10: fatal error: 'QApplication' file not found
#include <QApplication>
^
1 error generated.
try instead #include <QtGui/QApplication>
Use -I option of gcc to give additional include locations.
gcc hello_world.cpp -I/path-to-qt/include -o hello_world
If you use it like that, you have to use your includes like this:
#include <QtGui/QApplication>
if you want your includes to be shorter like #include <QApplication>, you can give multiple include folders like this:
gcc hello_world.cpp -I/path-to-qt/include/QtCore -I/path-to-qt/include/QtGui -o hello_world
But that is not all. You also have to give library directories and which libraries to link to, which is done like this:
gcc hello_world.cpp -I/path-to-qt/include/QtCore -I/path-to-qt/include/QtGui -o hello_world -L/path-to-qt/lib -lQtCore -lQtGui
It is also better to use g++, since you are using C++.
g++ hello_world.cpp -I/path-to-qt/include/QtCore -I/path-to-qt/include/QtGui -o hello_world -L/path-to-qt/lib -lQtCore -lQtGui
Try with g++ -I<path_to_include_directory> -L<path_to_library_dir> -lQtCore.
For example, in my Debian I would do: g++ -I/usr/local/include/Qt4 -L/usr/local/lib -lQtCore -lQtGui whatever.cpp
EDIT: Thanks to #erelender to point out that QApplication is in the QtGui library and that it depends on QtCore.
What if you try to add additional include path for gcc with using -I flags? Something like:
gcc -I/usr/local/Qt-5.1.1/include hello_world.cpp -o hello_world
Not sure about the path in mac, but on Linux the class QApplication
is defined at following location (qt4)
/usr/include/qt4/QtGui/qwindowdefs.h
Do you have something similar on Mac?
If you are building from command line, including a header file with gcc can be done with following switch
-I<path to .h file>