无法在Mac Mojave上用gcc链接任何C程序 [英] Cannot link any C program with gcc on Mac Mojave

查看:66
本文介绍了无法在Mac Mojave上用gcc链接任何C程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚更新到OSX 10.14.6(Mojave),现在,在升级Xcode并迁移MacPorts之后,即使最简单的C程序也不会与任何gcc版本链接.例如,链接程序

I've just updated to OSX 10.14.6 (Mojave) and now, after upgrading Xcode and migrating MacPorts, even the simplest C program will not link with any gcc version. For example, linking the program

int main() {}

给予:

dcs16> gcc test.c 
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status

我在/opt/local/bin中使用gcc 6.5:

I am using gcc 6.5 in /opt/local/bin:

dcs16> gcc --version
gcc (MacPorts gcc6 6.5.0_4) 6.5.0

Xcode版本为11.0,并且我已经安装了软件包(建议使用该软件包来解决其他人遇到的一些编译问题):

The Xcode version is 11.0 and I have installed the package (which was recommended for solving some compile problems that other people had):

/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

非常感谢您的帮助.

注意:与clang链接没有问题.

Note: There is no problem linking with clang.

注意gcc搜索目录为:

Note gcc search dirs are:

test> gcc -print-search-dirs
install: /opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/
programs: =/opt/local/libexec/gcc/x86_64-apple-darwin18/6.5.0/:/opt/local/libexec/gcc/x86_64-apple-darwin18/6.5.0/:/opt/local/libexec/gcc/x86_64-apple-darwin18/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/../../../../../x86_64-apple-darwin18/bin/x86_64-apple-darwin18/6.5.0/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/../../../../../x86_64-apple-darwin18/bin/
libraries: =/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/../../../../../x86_64-apple-darwin18/lib/x86_64-apple-darwin18/6.5.0/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/../../../../../x86_64-apple-darwin18/lib/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/../../../x86_64-apple-darwin18/6.5.0/:/opt/local/lib/gcc6/gcc/x86_64-apple-darwin18/6.5.0/../../../

推荐答案

添加"-L/usr/lib"解决了这个问题.

Adding "-L/usr/lib" solves the problem.

还可以从Xcode 11.0降级到Xcode 10.3解决了该问题!注意:我还检查了刚刚推出的Xcode 11.1,但问题仍然存在于11.1.

Also downgrading from Xcode 11.0 to Xcode 10.3 solves the problem! Note: I also checked Xcode 11.1 which just came out but the problem still exists with 11.1.

添加了注释:另一个程序员通知我,升级到OSX 10.15可以解决此问题.因此,这是OSX 10.14与Xcode 11之间的不兼容.

Note added: Another programmer informs me that upgrading to OSX 10.15 solves the problem. So this is an incompatibility between OSX 10.14 and Xcode 11.

[Added 28/12/2020]另一个程序员告诉我他在Xcode 12.3中遇到了这个问题.他的解决方案是降级到12.2.

[Added 28/12/2020] And another programmer informs me that he ran into this problem with Xcode 12.3. His solution was to downgrade to 12.2.

这篇关于无法在Mac Mojave上用gcc链接任何C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆