找不到 CMake LibXML 运行时库。视窗
我尝试创建 Scram (CI yaml 文件, CMakeLists.txt)适用于 Windows。该项目使用 CMake 创建构建文件。项目的构建已经开始工作,但是 libxml 和 boost 的运行时库没有捆绑到包中。 由于使用的是 mingw64 编译器。
Libxml2 将在上一步中由 CI 安装,并将安装前缀传递给 scram cmake。
在 CMakeLists.txt 中,libxml 包含为: find_package(LibXml2 REQUIRED)
1
然后我尝试将 libxmllibraries 安装为: install(FILES ${LIBXML2_LIBRARIES} DESTINATION bin)
问题是 LIBXML2_LIBRARIES 指向 libxml2_install_prefix/lib 中的 .dll.a 文件,而不是 libxml2_install_prefix/bin 文件夹中的 .dll 文件。因此,只有 .dll.a 文件被捆绑到 exe 中,因此该应用程序无法运行。
2
get_target_property(LIB_XML2_RUNTIME_OUTPUT_DIRECTORY LibXml2::LibXml2 RUNTIME_OUTPUT_DIRECTORY)
get_target_property(LIB_XML2_RUNTIME_OUTPUT_NAME LibXml2::LibXml2 RUNTIME_OUTPUT_NAME)
message(STATUS "XX LIB_XML2_RUNTIME_OUTPUT_DIRECTORY: ${LIB_XML2_RUNTIME_OUTPUT_DIRECTORY}")
message(STATUS "XX LIB_XML2_RUNTIME_OUTPUT_NAME: ${LIB_XML2_RUNTIME_OUTPUT_NAME}")
install (FILES
${LIBXML2_LIBRARIES}
"${LIB_XML2_RUNTIME_OUTPUT_DIRECTORY}/${LIB_XML2_RUNTIME_OUTPUT_NAME}"
DESTINATION bin
COMPONENT libraries)
在本例中,LIB_XML2_RUNTIME_OUTPUT_NAME
和 LIB_XML2_RUNTIME_OUTPUT_DIRECTORY
为“-NOT_FOUND” 这似乎是一个问题,因为 cmake 不知道导入目标的运行时目录(
3
我尝试过 install(IMPORTED_RUNTIME_ARTIFACTS LibXml2::LibXml2)
失败,并显示:install IMPORTED_RUNTIME_ARTIFACTS给定目标“ LibXml2::LibXml2" 不是可执行文件、库或模块。
此处还进行了描述: CMake Gitlab 存储库
4
install(TARGETS LibXml2::LibXml2 RUNTIME_DEPENDENCIES)
失败并显示以下消息:安装给定目标“LibXml2::LibXml2”的目标不存在。
来自CMake Docu:
Note: Imported Targets are supported only if they know the location of their .dll files. An imported SHARED or MODULE library must have IMPORTED_LOCATION set to its .dll file. See the add_library imported libraries section for details. Many Find Modules produce imported targets with the UNKNOWN type and therefore will be ignored.
可能 LibXml2 被导入为未知,因此没有指定 DLL 路径。如何解决这个问题并安装dll?
5
我尝试
安装(FILES $
引用了目标“LibXml2::LibXml2”的对象,但不是允许的目标类型之一(EXECUTABLE、SHARED、MODULE)。
。可能是因为目标是导入的,而不是由此 cmake 创建的
6
get_target_property(libxml2_imported_location LibXml2::LibXml2 IMPORTED_LOCATION)
还指向 .dll.a 文件
7 工作黑客(丑陋)
找出 .dll 的位置位于。对于 libXml2,它位于 bin 文件夹中;对于 boost,它位于与 .dll.a 相同的文件夹中 使用导入的位置并替换路径以匹配 .dll 的路径
get_target_property(libxml2_imported_location LibXml2::LibXml2 IMPORTED_LOCATION)
string(REPLACE "/lib/" "/bin/" libxml2_imported_location ${libxml2_imported_location})
string(REPLACE ".dll.a" ".dll" libxml2_imported_location ${libxml2_imported_location})
message(STATUS "XX libxml2_imported_location3 ${libxml2_imported_location}")
install(FILES ${libxml2_imported_location} DESTINATION bin COMPONENT libraries)
I try to create an automated build of Scram (CI yaml file, CMakeLists.txt) for Windows. The project uses CMake to create the build files. Building of the project worked already, but the runtime libraries of libxml and boost get not bundled into the package.
As compiler mingw64 is used.
Libxml2 will be installed by the CI in a previous step and the install prefix is passed to the scram cmake.
In the CMakeLists.txt libxml is included as:find_package(LibXml2 REQUIRED)
1
I tried then to install the libxmllibraries as:install(FILES ${LIBXML2_LIBRARIES} DESTINATION bin)
The problem is that LIBXML2_LIBRARIES points to the .dll.a files in the libxml2_install_prefix/lib and not to the .dll files in the libxml2_install_prefix/bin folder. So only the .dll.a files are bundled into the exe and therefore the application does not work.
2
get_target_property(LIB_XML2_RUNTIME_OUTPUT_DIRECTORY LibXml2::LibXml2 RUNTIME_OUTPUT_DIRECTORY)
get_target_property(LIB_XML2_RUNTIME_OUTPUT_NAME LibXml2::LibXml2 RUNTIME_OUTPUT_NAME)
message(STATUS "XX LIB_XML2_RUNTIME_OUTPUT_DIRECTORY: ${LIB_XML2_RUNTIME_OUTPUT_DIRECTORY}")
message(STATUS "XX LIB_XML2_RUNTIME_OUTPUT_NAME: ${LIB_XML2_RUNTIME_OUTPUT_NAME}")
install (FILES
${LIBXML2_LIBRARIES}
"${LIB_XML2_RUNTIME_OUTPUT_DIRECTORY}/${LIB_XML2_RUNTIME_OUTPUT_NAME}"
DESTINATION bin
COMPONENT libraries)
In this case LIB_XML2_RUNTIME_OUTPUT_NAME
and LIB_XML2_RUNTIME_OUTPUT_DIRECTORY
are "-NOT_FOUND"
This seems to be a problem because cmake does not know the runtime directory for imported targets (
3
I tried than also install(IMPORTED_RUNTIME_ARTIFACTS LibXml2::LibXml2)
which failed with: install IMPORTED_RUNTIME_ARTIFACTS given target "LibXml2::LibXml2" which is not an executable, library, or module.
Also described here: CMake Gitlab repository
4
install(TARGETS LibXml2::LibXml2 RUNTIME_DEPENDENCIES)
failed with the following message: install TARGETS given target "LibXml2::LibXml2" which does not exist.
From CMake Docu:
Note: Imported Targets are supported only if they know the location of their .dll files. An imported SHARED or MODULE library must have IMPORTED_LOCATION set to its .dll file. See the add_library imported libraries section for details. Many Find Modules produce imported targets with the UNKNOWN type and therefore will be ignored.
Probably LibXml2 is imported as unknown and therefore there is no DLL path specified. How to come around this issue and installing the dlls?
5
I tried
install(FILES $<TARGET_RUNTIME_DLLS:LibXml2::LibXml2> DESTINATION bin COMPONENT libraries)
but here I get the error message:
Objects of target "LibXml2::LibXml2" referenced but is not one of the allowed target types (EXECUTABLE, SHARED, MODULE).
. Probably because the target is imported and not created by this cmake
6
get_target_property(libxml2_imported_location LibXml2::LibXml2 IMPORTED_LOCATION)
points also to the .dll.a file
7 Working Hack (Ugly)
Find out where the .dll is located. For libXml2 it is in the bin folder, for boost it is in the same folder as the .dll.a
Use the imported location and replace the path to match the path to the .dll
get_target_property(libxml2_imported_location LibXml2::LibXml2 IMPORTED_LOCATION)
string(REPLACE "/lib/" "/bin/" libxml2_imported_location ${libxml2_imported_location})
string(REPLACE ".dll.a" ".dll" libxml2_imported_location ${libxml2_imported_location})
message(STATUS "XX libxml2_imported_location3 ${libxml2_imported_location}")
install(FILES ${libxml2_imported_location} DESTINATION bin COMPONENT libraries)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论