提问人:Duke M 提问时间:4/19/2023 更新时间:4/19/2023 访问量:66
如何避免CMake将对象的完整路径写入静态库?
How to avoid CMake writting full path of objects to the static library?
问:
原来的问题在这里。
几天后,我发现问题就在这里。
我尝试使用以下CMakeLists.txt来构建:tcmalloc_minimal_static.lib
#...
# https://github.com/gperftools/gperftools/blob/master/CMakeLists.txt#L593
if(MINGW OR MSVC)
set(WINDOWS_INCLUDES
# ...
src/windows/preamble_patcher.h)
set(libwindows_la_SOURCES ${WINDOWS_INCLUDES}
# ...
src/windows/preamble_patcher_with_stub.cc)
add_library(windows_object OBJECT ${libwindows_la_SOURCES})
add_library(windows INTERFACE)
target_sources(windows INTERFACE $<TARGET_OBJECTS:windows_object>)
# patch_functions.cc uses Psapi.lib. MSVC has a #pragma for that, but not us.
target_link_libraries(windows INTERFACE psapi)
#...
# https://github.com/gperftools/gperftools/blob/master/CMakeLists.txt#L811
set(libtcmalloc_minimal_internal_la_SOURCES src/common.cc
# ...
${TCMALLOC_MINIMAL_INCLUDES})
> add_library(tcmalloc_minimal_internal_object OBJECT ${libtcmalloc_minimal_internal_la_SOURCES})
# We #define NO_TCMALLOC_SAMPLES, since sampling is turned off for _minimal.
target_compile_definitions(tcmalloc_minimal_internal_object PRIVATE NO_TCMALLOC_SAMPLES NO_HEAP_CHECK NDEBUG)
add_library(tcmalloc_minimal_internal INTERFACE)
target_link_libraries(tcmalloc_minimal_internal INTERFACE ${LIBSPINLOCK} ${maybe_threads_lib})
target_sources(tcmalloc_minimal_internal INTERFACE $<TARGET_OBJECTS:tcmalloc_minimal_internal_object>)
#...
# https://github.com/gperftools/gperftools/blob/master/CMakeLists.txt#L847
if(GPERFTOOLS_BUILD_STATIC)
add_library(tcmalloc_minimal_static STATIC ${libtcmalloc_minimal_internal_la_SOURCES})
target_compile_definitions(tcmalloc_minimal_static PRIVATE NO_TCMALLOC_SAMPLES NDEBUG)
target_link_libraries(tcmalloc_minimal_static PRIVATE tcmalloc_minimal_internal Threads::Threads)
if(MINGW)
target_link_libraries(tcmalloc_minimal_static PRIVATE stacktrace)
endif()
if(NOT MSVC)
set_target_properties(tcmalloc_minimal_static PROPERTIES
OUTPUT_NAME tcmalloc_minimal)
endif()
weaken_object(tcmalloc_minimal_static)
install(TARGETS tcmalloc_minimal_static)
endif()
然后我弄错了.由7z.exe打开:tcmalloc_minimal_static.lib
tcmalloc_minimal_static.lib
- F:/
- *full/path/to/my/project/*
- build/Release/
- _deps/
- gperftools-build/
- tcmalloc_minimal_internal_object.dir/
- Release/
- central_freelist.obj
- ...
- windows_object.dir/
- Release/
- ia32_modrm_map.obj
- ...
- tcmalloc_minimal_static.dir/
- Release/
- central_freelist.obj
- ...
- 1.txt
- 2.txt
这太荒谬了。然后 objcopy.exe 根本无法读取这个库。
我试图添加到cmake启动参数。但它根本没有用。太多其他问题与共享库有关,但我面临着两个静态库。
我只想删除库中那些长长的绝对路径,以便 objcopy.exe 可以读取它。-DCMAKE_SKIP_RPATH
答: 暂无答案
评论
tcmalloc_minimal_static
libtcmalloc_minimal_internal_la_SOURCES
add_library(tcmalloc_minimal_static STATIC ${libtcmalloc_minimal_internal_la_SOURCES})
target_link_libraries(tcmalloc_minimal_static PRIVATE tcmalloc_minimal_internal Threads::Threads)
tcmalloc_minimal_internal
tcmalloc_minimal_static.lib
central_freelist.obj