【Linux开发】如何在./configure的时候将编译参数传入,改变默认的编译器gcc成arm-linux-gcc...

本文介绍如何通过设置CC变量为arm-linux-gcc来完成lrzsz软件的交叉编译过程。关键在于正确传递编译器路径并创建新的缓存文件确保配置更新。

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

如何在configure时,将编译参数传入,改变默认的编译器gcc成arm-linux-gcc

【问题】

想要用交叉编译工具arm-linux-gcc去编译lrzsz,
但是在./configure的时候,无法用–host=arm-linux或–build=arm-linux或–target=arm-linux等传入此编译器参数。

【解决过程】

按照INSTALL中的介绍,也是常用的方法,在configure的时候,加上–host=arm-linux,结果没有实现我们要的效果,没有将编译器从默认的
gcc改成arm-linux-gcc,编译器还是用的默认的gcc:

[crifan@localhost lrzsz-0.12.20]$ CFLAGS=-O2 ./configure –host=arm-linux 
loading cache ./config.cache
………………..
checking for gcc… (cached) gcc
checking whether the C compiler (gcc -O2 ) works… yes
checking whether the C compiler (gcc -O2 ) is a cross-compiler… no
………………..

后来经过多次尝试,最后受默认的
CFLAGS=-O2 ./configure
进行配置所启发,想到,是否可以将CC参数传入到configure中,
结果证实,如果没有自己的cache-file,即时加了对的CC参数,也还是无法传入:
[crifan@localhost lrzsz-0.12.20]$ CFLAGS=-O2 CC=arm-linux-gcc ./configure –host=arm-linux 
loading cache ./config.cache
………………..
checking for gcc… (cached) gcc
checking whether the C compiler (gcc -O2 ) works… yes
checking whether the C compiler (gcc -O2 ) is a cross-compiler… no
checking whether we are using GNU C… (cached) yes
………………..

而且,如果CC参数放在configure后面:
./configure CC=arm-linux-gcc
则不能识别:
[crifan@localhost lrzsz-0.12.20]$ CFLAGS=-O2 ./configure CC=arm-linux-gcc
configure: warning: CC=arm-linux-gcc: invalid host type
………………..

参数传递必须像
CFLAGS=-O2 ./configure
一样,将参数设置放在configure的前面:
CC=arm-linux-gcc./configure
才能识别的。

必须要自己制定自己的cache-file 然后用./configure进行新配置,加上CC参数,才会即时生效,编译器才可以变成我们要的arm-linux-gcc:
[crifan@localhost lrzsz-0.12.20]$ CC=arm-linux-gcc ./configure –cache-file=cache_file_0 –prefix=/usr/crifan/lrzsz
………………..
checking for gcc… arm-linux-gcc
checking whether the C compiler (arm-linux-gcc ) works… yes
checking whether the C compiler (arm-linux-gcc ) is a cross-compiler… yes
checking whether we are using GNU C… yes
………………..

否则,就无法将我们的CC参数传入了:
[crifan@localhost lrzsz-0.12.20]$ CC=arm-linux-gcc ./configure –prefix=/usr/crifan/lrzsz
………………..
checking for gcc… (cached) gcc
checking whether the C compiler (gcc ) works… yes
checking whether the C compiler (gcc ) is a cross-compiler… no
checking whether we are using GNU C… (cached) yes
………………..

[crifan@localhost lrzsz-0.12.20]$ CFLAGS=-O2 CC=arm-linux-gcc ./configure –cache-file=cache_file_0 
loading cache cache_file_0
………………..
checking for gcc… arm-linux-gcc
checking whether the C compiler (arm-linux-gcc -O2 ) works… yes
checking whether the C compiler (arm-linux-gcc -O2 ) is a cross-compiler… yes
checking whether we are using GNU C… yes

最好此处在加上–prefix=/usr/crifan/lrzsz,表示具体安装到哪里
[crifan@localhost lrzsz-0.12.20]$ CFLAGS=-O2 CC=arm-linux-gcc ./configure –cache-file=cache_file_0 –prefix=/usr/crifan/lrzsz
loading cache cache_file_0
………………..
checking for gcc… arm-linux-gcc
checking whether the C compiler (arm-linux-gcc -O2 ) works… yes
checking whether the C compiler (arm-linux-gcc -O2 ) is a cross-compiler… yes
checking whether we are using GNU C… yes
………………..

其中,/usr/crifan/lrzsz是已经建立好的,已经存在的文件夹,上面这样表示编译后,
将生成的可执行文件安装拷贝到那个目录.

【办法总结】
在./configure的时候,将CC参数放入configure之前,并且要制定cache file,才能完全即时识别编译器:
CC=arm-linux-gcc ./configure –cache-file=cache_file_0

转载于:https://www.cnblogs.com/huty/p/8518185.html

<think>好的,我现在需要帮助用户解决这个链接错误的问题。用户提供的错误信息是“cannot find -lssl”,也就是链接器找不到ssl库。首先,我得理解这个错误的原因。通常这种情况发生在编译程序时,链接阶段需要某个库文件,但系统里没有安装或者路径不对。 首先,用户给出的路径看起来是交叉编译工具链的一部分,路径中有arm-himix410-linux,这说明用户可能在为ARM架构交叉编译程序,目标平台可能是海思的某个芯片。交叉编译时,工具链的库路径和主机系统的库路径不同,所以需要确认交叉编译的ssl库是否安装正确。 接下来,我需要考虑可能的解决方法。第一步通常是检查是否安装了对应的库文件。对于-lssl,对应的库文件是libssl.so或libssl.a。用户使用的是交叉编译工具链,所以需要确认工具链的lib目录下是否存在这些文件。用户提供的路径中,工具链的lib目录可能在../lib/gcc/.../../../../../arm-linux-gnueabi/lib这个位置,需要检查是否存在libssl.so或libssl.a。 如果库文件不存在,那么可能需要安装对应的交叉编译库。例如,在Ubuntu系统中,可能会有类似libssl-dev的包,但交叉编译的库可能需要特定的包,比如libssl-dev:armhf或者通过源码编译安装。这时候需要指导用户如何安装这些库。 另外,还要考虑库文件的路径是否被正确包含在链接器的搜索路径中。用户可能在编译时没有指定-L参数来添加库的路径,或者环境变量如LIBRARY_PATH没有设置正确。需要检查Makefile或编译命令,确认是否有指定正确的库路径。 还有可能是符号链接问题,库文件存在但文件名不匹配。比如,libssl.so.1.1存在,但没有libssl.so的软链接。这时候需要创建正确的软链接。 最后,可能需要确认架构是否匹配,交叉编译的工具链是否与目标平台一致,比如arm-himix410是否与库文件的架构兼容。 总结可能的解决步骤:检查库是否存在,安装缺失的库,确认库路径,创建符号链接,检查架构兼容性。需要逐步引导用户排查这些问题,并提供具体的命令示例,比如使用find命令查找库文件,安装交叉编译库的方法,设置链接路径等。</think>这个错误信息表明在编译链接过程中,链接器(ld)无法找到名为`libssl`的库文件。以下是分步解释和解决方案: **错误信息解析** ``` /opt/hisi-linux/x86-arm/arm-himix410-linux/host_bin/../lib/gcc/arm-linux-gnueabi/7.3.0/../../../../arm-linux-gnueabi/bin/ld: cannot find -lssl ``` - `-lssl` 表示链接器需要 `libssl.so/libssl.a` 库 - `arm-himix410-linux` 表明是海思Hi3519/Hi3559系列交叉编译工具链 - 路径显示是面向ARM架构的交叉编译环境 **常见原因及解决方案** 1. **确认交叉编译SSL库是否存在** ```bash # 在交叉编译工具链目录中查找 find /opt/hisi-linux/x86-arm/arm-himix410-linux/ -name "libssl*" ``` 预期应找到类似: ``` arm-himix410-linux/arm-linux-gnueabi/lib/libssl.so arm-himix410-linux/arm-linux-gnueabi/lib/libssl.a ``` 2. **安装缺失的交叉编译库** 若未找到库文件,需安装对应SDK: ```bash # 通过海思SDK安装(具体路径可能不同) sudo apt-get install hisi-openssl-dev # 或手动编译openssl: ./Configure linux-armv4 --prefix=/opt/hisi-linux/x86-arm/arm-himix410-linux/ make && make install ``` 3. **检查链接路径** 在Makefile中确保包含: ```makefile LDFLAGS += -L/opt/hisi-linux/x86-arm/arm-himix410-linux/arm-linux-gnueabi/lib ``` 4. **验证库架构兼容性** ```bash file /opt/hisi-linux/x86-arm/arm-himix410-linux/arm-linux-gnueabi/lib/libssl.so ``` 应显示: ``` ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked ``` 5. **创建符号链接(如有需要)** ```bash cd /opt/hisi-linux/x86-arm/arm-himix410-linux/arm-linux-gnueabi/lib ln -s libssl.so.1.1 libssl.so ``` **典型修复流程** ```bash # 1. 安装交叉编译openssl wget https://www.openssl.org/source/openssl-1.1.1w.tar.gz tar xzf openssl-1.1.1w.tar.gz cd openssl-1.1.1w ./Configure linux-armv4 --prefix=/opt/hisi-linux/x86-arm/arm-himix410-linux/arm-linux-gnueabi make CROSS_COMPILE=arm-himix410-linux- make install # 2. 在项目中添加链接路径 export LIBRARY_PATH=/opt/hisi-linux/x86-arm/arm-himix410-linux/arm-linux-gnueabi/lib:$LIBRARY_PATH # 3. 重新编译项目 make clean && make ``` **注意事项** - 需确保openssl版本与工具链兼容(建议使用SDK指定版本) - 交叉编译时避免混用主机库和交叉编译- 海思SDK通常自带验证过的第三方库,优先使用SDK提供的库文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值