环境: ubuntu20.04, ROS Noetic;
rovio源码,执行
catkin_make
报如下错误:
[ 75%] Building CXX object rovio/CMakeFiles/feature_tracker_node.dir/src/feature_tracker_node.cpp.o
[ 80%] Building CXX object rovio/CMakeFiles/rovio_node.dir/src/rovio_node.cpp.o
[ 85%] Building CXX object rovio/CMakeFiles/rovio_rosbag_loader.dir/src/rovio_rosbag_loader.cpp.o
[ 90%] Linking CXX executable /home/rockeywh/code/rovio/catkin_vio/devel/lib/rovio/feature_tracker_node
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewUniform1f'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewUniform3f'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewShaderSource'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewValidateProgram'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewVertexAttribPointer'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewUseProgram'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewGetProgramiv'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `glewGetErrorString'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewCreateProgram'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewCompileShader'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewGetProgramInfoLog'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewLinkProgram'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewEnableVertexAttribArray'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewActiveTexture'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewBindBuffer'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewBufferData'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewDisableVertexAttribArray'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewGetShaderiv'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewGetUniformLocation'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewGetShaderInfoLog'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewGenBuffers'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewUniformMatrix4fv'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewUniform1i'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewAttachShader'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `__glewCreateShader'
/usr/bin/ld: /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so: undefined reference to `glewInit'
collect2: error: ld returned 1 exit status
make[2]: *** [rovio/CMakeFiles/feature_tracker_node.dir/build.make:222: /home/rockeywh/code/rovio/catkin_vio/devel/lib/rovio/feature_tracker_node] Error 1
make[1]: *** [CMakeFiles/Makefile2:569: rovio/CMakeFiles/feature_tracker_node.dir/all] Error 2
猜测是glew库链接问题,CMakeLists.txt文件中是添加了glew库的,使用ldd指令查看librovio.so依赖库的情况,返回结果如下:
~$ ldd /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so
linux-vdso.so.1 (0x00007ffd8d7f4000)
libopencv_imgproc.so.4.2 => /lib/x86_64-linux-gnu/libopencv_imgproc.so.4.2 (0x00007f3cb1b43000)
libyaml-cpp.so.0.6 => /lib/x86_64-linux-gnu/libyaml-cpp.so.0.6 (0x00007f3cb1ae8000)
libGL.so.1 => /lib/x86_64-linux-gnu/libGL.so.1 (0x00007f3cb1a60000)
libglut.so.3 => /lib/x86_64-linux-gnu/libglut.so.3 (0x00007f3cb1817000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f3cb1636000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f3cb14e7000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f3cb14ca000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3cb12d8000)
libopencv_core.so.4.2 => /lib/x86_64-linux-gnu/libopencv_core.so.4.2 (0x00007f3cb0f28000)
libGLdispatch.so.0 => /lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007f3cb0e70000)
libGLX.so.0 => /lib/x86_64-linux-gnu/libGLX.so.0 (0x00007f3cb0e3c000)
libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f3cb0cff000)
libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x00007f3cb0ceb000)
libXxf86vm.so.1 => /lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007f3cb0ce4000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3cb2174000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f3cb0cde000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f3cb0cbb000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f3cb0c9f000)
libtbb.so.2 => /lib/x86_64-linux-gnu/libtbb.so.2 (0x00007f3cb0c59000)
libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f3cb0c2d000)
libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x00007f3cb0c18000)
libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007f3cb0c12000)
libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f3cb0c0a000)
libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f3cb0bf0000)
在返回结果中没有看到glew, 应该就是glew库没有链接上, 自己写了一段测试代码,直接调用glew库,测试glew库是否能够正常调用,判断是库的问题还是代码的问题,测试代码如下:
//#define GLEW_STATIC
#include <iostream>
//#include </home/rockeywh/code/rovio/glew-2.2.0/include/GL/glew.h>
#include <GL/glew.h>
#include <GL/glut.h>
using namespace std;
int main ()
{
GLenum res = glewInit();
if (res != GLEW_OK) {
cout << "glewInit failed!!" << endl;
} else {
cout << "good!!" << endl;
}
return 0;
}
CMakeLists.txt文件内容如下:
add_compile_options(-std=c++11)
cmake_minimum_required(VERSION 3.0)
project(test)
find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})
find_package(GLUT REQUIRED)
include_directories(${GLUT_INCLUDE_DIRS})
add_executable(test test.cpp)
target_link_libraries(test ${GLUT_LIBRARIES} ${GLEW_LIBRARIES})
代码编译运行正常,没有报错,说明库是没问题的,然后将上面的test.cpp直接复制到rovio/src路径下,并在rovio/CMakeLists.txt文件中添加以下几句代码:
add_executable(test test.cpp)
target_link_libraries(test ${GLEW_LIBRARIES})
执行catkin_make,test.cpp能够编译通过,其余的还是会报上面的错误,对比发现源码中target_link_libraries中用的是 "${GLEW_LIBRARY}"
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${YamlCpp_LIBRARIES} ${OpenMP_EXE_LINKER_FLAGS} ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${GLEW_LIBRARY} ${OpenCV_LIBRARIES})
改成下面这样就能够编译通过不报错
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${YamlCpp_LIBRARIES} ${OpenMP_EXE_LINKER_FLAGS} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${GLEW_LIBRARIES} ${OpenCV_LIBRARIES})
这时再使用ldd指令查看librovio.so依赖库的情况,返回结果中就有了glew
rockeywh@rockeyw:~$ ldd /home/rockeywh/code/rovio/catkin_vio/devel/lib/librovio.so
linux-vdso.so.1 (0x00007ffe68df5000)
libopencv_imgproc.so.4.2 => /lib/x86_64-linux-gnu/libopencv_imgproc.so.4.2 (0x00007fc7eadb3000)
libyaml-cpp.so.0.6 => /lib/x86_64-linux-gnu/libyaml-cpp.so.0.6 (0x00007fc7ead58000)
libGL.so.1 => /lib/x86_64-linux-gnu/libGL.so.1 (0x00007fc7eacd0000)
libglut.so.3 => /lib/x86_64-linux-gnu/libglut.so.3 (0x00007fc7eaa87000)
libGLEW.so.2.1 => /lib/x86_64-linux-gnu/libGLEW.so.2.1 (0x00007fc7ea9dd000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fc7ea7fc000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc7ea6ab000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc7ea690000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc7ea49e000)
libopencv_core.so.4.2 => /lib/x86_64-linux-gnu/libopencv_core.so.4.2 (0x00007fc7ea0ee000)
libGLdispatch.so.0 => /lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007fc7ea036000)
libGLX.so.0 => /lib/x86_64-linux-gnu/libGLX.so.0 (0x00007fc7ea002000)
libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007fc7e9ec3000)
libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x00007fc7e9eb1000)
libXxf86vm.so.1 => /lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007fc7e9eaa000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc7eb3e4000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc7e9ea4000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc7e9e81000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fc7e9e65000)
libtbb.so.2 => /lib/x86_64-linux-gnu/libtbb.so.2 (0x00007fc7e9e1d000)
libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fc7e9df3000)
libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x00007fc7e9dde000)
libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007fc7e9dd8000)
libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fc7e9dd0000)
libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007fc7e9db4000)
原因:可能是与下载glew版本有关,find_package(GLEW REQUIRED)指令找到的变量名为GLEW_LIBRARIES,,,
haha~,不知道自己理解的对不对,不对的还请大家帮忙指正~
另:
开始没想到是glew库链接的问题,还以为是编译器的问题导致的,后来在测试代码中顺便测试了一下这个问题, 使用以下指令编译没有问题
g++ test.cpp -lglut -lGLEW -o test
但如果改成
gcc test.cpp -lglut -lGLEW -o test
就会报如下错误
~/code/text$ gcc text.cpp -lglut -lGLEW -o text
/usr/bin/ld: /tmp/ccxZFg7d.o: in function `main':
text.cpp:(.text+0x24): undefined reference to `std::cout'
/usr/bin/ld: text.cpp:(.text+0x29): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/bin/ld: text.cpp:(.text+0x33): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/usr/bin/ld: text.cpp:(.text+0x3e): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/usr/bin/ld: text.cpp:(.text+0x4e): undefined reference to `std::cout'
/usr/bin/ld: text.cpp:(.text+0x53): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/usr/bin/ld: text.cpp:(.text+0x5d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/usr/bin/ld: text.cpp:(.text+0x68): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/usr/bin/ld: /tmp/ccxZFg7d.o: in function `__static_initialization_and_destruction_0(int, int)':
但是报的好像都是"std::***", 所以如果是编译器问题应该报的是官方预定义的包相关的问题。