![如何在基于 ubuntu 的 docker 中使用 CMake 修复对 Qt5 lib 的未定义引用?](https://linux22.com/image/1579223/%E5%A6%82%E4%BD%95%E5%9C%A8%E5%9F%BA%E4%BA%8E%20ubuntu%20%E7%9A%84%20docker%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20CMake%20%E4%BF%AE%E5%A4%8D%E5%AF%B9%20Qt5%20lib%20%E7%9A%84%E6%9C%AA%E5%AE%9A%E4%B9%89%E5%BC%95%E7%94%A8%EF%BC%9F.png)
我正在尝试在基于 ubuntu 18.04 的 docker 容器中使用 CMake 运行 Qt 项目。当我为我的项目运行cmake
和make
命令时,出现以下错误。
/usr/local/Qt-5.12.0/lib/libQt5Core.a(qregularexpression.o): In function `QThreadStorage<QPcreJitStackPointer*>::deleteData(void*)':
qregularexpression.cpp:(.text._ZN14QThreadStorageIP20QPcreJitStackPointerE10deleteDataEPv[_ZN14QThreadStorageIP20QPcreJitStackPointerE10deleteDataEPv]+0x12): undefined reference to `pcre2_jit_stack_free_16'
/usr/local/Qt-5.12.0/lib/libQt5Core.a(qregularexpression.o): In function `safe_pcre2_match_16(pcre2_real_code_16 const*, unsigned short const*, int, int, int, pcre2_real_match_data_16*, pcre2_real_match_context_16*)':
qregularexpression.cpp:(.text._ZL19safe_pcre2_match_16PK18pcre2_real_code_16PKtiiiP24pcre2_real_match_data_16P27pcre2_real_match_context_16+0x32): undefined reference to `pcre2_match_16'
...这些未定义的引用一直在继续......
/usr/local/Qt-5.12.0/lib/libQt5Core.a(qlibrary_unix.o): In function `QLibraryPrivate::load_sys()':
qlibrary_unix.cpp:(.text._ZN15QLibraryPrivate8load_sysEv+0x628): undefined reference to `dlopen'
collect2: error: ld returned 1 exit status
CMakeFiles/db.dir/build.make:123: recipe for target 'db' failed
make[2]: *** [db] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/db.dir/all' failed
make[1]: *** [CMakeFiles/db.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
我尝试更改 CMakeLists.txt 文件以查看它是否导致了问题,并添加了目录和路径,但这似乎不是原因。我尝试更改 LIBRARY_PATH,但没有结果。还有其他方法可以解决这个问题吗?
答案1
尝试让它工作一段时间后,我决定重新配置并重新安装与docker相同版本的Qt。
我在 dockerfile 中有配置选项
bash ./configure -opensource -confirm-license -static -no-accessibility -sql-sqlite -sqlite -no-qml-debug \
-no-harfbuzz -openssl-linked -qt-pcre -no-dbus -nomake tools \
-no-xkbcommon-evdev -no-xinput2 -no-xcb-xlib -no-glib -qt-xcb -no-compile-examples -nomake examples \
-no-gif -qt-doubleconversion -no-gtk \
并把它们改成这样
bash ./configure -opensource -confirm-license -no-accessibility -sql-odbc -sql-sqlite -sqlite -gui -widgets -nomake tools -no-compile-examples -nomake examples -qt-doubleconversion\
&& make install
我添加了 gui 和小部件选项,并决定安装更多工具。这种方法修复了 CMake 在为项目构建可执行文件时找不到的不同库的未定义引用。虽然问题解决了,但我最终得到的 docker 镜像更大(多出 7 Gb),所以这是一个快速的解决方案,但不是最好的。