admin管理员组文章数量:1434921
I have successfully built and exported a shared library of mine by following the approach of putting the compiler flags into a separate INTERFACE library, as suggested in the CMake tutorial.
I also need an exportable static version of my library but I am struggling to make the things work. Please consider the following CMakeFile.txt
file that is a minimal reproducible example of my problem:
cmake_minimum_required(VERSION 3.21)
project(my_project LANGUAGES C)
# Example of interface library for compiler settings
add_library(compiler_flags INTERFACE)
target_compile_options(compiler_flags INTERFACE "-Wall")
# Real library
add_library(Foo STATIC foo.c) # It works with "SHARED" but not with "STATIC"
target_link_libraries(Foo PRIVATE compiler_flags)
# Install the real library
install(TARGETS Foo EXPORT FooTargets)
# Install the configuration targets
install(
EXPORT FooTargets
NAMESPACE Foo::
FILE FooTargets.cmake
DESTINATION lib/cmake/Foo)
When I run cmake -B build
, I get:
CMake Error: install(EXPORT "FooTargets" ...) includes target "Foo" which requires target "compiler_flags" that is not in any export set.
How can I make it work while keeping the compiler options in a separate INTERFACE library?
PS: I also looked at the static vs shared example in the official tutorial but, in that scenario, the static library is not directly exported (i.e., it is a private component of the exported shared library).
本文标签: cHow to export a static library linked to an interface libraryStack Overflow
版权声明:本文标题:c - How to export a static library linked to an interface library? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745623960a2666856.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论