2017-06-13 13 views
2

我目前正在嘗試使用Magick ++ API編譯一個簡單的C++代碼。我正在編譯的實際代碼很簡單。只是一個「hello world」,在頂部包含#include Magick ++。h。無法使用Magick ++編譯代碼(庫問題)

問題是,編譯器似乎無法找到-lMagick ++。請參閱下面

錯誤

ImageMagick的是從安裝二進制文件在Cygwin中通過Windows 7,我做了以下配置中安裝

export MAGICK_HOME="$HOME/ImageMagick-6.8.8" 
export PATH="$MAGICK_HOME/bin:$PATH" 
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$MAGICK_HOME/lib" 
export PKG_CONFIG_PATH="$MAGICK_HOME/lib/pkgconfig" 

CPP文件後:

g++ `Magick++-config --cppflags` -o hello hello_world.cpp \ `Magick++-config --ldflags --libs` 

#include <iostream> 
#include <Magick++.h> 
using namespace std; 

int main(int argc, char ** argv) 
{ 
    InitializeMagick(*argv); 
    cout<<"Hello Magick++"<<endl; 
    return 0; 
} 

與編譯

後退:

g++: -lMagick++: No such file or directory 
cc1plus: warning: command line option "-fopenmp" is valid for D but not for C++ 
hello_world.cpp: In function `int main(int, char**)': 
hello_world.cpp:7: error: `InitializeMagick' undeclared (first use this function) 
hello_world.cpp:7: error: (Each undeclared identifier is reported only once for each function it appears in.) 
+0

請顯示'Magick ++ - config --cppflags'和'Magick ++ - config --ldflags --libs'的輸出 – iehrlich

+0

'-fopenmp'從哪裏來? –

回答

0

只需從--cppflags中刪除-fopenmp即可。它由Magick(Core|Wand|++)-config添加,因爲編譯器支持該功能(在自動配置時),但並不意味着(或檢查)OpenMP是否可用於系統。我在使用LLVM-clang時總是這樣,忘記安裝OpenMP plugin

你可以修復這個問題,重新配置ImageKagick並用--disable-openmp重新編譯。

或者可能爲gcc安裝OpenMP

或者只是去掉標籤

g++ -o hello \ 
    `Magick++-config --cppflags | sed 's/-fopenmp//g'` \ 
    `Magick++-config --libs | sed 's/-fopenmp//g'` \ 
    hello_world.cpp 

個人 - 我會建議剛剝離出的標籤,直到你更舒適的編譯+鏈接,然後看到安裝的OpenMP插件/功能。