linux编译安装提示gcc未安装
来源:本站原创
点击数: 次
发布时间:2025年02月07日
问题描述:已经安装gcc环境,但是编译其他程序的时候提示'C compiler cannot create executables'错误,可能就是gcc环境未配置好
解决办法:
1.检查环境变量是否有问题(一般都是正常)
#添加环境变量
vim /etc/profile
export PATH=/path/to/gcc/bin:$PATH
其中/path/to/gcc/bin
应该替换为实际的GCC二进制文件所在的目录。
修改完毕后,使该配置文件生效
source /etc/profile
2.确认是否安装gcc
gcc --version
如果可以显示出版本号
创建一个test.c的测试脚本
#include <stdio.h> int main() { printf("hello, world!\n"); return 0; }
然后执行 gcc test.c -o test
没问题会正常打印出hello world,异常一般会返回例如:
libmpfr.so.4: cannot open shared object file: No such file or directory
此时就知道是缺少libmpfr.so库文件,简单的版本就是找个同版本操作系统下,查询相关文件然后拷贝过去
find /usr -name libmpfr.so.4,补上库文件后再编译安装其他程序就不会提示gcc环境问题