Loading

【转载】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 文件中的错误原因

posted @ 2023-06-08 10:40  她爱喝水  阅读(361)  评论(0编辑  收藏  举报