C ++ mingw链接Magick ++库错误

时间:2015-07-20 13:48:09

标签: c++ windows linker

我正在尝试使用mingw编译器在Windows上使用ImageMagicks C ++库(Magick ++)编译以下源文件。

#include <Magick++.h>
#include <fstream>
#include <sstream>

int main(int argc, char** argv) {
    Magick::InitializeMagick(*argv);

    Magick::Blob blob;

    std::ifstream in("test.png", std::ios::in | std::ios::binary);
    std::stringstream stream;
    stream << in.rdbuf();
    std::string imgData = stream.str();

    blob.update(imgData.c_str(), imgData.size());

    Magick::Image img(blob);
    img.magick("GIF");
    img.write("test.gif");
    return 0;
}

但我总是得到以下错误:

C:\Users\Johannes\Desktop\test>g++ test.cpp -o test -I"C:/Program Files/ImageMagick-6.9.1-Q16/include/" -L"C:/Program Files/ImageMagick-6.9.1-Q16/lib/" -lCORE_RL_magick_ -lCORE_RL_Magick++_ -lCORE_RL_wand_ -L"C:/MinGW/lib/" -L"C:/MinGW/bin/"

C:\Users\Johannes\AppData\Local\Temp\cc2h8X3v.o:test.cpp:(.text+0x25): undefined reference to `Magick::InitializeMagick(char const*)'
C:\Users\Johannes\AppData\Local\Temp\cc2h8X3v.o:test.cpp:(.text+0x2f): undefined reference to `Magick::Blob::Blob()'
C:\Users\Johannes\AppData\Local\Temp\cc2h8X3v.o:test.cpp:(.text+0xe5): undefined reference to `Magick::Blob::update(void const*, unsigned int)'
C:\Users\Johannes\AppData\Local\Temp\cc2h8X3v.o:test.cpp:(.text+0xf8): undefined reference to `Magick::Image::Image(Magick::Blob const&)'
C:\Users\Johannes\AppData\Local\Temp\cc2h8X3v.o:test.cpp:(.text+0x130): undefined reference to `Magick::Image::magick(std::string const&)'
C:\Users\Johannes\AppData\Local\Temp\cc2h8X3v.o:test.cpp:(.text+0x17c): undefined reference to `Magick::Image::write(std::string const&)'
C:\Users\Johannes\AppData\Local\Temp\cc2h8X3v.o:test.cpp:(.text+0x1a2): undefined reference to `Magick::Image::~Image()'
C:\Users\Johannes\AppData\Local\Temp\cc2h8X3v.o:test.cpp:(.text+0x1d0): undefined reference to `Magick::Blob::~Blob()'
C:\Users\Johannes\AppData\Local\Temp\cc2h8X3v.o:test.cpp:(.text+0x217): undefined reference to `Magick::Image::~Image()'
C:\Users\Johannes\AppData\Local\Temp\cc2h8X3v.o:test.cpp:(.text+0x255): undefined reference to `Magick::Blob::~Blob()'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\Johannes\AppData\Local\Temp\cc2h8X3v.o: bad reloc address 0x20 in section `.eh_frame$_ZStorSt13_Ios_OpenmodeS_'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

在Linux(Ubuntu)上,使用此构建命令一切正常:

g++ test.cpp -o test -fopenmp -I/usr/include/ImageMagick -fopenmp -I/usr/include/ImageMagick -lMagick++ -lMagickCore -lMagick++ -lMagickCore

我正在使用ImageMagicks版本:ImageMagick-6.9.1-8-Q16-x64

这是我的编译器版本:

C:\Users\Johannes>g++ --version
g++ (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\Users\Johannes>

这是我使用mingw的版本:

C:\MinGW\bin>"mingw32-c++.exe" --version
mingw32-c++.exe (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\MinGW\bin>

这是lib文件夹的内容:

C:\Program Files\ImageMagick-6.9.1-Q16\lib>dir
 Volume in Laufwerk C: hat keine Bezeichnung.
 Volumeseriennummer: CA70-61AA

 Verzeichnis von C:\Program Files\ImageMagick-6.9.1-Q16\lib

17.07.2015  18:27    <DIR>          .
17.07.2015  18:27    <DIR>          ..
11.07.2015  04:28           964.574 CORE_RL_Magick++_.lib
11.07.2015  04:25           255.094 CORE_RL_magick_.lib
11.07.2015  04:27           151.616 CORE_RL_wand_.lib
               3 Datei(en),      1.371.284 Bytes
               2 Verzeichnis(se), 272.797.249.536 Bytes frei

C:\Program Files\ImageMagick-6.9.1-Q16\lib>

这些是Magick ++的头文件:

C:\Program Files\ImageMagick-6.9.1-Q16\include>dir
 Volume in Laufwerk C: hat keine Bezeichnung.
 Volumeseriennummer: CA70-61AA

 Verzeichnis von C:\Program Files\ImageMagick-6.9.1-Q16\include

17.07.2015  15:48    <DIR>          .
17.07.2015  15:48    <DIR>          ..
17.07.2015  15:48    <DIR>          magick
17.07.2015  15:48    <DIR>          Magick++
11.07.2015  04:17               713 Magick++.h
17.07.2015  15:48    <DIR>          wand
               1 Datei(en),            713 Bytes
               5 Verzeichnis(se), 272.797.179.904 Bytes frei

C:\Program Files\ImageMagick-6.9.1-Q16\include>

最后但并非最不重要的系统的PATH变量:

C:\>echo %PATH%
c:\program files\graphicsmagick-1.3.20-q16;C:\Program Files\ImageMagick-6.9.1-Q1
6;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\
PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\
System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\MinGW\bin;C
:\Program Files (x86)\CMake\bin

C:\>

由于

0 个答案:

没有答案