How to install IMageMagick and ImageWand on Mac OS? [duplicate] - c++

I'm programming in C. I want use ImageMagick library but some fuction can't be resolved.
This is my cMakeList.txt file:
cmake_minimum_required(VERSION 3.3)
project(WebServer)
set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(SOURCE_FILES io.c server.c lock_fcntl.c sig_handler.c thread_job.c msg_parser.c)
set(LIB http-parser-master/http_parser.c )
set(CMAKE_USE_PTHREADS_INIT true)
set(CMAKE_USE_PTHREADS_INIT ON)
find_package(Threads REQUIRED)
find_package(ImageMagick COMPONENTS ImageWand)
include_directories(header)
include_directories(http-parser-master)
#include_directories(/usr/local/include/ImageMagick-7/MagickWand)
include_directories(${ImageMagick_INCLUDE_DIRS})
add_executable(server ${SOURCE_FILES} ${LIB})
add_executable(client client.c io.c)
add_executable(main main.c io.c)
target_link_libraries(main ${ImageMagick_LIBRARIES})
target_link_libraries(server Threads::Threads)
and this is the source main.c:
#include <ImageMagick-7/MagickWand/MagickWand.h>
#include "basic.h"
void convert_image(char *path, float quality_factor, char *out) {
int width, height;
MagickWand *n_wand = NULL;
MagickWandGenesis();
m_wand = (struct MagickWand *) NewMagickWand();
MagickReadImage(m_wand,"logo:");
width = MagickGetImageWidth(m_wand);
height = MagickGetImageHeight(m_wand);
if((width /= 2) < 1)width = 1;
if((height /= 2) < 1)height = 1;
MagickResizeImage(m_wand,width,height,LanczosFilter,1);
MagickSetImageCompressionQuality(m_wand,95);
MagickWriteImage(m_wand,"logo_resize.jpg");
if(m_wand)m_wand = (struct MagickWand *) DestroyMagickWand(m_wand);
MagickWandTerminus();
}
Only MagickWandGenesis() and MagickWandTerminus() are resolved.
The installation of the library ends correctly. How to solve?
edit:
Running I get the error:
/usr/local/include/ImageMagick-7/MagickWand/MagickWand.h:29:40: fatal error: MagickCore/magick-config.h: File o directory non esistente
# include "MagickCore/magick-config.h"
^
compilation terminated.
make[3]: *** [CMakeFiles/main.dir/main.c.o] Errore 1
make[2]: *** [CMakeFiles/main.dir/all] Errore 2
make[1]: *** [CMakeFiles/main.dir/rule] Errore 2
make: *** [main] Errore 2
I tried the solution shown here but does not work:
ImageMagick No such file or directory

The library structure is that:
ImageMagick-7
├── MagickCore
│   ├── magick-config.h
|
└── MagickWand
├── MagickWand.h
MagickWand.h includes some header in MagickCore.
I fix replacing include_directories(${ImageMagick_INCLUDE_DIRS})
with include_directories(/usr/local/include/ImageMagick-7).
I don't know why but if i print ${ImageMagick_INCLUDE_DIRS} this is not set.

Related

CMake linking error (undefined reference to function)

I'm working on C/C++ cross platform application. I'm using CMake for build process.
The project structure below is simplified, narrowing to the issue.
├── CMakeLists.txt
├── Common_libs
│ ├── CMakeLists.txt
│ └── File_Process_... (.cc/.h, 4 each)
└── MAIN
├── CMakeLists.txt
└── (Other subdirs and sources/headers)
./CMakeLists.txt:(Common_libs)
# CMakeLists.txt : CMake project, include source and define
# project specific logic here.
#
set(PKG_NAME File_Process)
add_library(${PKG_NAME} STATIC
include/File_Process_Interface.h
include/File_Process_Types.h
include/FP_Directory.h
include/FP_File.h
include/FP_FileLP.h
include/FP_Includes.h
include/Filestruct.h
../../MAIN/error.h
source/File_Process_Factory.cpp
source/FP_Directory.cpp
source/FP_File.cpp
source/FP_FileLP.cpp)
target_include_directories(${PKG_NAME} PUBLIC include)
target_include_directories(${PKG_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/Common/Resources/3RD_PARTYLibrary/include)
if (WIN32)
target_include_directories(${PKG_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/Common/Resources/Windows/Includes)
install(TARGETS ${PKG_NAME} ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/Common_libs/dist/${CMAKE_BUILD_TYPE}/Win/)
else()
SET(CMAKE_CXX_FLAGS "-std=c++11")
install(TARGETS ${PKG_NAME} ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/Common_libs/dist/${CMAKE_BUILD_TYPE}/Linux/)
endif(WIN32)
target_include_directories(${PKG_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
File_Process_Interface.h
namespace AppExecutable{
namespace Common {
class File_Process_Factory {
public:
enum File_ProcessObjectType {
FP_File, FP_Directory, FP_FileLP, Automatic_Detection
};
static IFile_Process* Create(File_ProcessObjectType type = FP_File, std::string source = "");
};
}
}
File_Process_Factory.cpp
namespace AppExecutable{
namespace Common {
IFile_Process* File_Process_Factory::Create(File_ProcessObjectType type, std::string source) {
switch (type) {
case File_Process_Factory::Automatic_Detection:
struct stat st;
if (stat(source.c_str(), &st) == -1) {
return NULL;
}
else {
if (S_ISDIR(st.st_mode)) {
return (IFile_Process*) (new Common::FP_Directory());
}
else {
if (source.rfind(".xyz") == (source.length() - 4)) {
return (IFile_Process*) (new Common::FP_FileLP());
}
else {
return (IFile_Process*) (new Common::FP_File());
}
}
}
//return (IFile_Process*)new Common::Automatic_Detection();
break;
case File_Process_Factory::FP_File:
return (IFile_Process*) (new Common::FP_File());
break;
case File_Process_Factory::FP_Directory:
return (IFile_Process*) (new Common::FP_Directory());
break;
case File_Process_Factory::FP_FileList:
return (IFile_Process*) (new Common::FP_FileLP());
break;
default:
throw ("Unknown File_ProcessObjectType");
}
}
./CMakeLists.txt:(MAIN)
cmake_minimum_required (VERSION 3.8)
project(AppExecutable C CXX)
cmake_policy(SET CMP0015 NEW)
if (WIN32)
include_directories(MAIN
MAIN/shared)
link_directories(../Common_libs/dist/${CMAKE_BUILD_TYPE}/Win/)
else()
include_directories(MAIN
MAIN/shared)
endif(WIN32)
file(GLOB SOURCES
*.cpp
shared/*.cpp
shared/*.c)
# Add source to this project's executable.
if (WIN32)
add_executable (AppExecutable ${SOURCES})
install(TARGETS AppExecutable DESTINATION ${CMAKE_SOURCE_DIR}/Application/Windows/)
target_link_libraries(AppExecutable File_Process)
else()
add_executable (AppExecutable ${SOURCES})
install(TARGETS AppExecutable DESTINATION ${CMAKE_SOURCE_DIR}/Application/Linux/)
target_link_libraries(AppExecutable File_Process)
endif(WIN32)
SET_TARGET_PROPERTIES(AppExecutable PROPERTIES DEBUG_POSTFIX "_debug")
Finally, when I do make, the following error is generated:
[ 33%] Built target Common_libs
[ 38%] Linking CXX executable AppExecutable
CMakeFiles/AppExecutable.dir/MAIN/FileEntry.cpp.o: In function `AppExecutable::Common::FileEntry::FileSimulation(int, char**)':
FileEntry.cpp:(.text+0xaa9): undefined reference to `AppExecutable::Common::File_Process_Factory::Create(AppExecutable::Common::File_Process_Factory::File_ProcessObjectType, std::string)'
collect2: error: ld returned 1 exit status
make[2]: *** [AppExecutable/AppExecutable] Error 1
make[1]: *** [AppExecutable/CMakeFiles/AppExecutable.dir/all] Error 2
make: *** [all] Error 2
link.txt
/opt/gcc54/bin/g++ -std=c++11 -O3 -DNDEBUG -static-libgcc -static-libstdc++ CMakeFiles/AppExecutable.dir/Output_App.cpp.o CMakeFiles/AppExecutable.dir/FileEntry.cpp.o CMakeFiles/AppExecutable.dir/AppExecutable.cpp.o CMakeFiles/AppExecutable.dir/ABCBaseClass.cpp.o CMakeFiles/AppExecutable.dir/ABCControl.cpp.o CMakeFiles/AppExecutable.dir/shared/CsvReader.c.o CMakeFiles/AppExecutable.dir/shared/OutputInterface.cpp.o CMakeFiles/AppExecutable.dir/shared/DataBlock.cpp.o CMakeFiles/AppExecutable.dir/shared/lElement.cpp.o CMakeFiles/AppExecutable.dir/shared/lParser.cpp.o CMakeFiles/AppExecutable.dir/shared/lParserCApi.cpp.o CMakeFiles/AppExecutable.dir/shared/ssupport.cpp.o CMakeFiles/AppExecutable.dir/shared/lVersionParser.c.o -o AppExecutable ../Common_libs/libFile_Process.a
I'm able to generate executable in Windows, I'm having issue on linux.
I've been trying to fix this for some time. Why it is showing errors if it has already been built before the linkage?

Build error : undefined reference to `cv_bridge::CvImage::toImageMsg() const'

I am using ROS Kinetic and trying to write a program that would read two videos and publish them on two different topics. But I think I've made some mistake in linking OpenCV libraries. I am getting the following errors.
CMakeFiles/src.dir/src/src.cpp.o: In function `main':
src.cpp:(.text+0x3fd): undefined reference to `cv_bridge::CvImage::toImageMsg() const'
src.cpp:(.text+0x56d): undefined reference to `cv_bridge::CvImage::toImageMsg() const'
collect2: error: ld returned 1 exit status
MultiCamImages/CMakeFiles/src.dir/build.make:165: recipe for target 'MultiCamImages/src' failed
make[2]: *** [MultiCamImages/src] Error 1
CMakeFiles/Makefile2:1089: recipe for target 'MultiCamImages/CMakeFiles/src.dir/all' failed
make[1]: *** [MultiCamImages/CMakeFiles/src.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
This is my source file:
#include <ros/ros.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char** argv){
ros::init(argc, argv, "PublishMultiCamImages");
ros::NodeHandle nh;
image_transport::ImageTransport it(nh);
image_transport::Publisher pub1 = it.advertise("/camera/image_raw1", 1);
image_transport::Publisher pub2 = it.advertise("/camera/image_raw2", 1);
cv::Mat im;
cv::String Path1("/home/akanksha/COSLAM_Dataset/EA-01/grayscale/*.jpg");
cv::String Path2("/home/akanksha/COSLAM_Dataset/EA-02/grayscale/*.jpg");
//time = ros::Time::now();
vector<cv::String> fn1;
vector<cv::String> fn2;
cv::glob(Path1,fn1, true); // recurse
cv::glob(Path2,fn2, true);
ros::Rate r(50);
int l1 = fn1.size();
int l2 = fn2.size();
int count1 = 0, count2 = 0;
bool flag;
while(ros::ok()){
flag = true;
if(count1 < l1){
cv::Mat image1 = cv::imread(fn1[count1]);
sensor_msgs::ImagePtr msg1 = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image1).toImageMsg();
pub1.publish(msg1);
count1++;
flag = false;
}
if(count2 < l2){
cv::Mat image2 = cv::imread(fn2[count2]);
sensor_msgs::ImagePtr msg2 = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image2).toImageMsg();
pub2.publish(msg2);
count2++;
flag = false;
}
if(flag)
break;
r.sleep();
}
ros::shutdown();
return 0;
}
This is my CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(MultiCamImages)
find_package(catkin REQUIRED COMPONENTS
roscpp
image_transport
OpenCV
)
# find_package(OpenCV REQUIRED)
set(OpenCV_LIBS opencv_core opencv_imgproc opencv_calib3d opencv_video opencv_features2d opencv_ml opencv_highgui opencv_objdetect)
add_executable(src src/src.cpp)
target_link_libraries(src ${catkin_LIBRARIES} ${OpenCV_LIBS})
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES MultiCamImages
# CATKIN_DEPENDS roscpp
# DEPENDS system_lib
)
include_directories(
${catkin_INCLUDE_DIRS}
)
And this is my pakage.xml
<?xml version="1.0"?>
<package>
<name>MultiCamImages</name>
<version>0.0.0</version>
<description>The MultiCamImages package</description>
<maintainer email="akanksha#todo.todo">akanksha</maintainer>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<run_depend>roscpp</run_depend>
<build_depend>sensor_msgs</build_depend>
<run_depend>sensor_msgs</run_depend>
<build_depend>cv_bridge</build_depend>
<run_depend>cv_bridge</run_depend>
</package>
If you could point out the problem that would be a great help. Thanks!
It doesn't look like you are linking cv_bridge in the cmake file. Maybe you want this:
find_package(catkin REQUIRED COMPONENTS
cv_bridge
roscpp
image_transport
OpenCV
)
Actually the way Joseph uses OpenCV libraries for linking is not right, since OpenCV does not belong to the standard package of ROS as with cv_bridge. In this case, you need to separately use find_package for OpenCV as with boost like this:
find_package(OpenCV REQUIRED)
# Or you may add specific major portion of OpenCV version, e.g., OpenCV3
find_package(OpenCV 3 REQUIRED)

Using SDL2 with CLion on OS X

So I am trying to get SDL2 to work with CLion (So that I can experiment/learn).
My main code is as such:
#include <iostream>
#include <SDL.h>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
bool init();
SDL_Window* gWindow = NULL;
SDL_Surface* gScreenSurface = NULL;
SDL_Surface* gHelloWorld = NULL;
bool init(){
bool success = true;
/*if(SDL_Init(SDL_INIT_VIDEO)<0){
success = false;
}
else{
}*/
return success;
}
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
And my CMake file looks like this
cmake_minimum_required(VERSION 3.6)
project(SDL2_Lesson_1)
set(CMAKE_CXX_STANDARD 11)
# includes cmake/FindSDL2.cmake
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
set(SOURCE_FILES Lesson_1.cpp)
add_executable(SDL2_App ${SOURCE_FILES})
target_link_libraries(SDL2_App ${SDL2_LIBRARY})
set(SOURCE_FILES Lesson_1.cpp)
add_executable(SDL2_Lesson_1 ${SOURCE_FILES})
Also, I have a file FindSDL2.cmake from here in a folder cmake within the project folder.
Now, with the files as I have them posted, everything compiles and runs fine. BUT, when I uncomment the commented section within init(), the compilation breaks down and gives me the following error:
Undefined symbols for architecture x86_64:
"_SDL_Init", referenced from:
init() in Lesson_1.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [SDL2_Lesson_1] Error 1
make[2]: *** [CMakeFiles/SDL2_Lesson_1.dir/all] Error 2
make[1]: *** [CMakeFiles/SDL2_Lesson_1.dir/rule] Error 2
make: *** [SDL2_Lesson_1] Error 2
Note: Lesson_1.cpp is the file with the main code. Also, this is only part of the error.
Use find_library() instead of find_package()
find_library(SDL2_LIBRARY SDL2 "path/to/your/library_bundle")
find_library(SDL2_App ${SDL2_LIBRARY})

Old OPENGL code, want to use glPushMatrix()

1st Question!
I'm trying to compile some openGL code where I use glPushMatrix().
I plan on reformatting the code to more recent practices (because glPushMatrix is deprecated), but,for now, I'd like to use a version of (openGL, GLU, GLUT)? where this function works.
My current cmake file looks like this
#CMakeLists.txt
cmake_minimum_required (VERSION 2.6)
project (PROJECTOR)
set( PROJECTOR_VERSION_MAJOR 0)
set( PROJECTOR_VERSION_MINOR 1)
add_executable( Projector.run /*...buncha files */ )
find_package(Boost)
include_directories(${Boost_INCLUDE_DIRS})
find_package(ImageMagick COMPONENTS Magick++)
include_directories(${ImageMagick_INCLUDE_DIRS})
# TODO - this doesn't rollback versions. It just sets a min version requirement.
# I'd like to roll back the versions.
find_package(OpenGL 2.0)
include_directories(${OpenGL_INCLUDE_DIRS})
find_package(GLUT REQUIRED)
include_directories(${GLUT_INCLUDE_DIRS})
find_package(GLU)
include_directories(${GLUE_INCLUDE_DIRS})
target_link_libraries(Projector.run ${ImageMagick_LIBRARIES})
target_link_libraries(Projector.run ${Boost_LIBRARIES})
target_link_libraries(Projector.run ${GLU_LIBRARIES})
target_link_libraries(Projector.run ${OpenGL_LIBRARIES})
target_link_libraries(Projector.run ${GLUT_LIBRARIES})
#
And this is the error output:
/usr/bin/ld: CMakeFiles/Projector.run.dir/open_image.cpp.o: undefined reference to symbol 'glPushMatrix'
//usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [Projector.run] Error 1
make[1]: *** [CMakeFiles/Projector.run.dir/all] Error 2
make: *** [all] Error 2
And this is a code snippet:
...
glPushMatrix();
int img_height,img_width = 3;
int row,col = 0;
for(col = 0; col < img_height; col++ )
{
for(row = 0; row < img_width; row++){
glTranslatef(CUBE_DIMEN,0.0f,0.0f);
glColor3f(r_comp,g_comp,b_comp);
glutSolidCube(CUBE_DIMEN);
}
glTranslatef(-1 * img_width * CUBE_DIMEN, -CUBE_DIMEN, 0.0f);
}
glPopMatrix();
...
What should I add so that my program will build?
Compile using the -lGL flag to include the library:
g++ -o main main.cpp -Wall -std=c++11 -lglut -lGL

Undefined reference to "function name from external library"

I'm using Ubuntu 12 64 bit, installed fftw library version 2.1.5.
I have a c++ project with use CMake to build the make file. This is my cmakelist.text:
project(MP)
cmake_minimum_required(VERSION 2.8)
if(TYPE STREQUAL "Debug")
set(CMAKE_BUILD_TYPE "Debug")
else()
set(CMAKE_BUILD_TYPE "Release")
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions( -std=c++11 )
endif()
find_package(GLUT REQUIRED)
find_package(OpenGL REQUIRED)
find_library(GLUI libglui.a ./vendor/lib)
include_directories(${OPENGL_INCLUDE_DIR}
./vendor/include)
LINK_DIRECTORIES(/usr/local/lib)
LINK_DIRECTORIES(/usr/lib)
LINK_DIRECTORIES(/usr/bin)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
target_link_libraries(${PROJECT_NAME} GL GLU glut ${GLUI})
When I tried running the make file create by Cmake, i got this problem:
CMakeFiles/SciVis.dir/Simulation.cc.o: In function `Simulation::init_simulation(unsigned long)':
Simulation.cc:(.text+0x2d5): undefined reference to `rfftw2d_create_plan'
Simulation.cc:(.text+0x2ee): undefined reference to `rfftw2d_create_plan'
CMakeFiles/SciVis.dir/Simulation.cc.o: In function `Simulation::solve()':
Simulation.cc:(.text+0x881): undefined reference to `rfftwnd_one_real_to_complex'
Simulation.cc:(.text+0x891): undefined reference to `rfftwnd_one_real_to_complex'
Simulation.cc:(.text+0xa7f): undefined reference to `rfftwnd_one_complex_to_real'
Simulation.cc:(.text+0xa8f): undefined reference to `rfftwnd_one_complex_to_real'
CMakeFiles/SciVis.dir/Simulation.cc.o: In function `Simulation::FFT(int, void*)':
Simulation.cc:(.text+0x390): undefined reference to `rfftwnd_one_complex_to_real'
Simulation.cc:(.text+0x3a0): undefined reference to `rfftwnd_one_real_to_complex'
collect2: error: ld returned 1 exit status
make[2]: *** [SciVis] Error 1
make[1]: *** [CMakeFiles/SciVis.dir/all] Error 2
make: *** [all] Error 2
In my Simulation.cc file:
#include <fftw.h>
void Simulation::init_simulation(size_t n)
{
//Allocate data structures
size_t dim = n * 2 * (n / 2 + 1);
vx = new fftw_real[dim];
vy = new fftw_real[dim];
vx0 = new fftw_real[dim];
vy0 = new fftw_real[dim];
fx = new fftw_real[n * n];
fy = new fftw_real[n * n];
rho = new fftw_real[n * n];
rho0 = new fftw_real[n * n];
plan_rc = rfftw2d_create_plan(n, n, FFTW_REAL_TO_COMPLEX, FFTW_IN_PLACE);
plan_cr = rfftw2d_create_plan(n, n, FFTW_COMPLEX_TO_REAL, FFTW_IN_PLACE);
// Initialize data structures to 0
for (size_t i = 0; i < n * n; i++)
{
vx[i] = vy[i] = vx0[i] = vy0[i] = fx[i] = fy[i] = rho[i] = rho0[i] = 0.0f;
}
}
void Simulation::FFT(int direction,void* vx)
{
if(direction==1) rfftwnd_one_real_to_complex(plan_rc,(fftw_real*)vx,(fftw_complex*)vx);
else rfftwnd_one_complex_to_real(plan_cr,(fftw_complex*)vx,(fftw_real*)vx);
}
I dont know where I were wrong, can someone please help me ?
Thank you very much.
You're not linking against FFTW, you need to make CMake find the library and link against it first, put this file in your project's directory under a new folder "CMakeModules".
FindFFTW.cmake
# - Find FFTW
# Find the native FFTW includes and library
#
# FFTW_INCLUDES - where to find fftw3.h
# FFTW_LIBRARIES - List of libraries when using FFTW.
# FFTW_FOUND - True if FFTW found.
if (FFTW_INCLUDES)
# Already in cache, be silent
set (FFTW_FIND_QUIETLY TRUE)
endif (FFTW_INCLUDES)
find_path (FFTW_INCLUDES fftw3.h)
find_library (FFTW_LIBRARIES NAMES fftw3)
# handle the QUIETLY and REQUIRED arguments and set FFTW_FOUND to TRUE if
# all listed variables are TRUE
include (FindPackageHandleStandardArgs)
find_package_handle_standard_args (FFTW DEFAULT_MSG FFTW_LIBRARIES FFTW_INCLUDES)
mark_as_advanced (FFTW_LIBRARIES FFTW_INCLUDES)
Next, add this line to the top of your CMakeLists.txt:
project(MP)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules" ${CMAKE_MODULE_PATH})
Now try this:
find_package(FFTW REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR} ${FFTW_INCLUDES}
./vendor/include)
...
target_link_libraries(${PROJECT_NAME} GL GLU glut ${GLUI} ${FFTW_LIBRARIES})