当我尝试查找Qt库时,我使用find_package()命令。但这是一个问题。此命令导入同一库的两个版本。 按版本我的意思是调试和重新发布。例如:
libQt5Core_debug.5.dylib
libQt5Core.5.11.0.dylib
由于这种不受欢迎的行为,我得到运行时链接链接错误。
objc[15947]: Class QMacAutoReleasePoolTracker is implemented in both /usr/local/Qt-5.11.0/lib/libQt5Core_debug.5.dylib (0x104326d40) and /usr/local/Qt-5.11.0/lib/libQt5Core.5.11.0.dylib (0x1075c41c8). One of the two will be used. Which one is undefined.
objc[15947]: Class QT_ROOT_LEVEL_POOL__THESE_OBJECTS_WILL_BE_RELEASED_WHEN_QAPP_GOES_OUT_OF_SCOPE is implemented in both /usr/local/Qt-5.11.0/lib/libQt5Core_debug.5.dylib (0x104326db8) and /usr/local/Qt-5.11.0/lib/libQt5Core.5.11.0.dylib (0x1075c4240). One of the two will be used. Which one is undefined.
objc[15947]: Class RunLoopModeTracker is implemented in both /usr/local/Qt-5.11.0/lib/libQt5Core_debug.5.dylib (0x104326de0) and /usr/local/Qt-5.11.0/lib/libQt5Core.5.11.0.dylib (0x1075c4268). One of the two will be used. Which one is undefined.
QObject::moveToThread: Current thread (0x7fcee5f02c20) is not the object's thread (0x7fcee5c04c10).
Cannot move to target thread (0x7fcee5f02c20)
You might be loading two sets of Qt binaries into the same process. Check that all plugins are compiled against the right Qt binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.
我的CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(Server)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_BUILD_TYPE "Debug")
set (CMAKE_CXX_FLAGS " -lprotobuf")
add_definitions(-DDEBUG_MODE)
set(CMAKE_AUTOMOC ON)
include_directories(/usr/local/boost_1_67_0/)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Sql REQUIRED)
find_package(Qt5Network REQUIRED)
set(SRCS Server.cpp Request_Response.pb.cc)
add_executable(Server main.cpp ${SRCS})
target_link_libraries(Server Qt5::Core Qt5::Widgets Qt5::Sql Qt5::Network)
问题: 如何告诉cmake不要将我的目标链接到同一个库的多个版本?
操作系统:macOS High Sierra 10.13.4cmake:3.11.0
编辑: 有人说它是this issue的副本,当然还有。{3}} 它涉及使用find_package()进行调试和发布安装,但这不一样。在他的情况下,lib的调试和发布版本分配在不同的路径中。
在我的情况下,我在同一个文件夹中有相同库的2个版本。 /usr/local/Qt-5.11.0/lib
看看这个:
$:lib artur$ ls | grep -i qt5core
libQt5Core.5.11.0.dylib
libQt5Core.5.11.dylib
libQt5Core.5.dylib
libQt5Core.dylib
libQt5Core.la
libQt5Core.prl
libQt5Core_debug.5.11.0.dylib
libQt5Core_debug.5.11.dylib
libQt5Core_debug.5.dylib
libQt5Core_debug.dylib
libQt5Core_debug.la
libQt5Core_debug.prl
注意: 如果我更改构建类型,一切正常。
这
set(CMAKE_BUILD_TYPE "Debug")
到
set(CMAKE_BUILD_TYPE "Release")