【转载】configure: error: C compiler cannot create executables 错误解析
1 原文地址#
configure: error: C compiler cannot create executables错误解析 - to_be_better_wen - https://blog.csdn.net/to_be_better_wen/article/details/130650774
2 前言#
在编译开源软件的时候,有时会遇到 "configure: error: C compiler cannot create executables" 的错误,表示不能生成可执行文件。本文以编译 curl-7.40.0 为例,模拟出这种错误,并讲解解决这种错误的方法。错误输出如下:
[root@192 curl-7.40.0]# ./configure LIBS=-lopenssl
checking whether to enable maintainer-specific portions of Makefiles... no
checking whether to enable debug build options... no
checking whether to enable compiler optimizer... (assumed) yes
checking whether to enable strict compiler warnings... no
checking whether to enable compiler warnings as errors... no
checking whether to enable curl debug memory tracking... no
checking whether to enable hiding of library internal symbols... yes
checking whether to enable c-ares for DNS lookups... no
checking for path separator... :
checking for sed... /usr/bin/sed
checking for grep... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ar... /usr/bin/ar
checking for a BSD-compatible install... /usr/bin/install -c
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in/home/betterman/opensource/curl-7.40.0': configure: error: C compiler cannot create executables See
config.log' for more details
3 错误解析#
根据最后一句输出,我们需要参考 config.log 的内容。从 config.log 文件中,可以找到如下一段内容:
configure:4216: checking whether the C compiler works
configure:4238: gcc conftest.c -lopenssl >&5 (1)
/usr/bin/ld: cannot find -lopenssl (2)
collect2: error: ld returned 1 exit status
configure:4242: $? = 1
configure:4280: result: no
configure: failed program was:
| /* confdefs.h / (3)
| #define PACKAGE_NAME "curl"
| #define PACKAGE_TARNAME "curl"
| #define PACKAGE_VERSION "-"
| #define PACKAGE_STRING "curl -"
| #define PACKAGE_BUGREPORT "a suitable curl mailing list: http://curl.haxx.se/mail/"
| #define PACKAGE_URL ""
| / end confdefs.h. */
|
| int main (void)
| {
|
| ;
| return 0;
| }
configure:4285: error: in/home/wenyong/opensource/curl-7.40.0': configure:4287: error: C compiler cannot create executables (4) See
config.log' for more details
从 (1) 可知,gcc 会编译 conftest.c 文件并且需要链接 libopenssl.so,所以报 (2) 的错误,表示编译时找不到 libopenssl.so 库,conftest.c 的内容是从 (3) 开始,最后产生了 (4) 处的错误。
4 解决方法#
由上可知,可以得出结论:软件包在 configure 的时候,configure 会根据用户指定的编译选项编译 conftest.c 文件,由此来预检查编译时要用到的 gcc,动态库等是否可以找到,尽早让用户检查错误。
本例的错误是由于 libopenssl.so 找不到,所以解决方法有:
1、通过 LDFLAGS 选项指定 libopenssl.so 所在的路径,例如:
./configure LIBS=-lopenssl LDFLAGS=/root/libopenssl/usr/lib
2、直接使用 ./configure 编译
如果编译 curl 不需要用到 openssl 的库,可以不链接。
5 总结#
本文讲解了解决 "configure: error: C compiler cannot create executables" 问题出现的原因与解决的思路:configure 运行的时候需要使用用户指定的选项编译 conftest.c 文件,但是由于选项指定的 gcc 或动态库找不到,导致编译报错,解决的方法是指定 gcc 和动态库的路径或者下载对应缺失的库,重点是查看 config.log 文件中的错误原因
作者:PikapBai
出处:https://www.cnblogs.com/PikapBai/p/17465175.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
备注:转载请注明出处并附加链接
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具