configure: error: C compiler cannot create executables错误解析

文章介绍了在编译开源软件curl时遇到的‘configure:error:Ccompilercannotcreateexecutables’错误,该错误通常是由于找不到libopenssl.so库导致的。解决方案包括通过LDFLAGS指定libopenssl.so路径或确保配置时不依赖openssl库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一. 前言

        在编译开源软件的时候,有时会遇到"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

二. 错误解析

        根据最后一句输出,我们需要参考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)处的错误。

三. 解决方法

        由上可知,可以得出结论:软件包在configure的时候,configure会根据用户指定的编译选项编译conftest.c文件,由此来预检查编译时要用到的gcc,动态库等是否可以找到,尽早让用户检查错误。

        本例的错误是由于libopenssl.so找不到,所以解决方法有:

1. 通过LDFLAGS选项指定libopenssl.so所在的路径,例如:

./configure LIBS=-lopenssl LDFLAGS=/root/libopenssl/usr/lib

2. 直接使用./configure编译

        如果编译curl不需要用到openssl的库,可以不链接。

四. 总结

        本文讲解了解决"configure: error: C compiler cannot create executables"问题出现的原因与解决的思路:configure运行的时候需要使用用户指定的选项编译conftest.c文件,但是由于选项指定的gcc或动态库找不到,导致编译报错,解决的方法是指定gcc和动态库的路径。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值