在学习gcc静态库动态库编译的时候选用静态库编译时出错显示:/usr/lib/ld:cannot find -lc

百度:/usr/lib/ld:cannot find -lc多处给的解决方案为:

然而并不能解决问题,最终定位发现是静态编译的问题。而且不止会出现这种情况:

/usr/lib/ld:cannot find -lc

/usr/lib/ld:cannot find -lgcc_s

/usr/lib/ld:cannot find -lm

等的错误,主要原因在静态编译时需要链接静调库。如上命令:

[xiaohexiansheng@centos6 app]$ gcc -static -I./libs main.c -o app -L./libs -lcrypto -lfunc

如果在编译时去掉-static选项选用动态库编译则不会出现此种情况

[xiaohexiansheng@centos6 app]$ gcc -I./libs main.c -o app -L./libs -lcrypto -lfunc
[xiaohexiansheng@centos6 app]$ ls
app  libs  main.c

非静态编译时ldd filename,显示如下,这是可执行程序所需的动态库,运行可执行程序时需要的动态库。

[xiaohexiansheng@centos6 app]$ ldd app
        linux-gate.so.1 =>  (0x004ad000)
        libcrypto.so => /usr/lib/libcrypto.so (0x03ad9000)
        libfunc.so => not found
        libc.so.6 => /lib/libc.so.6 (0x0052a000)
        libdl.so.2 => /lib/libdl.so.2 (0x0070c000)
        libz.so.1 => /lib/libz.so.1 (0x00713000)
        /lib/ld-linux.so.2 (0x00508000)

静态编译时需要将所有的.a库链接到可执行文件中,所以需要libc静态库文件,在系统找查找glibc-static提示没有库文件。

#yum install glibc-static安装静态库。

gcc static静态编译选项提示错误:/usr/lib/ld:cannot find -lc的更多相关文章

  1. gcc static静态编译选项提示错误修正(/usr/lib/ld: cannot find -lc)

    用gcc静态编译C程序时显示出: /usr/lib/ld: cannot find -lc /usr/lib/ld: cannot find -lgcc_s /usr/lib/ld: cannot f ...

  2. make -f dc_debug.mak 提示错误"/usr/bin/ld:can not find -l***"解决办法

    在公司不同服务器上"make -f ***"程序的时候,有的服务器可以编译通过,有的却提示"/usr/bin/ld:can not find -l***"的错误 ...

  3. 编译错误 ----- /usr/bin/ld: cannot find -lc

    yum install glibc-static glib-static是Gcc链接时使用到的库.

  4. 【转】G++ 处理 /usr/bin/ld: cannot find -lc

    原文网址:http://blog.sina.com.cn/s/blog_67bbb71101010tto.html 用g++编译C++程序时显示出:/usr/lib/ld: cannot find - ...

  5. /usr/bin/ld: cannot find -lc

    yum install glibc-static [root@test chkrootkit-0.50]# make sensecc -static -o strings-static strings ...

  6. /usr/bin/ld: cannot find -lc错误原因及解决方法

    问题解决 我在执行如下命令的时候,出现了错误. gcc -o main main.c -static -L. –lmylib Linux环境下gcc静态编译/usr/bin/ld: cannot fi ...

  7. 【转】链接任意目录下库文件(解决错误“/usr/bin/ld: cannot find -lxxx”

    netbeans构建项目也出现了同样的问题.猜测是netbeans内部就用的是-l 这种编译方式,所以需要把***.a手动改为lib***.a 原文地址:链接任意目录下库文件(解决错误“/usr/bi ...

  8. 【解决】/usr/bin/ld: cannot find -lc

    现象:运行gcc静态编译程序时报错: /usr/bin/ld: cannot find -lc collect2: ld returned 1 exit statusmake: *** [gcc_dr ...

  9. android编译错误--/usr/bin/ld: cannot find -lz

    编译时出现/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libz.so when se ...

随机推荐

  1. 计算Linux权限掩码umask值

    创建文件默认最大权限为666 (-rw-rw-rw-),默认创建的文件没有可执行权限x位. 创建目录默认最大权限777(-rwx-rwx-rwx),默认创建的目录属主是有x权限,允许用户进入. 简单的 ...

  2. MYSQL5.7修改密码

    参考:https://www.cnblogs.com/activiti/p/7810166.html # alter user 'root'@'localhost' identified by '12 ...

  3. elementary os 5配置

    打开终端,执行以下步骤: 1.更新软件源 sudo apt update 2.安装add-apt-repository命令所在的软件包 sudo apt install software-proper ...

  4. Android sdk manager更新 下载API源码

    方法一:在C:\Windows\System32\drivers\etc路径下的hosts文件中加入如下代码即可更新 203.208.46.146 www.google.com74.125.113.1 ...

  5. Bootstrap模态框垂直居中展示的方法

    在bootstrap.js中加入以下代码:

  6. Gitlab,这也就O了???

    最简单配置也是一句话搞了... rpm -i gitlab-ce--ce..el7.x86_64.rpm vim /etc/gitlab/gitlab.rb gitlab-ctl reconfigur ...

  7. HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)

    6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...

  8. 洛谷 P1182 数列分段`Section II`【二分答案】

    [代码]: #include<bits/stdc++.h> const double eps = 1e-8; const int maxn = 1e6+5; #define inf 0x3 ...

  9. Naming conventions of python

    1.package name 全部小写字母,中间可以由点分隔开,作为命名空间,包名应该具有唯一性,推荐采用公司或组织域名的倒置,如com.apple.quicktime.v2 2.module nam ...

  10. Codeforces #445 Div2 D

    #445 Div2 D 题意 给出一些字符串,要求构造一个最短的且字典序最小的字符串,使得给出的字符串都为目标字符串的子串,且这些字符串作为子串出现的次数都是最多的,如果不存在目标字符串输出 &quo ...