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)
Related
I am trying to do the ros_wiki tutorial to convert ROS images to OpenCV images, but when I try to compile my catkin workspace I get several pages of errors that all have the following form:
CMakeFiles/image_converter.dir/scripts/image_converter.cpp.o: In function `cv::String::~String()':
image_converter.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
I've googled around a lot and found various similar problems, but those problems were all fixed by updating the CMakeLists.txt file and the package.xml file, which did not work for me.
Here is an example of one such solution - they all center around including
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
target_link_libraries( your_target ${OpenCV_LIBS} )
in the cmakelists, but I have those already.
My C++ code:
#include <ros/ros.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <string>
#include <iostream>
const std::string wn = "OCV_window";
class ImageConverter
{
ros::NodeHandle nh_;
image_transport::ImageTransport it_;
image_transport::Subscriber image_sub_;
image_transport::Publisher image_pub_;
public:
ImageConverter()
: it_(nh_)
{
image_sub_ = it_.subscribe("/camera/color/image_raw", 1, &ImageConverter::imageCb, this);
image_pub_ = it_.advertise("/image_editor/output_image", 1);
cv::namedWindow(wn);
}
~ImageConverter()
{
cv::destroyWindow(wn);
}
void imageCb(const sensor_msgs::ImageConstPtr& incoming_message)
{
cv_bridge::CvImagePtr cvi;
try
{
cvi = cv_bridge::toCvCopy(incoming_message, sensor_msgs::image_encodings::RGB8);
}
catch (cv_bridge::Exception& e)
{
ROS_ERROR("CV_Bridge Exception: %s", e.what());
return;
}
cv::imshow(wn, cvi->image);
cv::waitKey(3);
image_pub_.publish(cvi->toImageMsg());
}
};
int main(int argc, char** argv)
{
ros::init(argc,argv, "Image_Converter");
ImageConverter ic;
ros::spin();
return(0);
}
My cmakelists file:
cmake_minimum_required(VERSION 2.8.3)
project(odom_reporter)
add_compile_options(-std=c++11)
find_package(catkin REQUIRED COMPONENTS
geometry_msgs
nav_msgs
roscpp
rospy
std_msgs
message_generation
image_transport
cv_bridge
sensor_msgs
OpenCV REQUIRED
)
add_service_files(
FILES
HMD.srv
)
catkin_package()
include_directories(
${OpenCV_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
)
add_executable (image_converter scripts/image_converter.cpp)
target_link_libraries (image_converter ${OpenCV_LIBS})
My package.xml file:
<?xml version="1.0"?>
<package format="2">
<name>odom_reporter</name>
<version>0.0.0</version>
<description>The odom_reporter package</description>
<maintainer email="calabrnb#mail.uc.edu">Nate Calabrese</maintainer>
<license>BSD</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>nav_msgs</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>message_generation</build_depend>
<build_depend>image_transport</build_depend>
<build_depend>cv_bridge</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>OpenCV</build_depend>
<build_export_depend>geometry_msgs</build_export_depend>
<build_export_depend>nav_msgs</build_export_depend>
<build_export_depend>roscpp</build_export_depend>
<build_export_depend>rospy</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>
<build_export_depend>message_runtime</build_export_depend>
<build_export_depend>image_transport</build_export_depend>
<build_export_depend>cv_bridge</build_export_depend>
<build_export_depend>sensor_msgs</build_export_depend>
<build_export_depend>OpenCV</build_export_depend>
<exec_depend>geometry_msgs</exec_depend>
<exec_depend>nav_msgs</exec_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>message_runtime</exec_depend>
<exec_depend>image_transport</exec_depend>
<exec_depend>cv_bridge</exec_depend>
<exec_depend>sensor_msgs</exec_depend>
<exec_depend>OpenCV</exec_depend>
<export>
</export>
</package>
That should work, but there's a problem: find_package() only supports finding one package per call.
You're currently trying to find two packages with it, and not finding the second one, OpenCV:
find_package(catkin REQUIRED COMPONENTS
image_transport
cv_bridge
...
)
find_package(OpenCV REQUIRED)
find_package(<package> [version] [EXACT] [QUIET] [MODULE]
[REQUIRED] [[COMPONENTS] [components...]]
[OPTIONAL_COMPONENTS components...]
[NO_POLICY_SCOPE])
I'm trying to link a library called apriltags to my c++ project. I've downloaded the source files, placed them in my project and set up the CMakeLists.txt such that the imports in my classes work fine. However, there is a referencing problem, such that I get the following error when using building with:
$ /Applications/CLion.app/Contents/bin/cmake/bin/cmake --build "/Users/petter/Desktop/MSc Project/autonomous-car/cmake-build-debug" --
target autonomous_car -- -j 2
Error:
[ 50%] Linking CXX executable bin/autonomous_car
Undefined symbols for architecture x86_64:
"AprilTags::TagDetector::extractTags(cv::Mat const&)", referenced from:
_main in main.cpp.o
"AprilTags::TagFamily::TagFamily(AprilTags::TagCodes const&)", referenced from:
AprilTags::TagDetector::TagDetector(AprilTags::TagCodes const&) in main.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]: *** [bin/autonomous_car] Error 1
make[2]: *** [CMakeFiles/autonomous_car.dir/all] Error 2
make[1]: *** [CMakeFiles/autonomous_car.dir/rule] Error 2
make: *** [autonomous_car] Error 2
Here is my code:
#include <iostream>
#include <cstring>
#include <vector>
#include <sys/time.h>
#include <AprilTags/TagDetector.h>
#include <AprilTags/Tag36h11.h>
#include <eigen3/Eigen/Dense>
using namespace AprilTags;
using namespace cv;
int main() {
VideoCapture cap(0); // open the default camera
if (!cap.isOpened()) // check if we succeeded
return -1;
namedWindow("view", 1);
TagCodes tag_codes = tagCodes36h11;
TagDetector* detector = NULL;
detector = new TagDetector(tag_codes);
for (;;) {
Mat frame;
cap >> frame; // get a new frame from camera
vector<TagDetection> det = detector->extractTags(frame);
imshow("view", frame);
if (waitKey(30) >= 0) break;
}
return 0;
}`
And here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(autonomous_car)
set(SOURCE_FILES main.cpp )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_executable(autonomous_car ${SOURCE_FILES})
add_library(apriltags ${SOURCE_FILES})
find_package(OpenCV REQUIRED)
find_package(Sdl2 REQUIRED)
find_package(PkgConfig)
pkg_check_modules(EIGEN3 REQUIRED eigen3)
include_directories(${EIGEN3_INCLUDE_DIRS})
target_link_libraries(apriltags)
target_link_libraries(autonomous_car ${OpenCV_LIBS})
target_link_libraries(autonomous_car ${Eigen_LIBS})
target_link_libraries(autonomous_car ${Sdl2_LIBS})
include_directories(apriltags . )
include_directories(${Eigen_INCLUDE_DIRS})
include_directories(${OpenCV_INCLUDE_DIRS})
include_directories(${Sdl2_INCLUDE_DIRS})
Project structure:
project structure
UPDATE: The code compiles successfully on another computer. So the problem is not with the code itself but with the way I have the dependencies installed.
If I have omitted any necessary information, please let me know. The full code can be found here.
The following code compiles and runs perfectly fine on Ubuntu 14.04 with OpenCV 3.2.0 freshly installed from SourceForge using these instructions:
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
Mat image;
image = imread( argv[1], 1 );
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitkey(0);
return 0;
}
Using the following CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
The following code fails to compile.
lane_finder.h
#ifndef Lane_Finder_h
#define Lane_Finder_h
#include <stdio.h>
#include <ros/ros.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/image_encodings.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/opencv.hpp>
class LaneFinder
{ *snip* }
#endif
lane_finder.cpp:
#include "lane_finder.h"
sensor_msgs::CompressedImage LaneFinder::findLanes(const sensor_msgs::Image& msg) {
*snip*
frame = in_msg->image;
cv::namedWindow("Display Image", cv::WINDOW_AUTOSIZE );
cv::imshow("Display Image", frame);
*snip*
}
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.3)
project(lane_finding)
find_package(catkin REQUIRED COMPONENTS roscpp cv_bridge sensor_msgs)
find_package(OpenCV REQUIRED)
catkin_package()
include_directories(include ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
add_executable(lane_finder src/lane_finder.cpp src/main.cpp)
target_link_libraries(lane_finder
${catkin_LIBRARIES}
${OpenCV_LIBS}
)
Compile Errors:
CMakeFiles/lane_finder.dir/src/lane_finder.cpp.o: In function `LaneFinder::findLanes(sensor_msgs::Image_<std::allocator<void> > const&)':
lane_finder.cpp:(.text+0x36c): undefined reference to `cv::namedWindow(cv::String const&, int)'
lane_finder.cpp:(.text+0x3c1): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
CMakeFiles/lane_finder.dir/src/lane_finder.cpp.o: In function `cv::String::String(char const*)':
lane_finder.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4f): undefined reference to `cv::String::allocate(unsigned long)'
CMakeFiles/lane_finder.dir/src/lane_finder.cpp.o: In function `cv::String::~String()':
lane_finder.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
CMakeFiles/lane_finder.dir/src/lane_finder.cpp.o: In function `cv::String::operator=(cv::String const&)':
lane_finder.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
I cannot for the life of me figure out why one runs perfectly and the other fails. I suspect that I have linked something improperly, since this is my first time attempting to compile using a header file I wrote myself. If you believe that I have omitted something important in attempting to keep this readable, I have included a link to the github repo containing the full code at the beginning of this post.
Thank you all so much.
You should add this option:
pkg-config opencv --cflags --libs
My pltform:
Win10 64bit
QT58(mingw53)
after installing opencv 3.30, I write code:
//main.cc
#include <iostream>
#include <QDir>
#include <qdebug>
#include "opencv2/opencv.hpp"
using namespace std;
int main()
{
qDebug()<< QDir::currentPath();
cv::Mat image = cv::imread("1.jpg",1);
std::cout << image.cols << " " << image.rows << std::endl;
if(image.data == 0){
cout << "No Image" <<endl;
}
else{
cout << "Image" << endl;
}
cv::namedWindow("My Image");
cv::imshow("My Image", image)
system("pause");
return 0;
}
I get the error, like this:
release/main.o:main.cpp:(.text.startup+0x170): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
collect2.exe: error: ld returned 1 exit status
I dont know why, but other functions work well,expect imshow(). And I did add the LIBS:
//qt.pro
INCLUDEPATH += D:\opencv\build\mingw\include
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_highgui330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_calib3d330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_dnn330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_features2d330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_flann330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_imgcodecs330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_imgproc330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_ml330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_objdetect330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_photo330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_shape330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_stitching330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_superres330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_video330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_videoio330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_videostab330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\opencv_ffmpeg330.dll
LIBS += D:\opencv\build\mingw\x86\mingw\bin\libopencv_core330.dll
cv_bridge depends on OpenCV 2.4. Change the CMakeLists.txt to specify:
find_package(OpenCV 2 REQUIRED)
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
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})