Ubuntu下自己编译了QVTKWidget,在使用的过程中报错
/usr/bin/ld: warning: libQt5X11Extras.so.5, needed by /usr/local/lib/libvtkGUISupportQt-8.0.so.1, not found (try using -rpath or -rpath-link)
/usr/local/lib/libvtkGUISupportQt-8.0.so.1: undefined reference to QX11Info::display()@Qt_5' /usr/local/lib/libpcl_visualization.so: undefined reference to
__cxa_throw_bad_array_new_length@Qt_5’
我们将QT安装到了opt目录下面,导致在系统目录下找不到对应的QT库文件
第一步:修改cmakelists.txt文件,指定QT目录为我们安装的QT目录
在find_package之前添加QT的cmake路径
set(CMAKE_PREFIX_PATH “/opt/Qt5.7.1/5.7/gcc_64/lib/cmake”)
find_package (Qt5 COMPONENTS Core Widgets REQUIRED)
第二步:清除CMake在build目录下面的缓存文件,清空build目录即可一定要做这一步
参考CMAKE_MODULE_PATH 与 CMAKE_PREFIX_PATH这时候cmake会在我们指定的目录下找QT
第三步:重新cmake配置,并且编译
第四步:运行报错后,将QT库目录添加到LD_LIBRARY_PATH中,运行成功
运行报错
./Demo: error while loading shared libraries: libQt5X11Extras.so.5: cannot open shared object file: No such file or directory
将QT的lib目录添加到LD_LIBRARY_PATH中后运行OK(可以将这个命令添加到~/.bashrc文件末尾,不然每次打开终端之后都需要执行这条命令)
export LD_LIBRARY_PATH=/opt/Qt5.7.1/5.7/gcc_64/lib:$LD_LIBRARY_PATH
cmake命令行指定CMAKE_PREFIX_PATH路径
cmake … -DCMAKE_PREFIX_PATH=/opt/Qt5.7.1/5.7/gcc_64/lib/cmake
/usr/lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5’ not found
CMake中添加Qt模块的合理方法
CMAKE_MODULE_PATH 与 CMAKE_PREFIX_PATH
如何彻底清除cmake产生的缓存