【问题标题】:Compile c++ code using Magick++ and openMPI使用 Magick++ 和 openMPI 编译 c++ 代码
【发布时间】:2015-01-27 00:51:28
【问题描述】:

我正在尝试使用 Magick++ 库编译我的 C++ 代码,以使用 openMPI 以分布式方式操作图像,当我尝试编译它时遇到一些错误。

这是我的代码:

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

int main(int argc, char **argv){

int rank, numtask;

InitializeMagick(*argv);

Image image;
try { 
    // Read a file into image object 
    image.read( "test_image.jpg" );
    image.type( GrayscaleType );
    Blob blob; 
    image.magick( "JPEG" ); // Set JPEG output format 
    image.write( &blob );

} 
catch( Exception &error_ ){ 
    cout << "Caught exception: " << error_.what() << endl; 
    return 1; 
 } 

//Now in the "distributed enviroment" I just print an hello world to test it. 
MPI_Init(&argc,&argv);

MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &numtask);

cout<<"HelloWorld\n";

MPI_Finalize();

}

这是我在 shell 上输入的命令

mpiCC openmpi_project.cc -o openmpi_project

这是shell的输出

openmpi_project.cc:(.text+0x1d): 未定义的引用 "Magick::InitializeMagick(char const*)"

openmpi_project.cc:(.text+0x29): 未定义的引用 "魔术::Image::Image()"

openmpi_project.cc:(.text+0x5d): 未定义的引用 "Magick::Image::read(std::string const&)"

openmpi_project.cc:(.text+0x86): 未定义的引用 "Magick::Image::type(MagickCore::ImageType)"

openmpi_project.cc:(.text+0x92): rundefined 引用 "魔术::Blob::Blob()"

openmpi_project.cc:(.text+0xc6): 未定义的引用 "Magick::Image::magick(std::string const&)"

openmpi_project.cc:(.text+0xf1): 未定义的引用 "Magick::Image::write(Magick::Blob*)"

openmpi_project.cc:(.text+0xfd): 未定义的引用 "魔术::Blob::~Blob()"

openmpi_project.cc:(.text+0x158): 未定义的引用 "魔术::Image::~Image()"

openmpi_project.cc:(.text+0x1d3): 未定义的引用 "魔术::Blob::~Blob()"

openmpi_project.cc:(.text+0x261): 未定义的引用 "魔术::Image::~Image()"

/tmp/ccqFzUdy.o:(.gcc_except_table+0x58): 未定义的引用 “Magick::Exception 的类型信息”

【问题讨论】:

标签: c++ imagemagick openmpi magick++


【解决方案1】:

ImageMagick 附带配置实用程序。对于 Magick++,此实用程序是 Magick++-config。请参阅the API docs 下的使用小节。

LDFLAGS=$(Magick++-config --ldflags)
CXXFLAGS=$(Magick++-config --cxxflags)
$(CC) $CXXFLAGS openmpi_project.cc $LDFLAGS -o openmpi_project

跳转到 MPI compiling/linking docs,并将 Magick++ 的附加标志集成到 mpiCC

LDFLAGS=$(Magick++-config --ldflags)
CXXFLAGS=$(Magick++-config --cxxflags)
mpiCC --with-wrapper-cxxflags=$CXXFLAGS openmpi_project.cc \
      --with-wrapper-ldflags=$LDFLAGS -o openmpi_project

【讨论】:

  • @emcconville 很好的答案,这几天我一直在为这个问题头疼。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-16
  • 2014-09-09
  • 2015-06-06
  • 1970-01-01
  • 1970-01-01
  • 2017-07-28
  • 2019-07-12
相关资源
最近更新 更多