Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking error to OpenCV #4

Closed
kloukiniotisandreas opened this issue Jul 8, 2021 · 11 comments
Closed

Linking error to OpenCV #4

kloukiniotisandreas opened this issue Jul 8, 2021 · 11 comments

Comments

@kloukiniotisandreas
Copy link

I am getting a linking error to OpenCV in catkin_make. I am using ros melodic and Ubuntu 18.04.5. Have you faced this issue?

[ 92%] Built target laser_mapping
[ 94%] Building CXX object VLOAM-CMU-16833/src/lidar_odometry_mapping/CMakeFiles/lidar_odometry_mapping.dir/src/lidar_odometry_mapping.cpp.o
[ 96%] Linking CXX shared library /home/beastv2/catkin_ws/devel/lib/liblidar_odometry_mapping.so
[ 96%] Built target lidar_odometry_mapping
[ 98%] Building CXX object VLOAM-CMU-16833/src/vloam_main/CMakeFiles/vloam_main_node.dir/src/vloam_main_node.cpp.o
[100%] Linking CXX executable /home/beastv2/catkin_ws/devel/lib/vloam_main/vloam_main_node
/home/beastv2/catkin_ws/devel/lib/libimage_util.so: undefined reference to cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)' /home/beastv2/catkin_ws/devel/lib/libimage_util.so: undefined reference to cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int)'
/home/beastv2/catkin_ws/devel/lib/libimage_util.so: undefined reference to cv::calcOpticalFlowPyrLK(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputOutputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, cv::Size_<int>, int, cv::TermCriteria, int, double)' /home/beastv2/catkin_ws/devel/lib/libimage_util.so: undefined reference to cv::waitKey(int)'
/home/beastv2/catkin_ws/devel/lib/libpoint_cloud_util.so: undefined reference to `cv::setMouseCallback(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, void ()(int, int, int, int, void), void*)'
collect2: error: ld returned 1 exit status
VLOAM-CMU-16833/src/vloam_main/CMakeFiles/vloam_main_node.dir/build.make:975: recipe for target '/home/beastv2/catkin_ws/devel/lib/vloam_main/vloam_main_node' failed
make[2]: *** [/home/beastv2/catkin_ws/devel/lib/vloam_main/vloam_main_node] Error 1
CMakeFiles/Makefile2:2542: recipe for target 'VLOAM-CMU-16833/src/vloam_main/CMakeFiles/vloam_main_node.dir/all' failed
make[1]: *** [VLOAM-CMU-16833/src/vloam_main/CMakeFiles/vloam_main_node.dir/all] Error 2
Makefile:145: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

@YukunXia
Copy link
Owner

YukunXia commented Jul 8, 2021

I haven't seen this, but could you make another minimal testing folder for OpenCV? Generate a cv::Mat and print, or imread an image and visualize it out. See how you properly configure your OpenCV libraries in your CMakeLists.txt, and replace all OpenCV configurations under this repository with that one.

Some tips that may help:

  • Check your OpenCV installed folder
    • Since I set the minimal OpenCV version to 4.5.1, it's likely that you have to manually install it, rather than use one-liner from apt-get. If you do that, there's a step to choose the installation path. Maybe you can specify that path before every "find_package".
    • A lower OpenCV version may also work with this repo. I don't think I used any fancy OpenCV functions, so change the version number if that's necessary and good luck.
  • Check OpenCVconfig.cmake under a system path. At line 80 or so, OpenCV_INSTALL_PATH is defined. Check if the defined path is the correct one.

@YukunXia
Copy link
Owner

YukunXia commented Jul 9, 2021

Another suggestion could be that, in src/visual_odometry/CMakeLists.txt, at both line 145 and 152, add ${OpenCV_LIBS} along with ${catkin_LIBRARIES}.

@KalmanSLAMer
Copy link

I get this problem "tried to advertise a service that is already advertised in this node" when I run this program. Have you faced this issue? Looking forward to your reply.

@YukunXia
Copy link
Owner

I get this problem "tried to advertise a service that is already advertised in this node" when I run this program. Have you faced this issue? Looking forward to your reply.

@wwq985 This is really another problem. Could you please open another issue?

In that new issue, please attach some more information, eg. which service is complaining, which command you have input into each terminal, and if there's any other ROS program/node running.

@KalmanSLAMer
Copy link

Thanks.
when I roslaunch this,
process[vloam_main_node -1]: started with pid [18081]
process[rviz-2]: started with pid [18082]
[ERROR] [1626056112.350555675]: Tried to advertise a service that is already advertised in this node [/rviz/compressed/setparameters]
There is nothing when I play the bag.

@kloukiniotisandreas
Copy link
Author

kloukiniotisandreas commented Jul 12, 2021

Adding the path to opencv in include_directories solved the issue. Thanks
e.g.
include_directories(
${catkin_INCLUDE_DIRS}
/usr/local/include/opencv4
${OpenCV_INCLUDE_DIRS}
)

@YukunXia
Copy link
Owner

Adding the path to opencv in include_directories solved the issue. Thanks
e.g.
include_directories(
${catkin_INCLUDE_DIRS}
/usr/local/include/opencv4
${OpenCV_INCLUDE_DIRS}
)

@kloukiniotisandreas This I think means that your opencv hasn't been properly configured with CMake. ${OpenCV_INCLUDE_DIRS} should imply your opencv's include folder, eg. /usr/local/include/opencv4. Anyway, you can run the program now.

@yunkong11
Copy link

I also encountered the same problem,I am using ros melodic and Ubuntu 18.04。
[ 98%] Linking CXX executable /home/fp/catkin_ws/devel/lib/vloam_main/vloam_main_node
/home/fp/catkin_ws/devel/lib/libimage_util.so:对‘cv::imshow(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cv::_InputArray const&)’未定义的引用
/home/fp/catkin_ws/devel/lib/libimage_util.so:对‘cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int)’未定义的引用
/home/fp/catkin_ws/devel/lib/libimage_util.so:对‘cv::calcOpticalFlowPyrLK(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::_InputOutputArray const&, cv::_OutputArray const&, cv::OutputArray const&, cv::Size, int, cv::TermCriteria, int, double)’未定义的引用
/home/fp/catkin_ws/devel/lib/libimage_util.so:对‘cv::waitKey(int)’未定义的引用
/home/fp/catkin_ws/devel/lib/libpoint_cloud_util.so:对‘cv::setMouseCallback(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, void ()(int, int, int, int, void), void*)’未定义的引用
collect2: error: ld returned 1 exit status
VLOAM-CMU-16833-master/src/vloam_main/CMakeFiles/vloam_main_node.dir/build.make:818: recipe for target '/home/fp/catkin_ws/devel/lib/vloam_main/vloam_main_node' failed
make[2]: *** [/home/fp/catkin_ws/devel/lib/vloam_main/vloam_main_node] Error 1
CMakeFiles/Makefile2:3069: recipe for target 'VLOAM-CMU-16833-master/src/vloam_main/CMakeFiles/vloam_main_node.dir/all' failed
make[1]: *** [VLOAM-CMU-16833-master/src/vloam_main/CMakeFiles/vloam_main_node.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j12 -l12" failed

In vloam_main/CMakeFiles,I add the path to opencv
include_directories(
include
${catkin_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
${CERES_INCLUDE_DIRS}
/usr/local/include/opencv4
${OpenCV_INCLUDE_DIRS})

But still not resolved,Looking forward to your reply.

@YukunXia
Copy link
Owner

YukunXia commented Nov 3, 2021

I also encountered the same problem,I am using ros melodic and Ubuntu 18.04。 [ 98%] Linking CXX executable /home/fp/catkin_ws/devel/lib/vloam_main/vloam_main_node /home/fp/catkin_ws/devel/lib/libimage_util.so:对‘cv::imshow(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cv::_InputArray const&)’未定义的引用 /home/fp/catkin_ws/devel/lib/libimage_util.so:对‘cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int)’未定义的引用 /home/fp/catkin_ws/devel/lib/libimage_util.so:对‘cv::calcOpticalFlowPyrLK(cv::_InputArray const&, cv::_InputArray const&, cv::_InputArray const&, cv::InputOutputArray const&, cv::OutputArray const&, cv::OutputArray const&, cv::Size, int, cv::TermCriteria, int, double)’未定义的引用 /home/fp/catkin_ws/devel/lib/libimage_util.so:对‘cv::waitKey(int)’未定义的引用 /home/fp/catkin_ws/devel/lib/libpoint_cloud_util.so:对‘cv::setMouseCallback(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, void ()(int, int, int, int, void), void*)’未定义的引用 collect2: error: ld returned 1 exit status VLOAM-CMU-16833-master/src/vloam_main/CMakeFiles/vloam_main_node.dir/build.make:818: recipe for target '/home/fp/catkin_ws/devel/lib/vloam_main/vloam_main_node' failed make[2]: *** [/home/fp/catkin_ws/devel/lib/vloam_main/vloam_main_node] Error 1 CMakeFiles/Makefile2:3069: recipe for target 'VLOAM-CMU-16833-master/src/vloam_main/CMakeFiles/vloam_main_node.dir/all' failed make[1]: *** [VLOAM-CMU-16833-master/src/vloam_main/CMakeFiles/vloam_main_node.dir/all] Error 2 Makefile:140: recipe for target 'all' failed make: *** [all] Error 2 Invoking "make -j12 -l12" failed

In vloam_main/CMakeFiles,I add the path to opencv include_directories( include ${catkin_INCLUDE_DIRS} ${PCL_INCLUDE_DIRS} ${CERES_INCLUDE_DIRS} /usr/local/include/opencv4 ${OpenCV_INCLUDE_DIRS})

But still not resolved,Looking forward to your reply.

The main problem is that there're undefined references of OpenCV. Did you manage to compile any code using OpenCV with CMake? If so, please feel free to adapt the cmakelists under this repo. And maybe share your solution here.

https://github.com/YukunXia/VLOAM-CMU-16833/blob/master/src/vloam_main/CMakeLists.txt#L180-L182

The ${OpenCV_LIBS} should get the linking job done. Maybe you can check this variable in your cmakelists? eg. print this variable.

@YukunXia YukunXia reopened this Nov 3, 2021
@yunkong11
Copy link

Another suggestion could be that, in src/visual_odometry/CMakeLists.txt, at both line 145 and 152, add ${OpenCV_LIBS} along with ${catkin_LIBRARIES}.

I solved this problem according to your suggestion,thank you very much.

@YukunXia
Copy link
Owner

YukunXia commented Nov 7, 2021

Another suggestion could be that, in src/visual_odometry/CMakeLists.txt, at both line 145 and 152, add ${OpenCV_LIBS} along with ${catkin_LIBRARIES}.

I solved this problem according to your suggestion,thank you very much.

Cool. I'll close this issue again.

@YukunXia YukunXia closed this as completed Nov 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants