如何在cmake中静态链接到glibc [英] How to static linking to glibc in cmake
问题描述
我正在尝试从Fedora构建一个可以在RedHat 6机器上运行的软件包。因此,我需要与RedHat机器中不存在的某些库进行构建和静态链接。
我发现我可以 -static-libgcc
或 -static-libstdc ++
链接到静态版本标准库,但我不知道如何使用 glibc
。如何使用CMake链接到 glibc
的静态库?
I'm trying to build a package from Fedora that can run on a RedHat 6 machine. So I need to build and static linking with some library that does not exist in RedHat machine.
I found that I can you -static-libgcc
or -static-libstdc++
to link with static version of standard library but I don't know how to do with glibc
. How can I link to static library of glibc
with CMake?
对不起,我的英语不好。
Sorry for my bad English.
推荐答案
由于 -static-libgcc
和 -static-libstdc ++
是链接器选项,在CMake中进行设置的正确方法是使用 target_link_libraries()
。
Since -static-libgcc
and -static-libstdc++
are linker options, the correct way to set them in CMake is with target_link_libraries()
.
因此,您可以这样设置,其中MyLibrary是项目名称:
So you would set it like this, where MyLibrary is the name of your project:
target_link_libraries(MyLibrary -static-libgcc -static-libstdc++)
这篇关于如何在cmake中静态链接到glibc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!