简体   繁体   English

Clion Cmake 静态库链接 -static-libgcc -static-libstdc++

[英]Clion Cmake Static Library link -static-libgcc -static-libstdc++

I'm using centos 8 Gcc我正在使用 centos 8 Gcc

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.3.1 20190507 (Red Hat 8.3.1-4) (GCC)

My CMake [UPDATED]我的 CMake [更新]

cmake_minimum_required(VERSION 3.10)
project(TestProject)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS " -static -static-libgcc -static-libstdc++ -std=c++17")
add_executable(TestProject main.cpp)
SET(BUILD_SHARED_LIBS OFF)

#--------------- Static Includes -----------------
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(PHTREADS_LIB "-lphreads")
#----- Include Curl
set(CURL_LIBRARY "-lcurl")
find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIR})

target_link_libraries(TestProject ${CURL_LIBRARIES}  ${PHTREADS_LIB})


The issue [UPDATED问题[更新

/usr/bin/ld: cannot find -lcurl
/usr/bin/ld: cannot find -lphreads
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/TestProject.dir/build.make:84: TestProject] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/TestProject.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/TestProject.dir/rule] Error 2

My main goal is to try to add (libgcc libstdc++) as static.我的主要目标是尝试将 (libgcc libstdc++) 添加为静态。

Can someone guide me on what I'm doing wrong?有人可以指导我做错了什么吗?

/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc

Missing glibc-static缺少 glibc 静态

Centos 8 Centos 8

dnf --enablerepo=PowerTools install glibc-static
or
yum install glibc-static

for libstdc++

dnf --enablerepo=PowerTools install libstdc++-static
or 
yum install libstdc++-static

Centos 7森托斯 7

yum install glibc-static

Include Threads包括线程

#----- Include phtread
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} Threads::Threads)

Include Curl [FIX]包括卷曲 [FIX]

Here is more complicated for Centos 8对于 Centos 8,这里更复杂

Zlib兹库

dnf --enablerepo=PowerTools install zlib-static

CMake Include Zlib CMake 包含 Zlib

add_library(
        libz
        STATIC IMPORTED
)
set_target_properties(
        libz
        PROPERTIES IMPORTED_LOCATION
        /usr/lib64/libz.a
)

Install Static Lib安装静态库

wget https://curl.haxx.se/download/curl-7.61.0.tar.gz

tar -xvf curl-7.61.0.tar.gz

cd curl-7.61.0/

Set Config设置配置

./configure --disable-debug --disable-ftp --disable-ldap --disable-ldaps --disable-rtsp --disable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smb --disable-smtp --disable-gopher --disable-manual --disable-ipv6 --disable-sspi --disable-crypto-auth --disable-ntlm-wb --disable-tls-srp --without-nghttp2 --without-libidn2 --without-libssh2 --without-brotli --with-zlib --without-ssl

for SSL ( --with-ssl  required openssl-static (not availabe for Centos 8 ) ) 

Install安装

make && make install

Cmake Changes Cmake 更改

add_library(
        libz
        STATIC IMPORTED
)
set_target_properties(
        libz
        PROPERTIES IMPORTED_LOCATION
        /usr/lib64/libz.a
)


target_link_libraries(TestProject libcurl libz Threads::Threads)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 static-libgcc 和 static-libstdc++ 不工作 - static-libgcc and static-libstdc++ not working Eclipse CDT链接选项-static-libgcc -static-libstdc ++不影响Windows上的行为 - Eclipse CDT Link Options -static-libgcc -static-libstdc++ Not Affecting Behavior on Windows 使用-static-libgcc -static-libstdc ++进行编译仍会导致对libc.so的动态依赖 - Compiling with -static-libgcc -static-libstdc++ still results in dynamic dependency on libc.so 如果未使用-static-libstdc ++进行编译,则MinGW崩溃 - MinGW crash if not compiled with -static-libstdc++ -static-libstdc ++ GCC标志是否影响Linux上静态库(* .a)的生成 - Does -static-libstdc++ GCC flag affect the generation of a static library (*.a) on Linux 无法在 MinGW/CLion (c++) 中将 curl 和 libgcc 编译为静态库 - Cannot compile curl and libgcc as a static library in MinGW/CLion (c++) 使用 CMake 将 GLFW 作为静态库添加到 CLion - Adding GLFW as a static library to CLion with CMake -static-libstdc++ 适用于 g++ 但不适用于纯 gcc? - -static-libstdc++ works on g++ but not on pure gcc? 带有PDC的C ++ 64位项目通过Clion的CMake实现了静态链接库 - C++ 64bit project with PDCurses static link library via Clion's CMake 为什么OSX上的异常不能与gcc7和-static-libgcc一起使用? - Why don't exceptions work with gcc7 and -static-libgcc on OSX?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM