简体   繁体   English

使用Magick ++和openMPI编译C ++代码

[英]Compile c++ code using Magick++ and openMPI

I'm trying to compile my C++ code using Magick++ library to manipulate images in a distributed way using openMPI and I get some errors when I try to compile it. 我正在尝试使用Magick++库编译我的C ++代码,以使用openMPI以分布式方式处理图像,并且在尝试编译时会出现一些错误。

This is my code: 这是我的代码:

#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();

} }

this is the command that I type on the shell 这是我在外壳上键入的命令

mpiCC openmpi_project.cc -o openmpi_project

and this is the output of the shell 这是外壳的输出

openmpi_project.cc:(.text+0x1d): undefined reference to "Magick::InitializeMagick(char const*)" openmpi_project.cc:(.text+0x1d):对“ Magick :: InitializeMagick(char const *)”的未定义引用

openmpi_project.cc:(.text+0x29): undefined reference to "Magick::Image::Image()" openmpi_project.cc:(.text+0x29):对“ Magick :: Image :: Image()”的未定义引用

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

openmpi_project.cc:(.text+0x86): undefined reference to "Magick::Image::type(MagickCore::ImageType)" openmpi_project.cc:(.text+0x86):对“ Magick :: Image :: type(MagickCore :: ImageType)”的未定义引用

openmpi_project.cc:(.text+0x92): rundefined reference to "Magick::Blob::Blob()" openmpi_project.cc:(.text+0x92):运行定义的对“ Magick :: Blob :: Blob()”的引用

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

openmpi_project.cc:(.text+0xf1): undefined reference to "Magick::Image::write(Magick::Blob*)" openmpi_project.cc:(.text+0xf1):对“ Magick :: Image :: write(Magick :: Blob *)”的未定义引用

openmpi_project.cc:(.text+0xfd): undefined reference to "Magick::Blob::~Blob()" openmpi_project.cc:(.text+0xfd):对“ Magick :: Blob ::〜Blob()”的未定义引用

openmpi_project.cc:(.text+0x158): undefined reference to "Magick::Image::~Image()" openmpi_project.cc:(.text+0x158):对“ Magick :: Image ::〜Image()”的未定义引用

openmpi_project.cc:(.text+0x1d3): undefined reference to "Magick::Blob::~Blob()" openmpi_project.cc:(.text+0x1d3):对“ Magick :: Blob ::〜Blob()”的未定义引用

openmpi_project.cc:(.text+0x261): undefined reference to "Magick::Image::~Image()" openmpi_project.cc:(.text+0x261):对“ Magick :: Image ::〜Image()”的未定义引用

/tmp/ccqFzUdy.o:(.gcc_except_table+0x58): undefined reference to "typeinfo for Magick::Exception" /tmp/ccqFzUdy.o:(.gcc_except_table+0x58):对“ Magick :: Exception的typeinfo”的未定义引用

ImageMagick ships with config utilities. ImageMagick附带配置实用程序。 For Magick++ this utility is Magick++-config . 对于Magick ++,此实用程序是Magick++-config See the Usage sub-section under the API docs . 请参阅API文档用法”小节。

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

Jump over to the MPI compiling/linking docs , and integrate Magick++'s additional flags to mpiCC 跳转到MPI 编译/链接文档 ,并将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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM