2017-05-31 88 views
0

我想在編譯C++程序時靜態鏈接庫。
G ++(GCC)4.8.5 20150623(紅帽4.8.5-4)無glibc靜態包可用

$ g++ -std=c++11 -I/home/jerry/Desktop/tiny-dnn -m32 -pthread -static train.cpp -o train 
/usr/bin/ld: cannot find -lstdc++ 
/usr/bin/ld: cannot find -lm 
/usr/bin/ld: cannot find -lpthread 
/usr/bin/ld: cannot find -lc 
collect2: error: ld returned 1 exit status 

我發現這個職位 (/usr/bin/ld: cannot find -lc while compiling with makefile),說要安裝glibc的靜電。

bash-4.2# sudo yum install glibc-static 
Loaded plugins: langpacks 
ol7_UEKR3                       | 1.2 kB 00:00:00  
ol7_latest                      | 1.4 kB 00:00:00  
No package glibc-static available. 
Error: Nothing to do 
bash-4.2# yum info glibc-static 
Loaded plugins: langpacks 
Error: No matching Packages to list 
bash-4.2# yum search glibc 
Loaded plugins: langpacks 
================================================== N/S matched: glibc =================================================== 
glibc-common.x86_64 : Common binaries and locale data for glibc 
compat-glibc.x86_64 : Compatibility C library 
compat-glibc-headers.x86_64 : Header files for development using standard C libraries. 
glibc.i686 : The GNU libc libraries 
glibc.x86_64 : The GNU libc libraries 
glibc-devel.i686 : Object files for development using standard C libraries. 
glibc-devel.x86_64 : Object files for development using standard C libraries. 
glibc-headers.x86_64 : Header files for development using standard C libraries. 
glibc-utils.x86_64 : Development utilities from GNU C library 
kdesdk-kmtrace.x86_64 : Assist with malloc debugging using glibc's "mtrace" functionality 
kernel-headers.x86_64 : Header files for the Linux kernel for use by glibc 
latrace.i686 : LD_AUDIT feature frontend for glibc 2.4+ 
latrace.x86_64 : LD_AUDIT feature frontend for glibc 2.4+ 

    Name and summary matches only, use "search all" for everything. 

我該如何安裝glibc-static?請幫忙。

謝謝。

+0

即使您正在編譯的程序是用C++編寫的,但這個問題不是關於C++作爲一種語言,因此請刪除該標記。 –

回答

0

glibc-static僅在可選通道中可用。可選渠道中的RPM軟件包在官方不受支持,這就是默認情況下未啓用這些渠道的原因。

啓用可選通道的確切命令取決於產品型號。像

subscription-manager repos --enable=rhel-7-server-optional-rpms 

可以工作,但細節取決於你的環境(這是一個系統管理員比編程問題在這一點上)。

注意: Red Hat不支持靜態鏈接有很好的理由。你真的應該避免它。