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.
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+0x29): undefined reference to
"Magick::Image::Image()"
openmpi_project.cc:(.text+0x5d): undefined reference to
"Magick::Image::read(std::string const&)"
openmpi_project.cc:(.text+0x86): undefined reference to
"Magick::Image::type(MagickCore::ImageType)"
openmpi_project.cc:(.text+0x92): rundefined reference to
"Magick::Blob::Blob()"
openmpi_project.cc:(.text+0xc6): undefined reference to
"Magick::Image::magick(std::string const&)"
openmpi_project.cc:(.text+0xf1): undefined reference to
"Magick::Image::write(Magick::Blob*)"
openmpi_project.cc:(.text+0xfd): undefined reference to
"Magick::Blob::~Blob()"
openmpi_project.cc:(.text+0x158): undefined reference to
"Magick::Image::~Image()"
openmpi_project.cc:(.text+0x1d3): undefined reference to
"Magick::Blob::~Blob()"
openmpi_project.cc:(.text+0x261): undefined reference to
"Magick::Image::~Image()"
/tmp/ccqFzUdy.o:(.gcc_except_table+0x58): undefined reference to
"typeinfo for Magick::Exception"
ImageMagick ships with config utilities. For Magick++ this utility is Magick++-config. See the Usage sub-section under the API docs.
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
LDFLAGS=$(Magick++-config --ldflags)
CXXFLAGS=$(Magick++-config --cxxflags)
mpiCC --with-wrapper-cxxflags=$CXXFLAGS openmpi_project.cc \
--with-wrapper-ldflags=$LDFLAGS -o openmpi_project
Related
I'm trying to compile a DLIB example: http://dlib.net/image_ex.cpp.html
and I copied it word-for-word:
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/image_transforms.h>
#include <fstream>
using namespace std;
using namespace dlib;
// ----------------------------------------------------------------------------
int main(int argc, char** argv)
{
try
{
// make sure the user entered an argument to this program
if (argc != 2)
{
cout << "error, you have to enter a BMP file as an argument to this program" << endl;
return 1;
}
And I used this command:
g++ dlib1.cpp -o dlib1 -std=c++11 -O3 -I ~/Packages/dlib/ -lpthread -lX11 -ljpeg -lpng -DDLIB_JPEG_SUPPORT -DDLIB_PNG_SUPPORT
And despite that command working fine months ago: [Can't include the JPEG_SUPPORT headers in a dlib cpp file ] this time, it gave me hundreds of errors:
dlibTest-0.cpp:(.text._ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_[_ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_]+0x7e): undefined reference to `dlib::png_loader::is_gray() const'
dlibTest-0.cpp:(.text._ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_[_ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_]+0x94): undefined reference to `dlib::png_loader::is_gray() const'
dlibTest-0.cpp:(.text._ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_[_ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_]+0xaa): undefined reference to `dlib::png_loader::is_graya() const'
dlibTest-0.cpp:(.text._ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_[_ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_]+0xd0): undefined reference to `dlib::png_loader::get_row(unsigned int) const'
dlibTest-0.cpp:(.text._ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_[_ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_]+0x176): undefined reference to `dlib::png_loader::get_row(unsigned int) const'
dlibTest-0.cpp:(.text._ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_[_ZNK4dlib10png_loader9get_imageINS_7array2dINS_9rgb_pixelENS_33memory_manager_stateless_kernel_1IcEEEEEEvRT_]+0x1ce): undefined reference to `dlib::png_loader::is_graya() const'
What exactly is going wrong here?
Some of the samples need a command line such as ...
g++ -std=c++11 -O3 -I.. ../dlib/all/source.cpp -lpthread -lX11 example_program_name.cpp
I guess source.cpp is a "library as cpp code" link : dlib compile
I'm trying to port over a game that I made using Allegro 5.0 (from Windows to a Raspberry Pi running Raspian). I installed Allegro and moved over all my source files, but when I try to compile using: *g++ -std=c++0x .cpp -o SpaceFighter $(pkg-config --libs allegro-5) I get the following:
/tmp/ccBliSky.o: In function main':
main.cpp:(.text+0x130): undefined reference toal_show_native_message_box'
main.cpp:(.text+0x160): undefined reference to al_init_font_addon'
main.cpp:(.text+0x164): undefined reference toal_init_ttf_addon'
main.cpp:(.text+0x168): undefined reference to al_init_image_addon'
main.cpp:(.text+0x1a4): undefined reference toal_load_ttf_font'
main.cpp:(.text+0x574): undefined reference to al_draw_textf'
/tmp/ccBMyqom.o: In functionMenuItem::MenuItem()':
MenuItem.cpp:(.text+0xa0): undefined reference to al_load_ttf_font'
/tmp/ccBMyqom.o: In functionMenuItem::~MenuItem()':
MenuItem.cpp:(.text+0x1ac): undefined reference to al_destroy_font'
/tmp/ccBMyqom.o: In functionMenuItem::Draw(GameTime const*)':
MenuItem.cpp:(.text+0x2fc): undefined reference to al_draw_text'
/tmp/ccKXP3ds.o: In functionPlayerShip::SetAudioSample(std::string)':
PlayerShip.cpp:(.text+0x604): undefined reference to al_destroy_sample'
PlayerShip.cpp:(.text+0x64c): undefined reference toal_load_sample'
collect2: error: ld returned 1 exit status
AND NO THIS IS NOT A DUPLICATE OF "What are undefined reference/unresolved external symbol errors? What are common causes and how to fix/prevent them?"
I know what usually causes most undefined reference errors. This question is specific to the allegro library I'm using.
Here's a bit of code (I'm obviously not going to post the whole game):
#include <allegro5/allegro.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_image.h>
#include <iostream>
#include "Game.h"
int main(int argc, char *argv[])
{
const char errorType[] = "Initialization Error";
const int flags = ALLEGRO_MESSAGEBOX_ERROR;
// Initialize Allegro
if (!al_init())
{
const char message[] = "Failed to initialize Allegro Library.";
//al_show_native_message_box(nullptr, "Error", errorType, message, nullptr, flags);
return -1;
}
Game game;
// Initialize a new window for gameplay.
int screenWidth = Game::GetScreenWidth();
int screenHeight = Game::GetScreenHeight();
Thanks in advance for any help!
Alegro divides its functionality across several modules. Your pkg-config line must include all the modules you are using. Try the following:
pkg-config --libs allegro-5 allegro_font-5 allegro_image-5 allegro_ttf-5
I had the same problem with the al_show_native_message_box function and I solved it by adding the following flag:
-lallegro_dialog
I have created a simple C++ application. I can compile it, and it works fine. But now I need to load the library dynamically, and I have added dlfnc.h to my project and added some more code:
#include <iostream>
#include <dlfcn.h>
void *mylib;
int eret;
using namespace std;
int main() {
mylib = dlopen("mylib.so", RTLD_LOCAL | RTLD_LAZY);
eret = dlclose(mylib);
cout << "!!!Hello, World!!!" << endl; // Prints !!!Hello, World!!!
return 0;
}
Compiling:
cd ~/workspace/LinuxGcc/src
g++ LinuxGcc.cpp
And I got a compilation error:
/tmp/ccxTLiGY.o: In function `main':
LinuxGcc.cpp:(.text+0xf): undefined reference to `dlopen'
LinuxGcc.cpp:(.text+0x25): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
dlfcn.h exist in /usr/include/.
Where is the problem?
From dlopen(3):
Link with -ldl.
so
g++ LinuxGcc.cpp -ldl
will be OK.
The solution is very simple. Add the -ldl flag for linking.
In case of the Bazel build system, linkopts = ['-ldl'].
I am new at OpenCv. I am using Eclipse C/C++. When i try to run this sample code i faced with these errors. What should i do to solve this problem? Is there any problem at configurating ?
#using namespace std;
#using namespace cv;
int main( int argc, const char** argv )
{
Mat img = imread("MyPic.JPG", CV_LOAD_IMAGE_UNCHANGED);
if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
//system("pause"); //wait for a key press
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); /
waitKey(0); //wait infinite time for a keypress
destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
return 0;
}
16:11:28 **** Incremental Build of configuration Debug for project OpenCv ****
Info: Internal Builder is used for build
g++ "-IC:\\opencv\\build\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\OpenCv.o" "..\\src\\OpenCv.cpp"
g++ "-LC:\\opencv\\build\\x86\\vc12\\lib" -o OpenCv.exe "src\\OpenCv.o" -lopencv_calib3d249 -lopencv_contrib249 -lopencv_core249 -lopencv_features2d249 -lopencv_flann249 -lopencv_gpu249 -lopencv_highgui249 -lopencv_imgproc249 -lopencv_legacy249 -lopencv_ml249 -lopencv_nonfree249 -lopencv_objdetect249 -lopencv_ocl249 -lopencv_photo249 -lopencv_stitching249 -lopencv_superres249 -lopencv_ts249 -lopencv_video249 -lopencv_videostab249
src\OpenCv.o: In function `main':
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:10: undefined reference to `cv::imread(std::string const&, int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:19: undefined reference to `cv::namedWindow(std::string const&, int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:20: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:20: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:22: undefined reference to `cv::waitKey(int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:24: undefined reference to `cv::destroyWindow(std::string const&)'
src\OpenCv.o: In function `ZN2cv3MatD1Ev':
C:/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
src\OpenCv.o: In function `ZN2cv3Mat7releaseEv':
C:/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2.exe: error: ld returned 1 exit status
problem1: you will have to include opencv / c++ header files to make it work:
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#using namespace cv;
#include <iostream>
#using namespace std;
int main() {
...
then, problem2: you cannot use the vc12 libs with mingw. (it's a different compiler)
there are no more prebuild mingw libs for opencv, so, before doing anything else, you will have to build the opencv libs locally using cmake.
again, do you really need to use mingw / eclipse ? (vs express is still free)
I need to iterate through files in a folder using C++ and I am using Boost filesystem library for that purpose.
I am trying to run the tutorial code in http://www.boost.org/doc/libs/1_54_0/libs/filesystem/doc/tutorial.html
After installing boost, running bootstrap.sh to build all libraries followed by ./b2, I am able to run some simple code. But when I try to compile the following code from the tutorial
#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
int main(int argc, char* argv[])
{
if(argc < 2)
{
std::cout << "Usage: a.out path\n";
return 1;
}
path my_path(argv[1]);
std::cout << argv[1] << " " << file_size(my_path) << '\n';
return 0;
}
using
g++ f1.cpp -lboost_filesystem -lboost_system
I get the following error:-
/tmp/cc3IJurw.o: In function `boost::filesystem::file_size(boost::filesystem::path const&)':
f1.cpp:(.text._ZN5boost10filesystem9file_sizeERKNS0_4pathE[boost::filesystem::file_size(boost::filesystem::path const&)]+0x19): undefined reference to `boost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)'
/tmp/cc3IJurw.o: In function `boost::filesystem::path::path<char*>(char* const&, boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<char*>::type>, void>::type*)':
f1.cpp:(.text._ZN5boost10filesystem4pathC2IPcEERKT_PNS_9enable_ifINS0_11path_traits11is_pathableINS_5decayIS4_E4typeEEEvE4typeE[_ZN5boost10filesystem4pathC5IPcEERKT_PNS_9enable_ifINS0_11path_traits11is_pathableINS_5decayIS4_E4typeEEEvE4typeE]+0x22): undefined reference to `boost::filesystem::path::codecvt()'
collect2: ld returned 1 exit status
Does anyone know a fix to this?