1

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() {}

gives:

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

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

dcs16> gcc --version
gcc (MacPorts gcc6 6.5.0_4) 6.5.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

Any help is greatly appreciated.

Note: There is no problem linking with clang.

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/../../../
DavidS
  • 483
  • 5
  • 17
  • Could you try running `sudo port upgrade gcc6`. – Mihir Luthra Sep 24 '19 at 02:56
  • @Mihir I had done that and gcc5 did not work as well. – DavidS Sep 24 '19 at 04:29
  • Does `clang` work correctly? – Mihir Luthra Sep 24 '19 at 04:31
  • @Mihir clang works fine. It is just gcc. – DavidS Sep 24 '19 at 04:55
  • Check out [Can't compile C program on a Mac after upgrade to Mojave](https://stackoverflow.com/questions/52509602/cant-compile-c-program-on-a-mac-after-upgrade-to-mojave/). There's a decent chance the answer will assist you. – Jonathan Leffler Sep 24 '19 at 05:23
  • As per [mailing lists](https://lists.macports.org/pipermail/macports-users/2019-September/047395.html), installing old cmd line tools may help. https://developer.apple.com/download/more/?=xcode – Mihir Luthra Sep 24 '19 at 05:45
  • @Mihir Unfortunately I had already installed the cmd line tools and this did not help. Interestingly enough the system version of gcc in /usr/bin/ works fine. It is just the macports version. – DavidS Sep 24 '19 at 06:05
  • That `/usr/bin/gcc` is actually the `clang` provided by the Xcode command line tools. Why aren't you using those tools anyway? – trojanfoe Sep 24 '19 at 06:05
  • @DavidS, macOS doesn't have any gcc in real. `cc`, `gcc` and `clang` are all `clang`. – Mihir Luthra Sep 24 '19 at 06:08
  • @trojanfoe Interesting. I did not know this. In any case, I need to compile a lot of code including some Fortran modules which clang cannot handle. – DavidS Sep 24 '19 at 06:10
  • OK, well it sounds like your installation of gcc is broken if it does not have `/usr/lib` in its standard library paths. How about removing macports and trying homebrew instead? – trojanfoe Sep 24 '19 at 06:11
  • @trojanfoe Yes I might break down and try homebrew at some point. Interestingly enough, a coworker who also compiles on his mac is having exactly the same problem so it is not just my machine. – DavidS Sep 24 '19 at 06:17
  • It would be interesting to see what `gcc` was configured to use with `gcc -print-search-dirs`. – trojanfoe Sep 24 '19 at 06:18
  • @trojanfoe OK I added this info to the post. – DavidS Sep 24 '19 at 06:23
  • Looks like this problem has been reported to MacPorts: https://trac.macports.org/ticket/59083 – DavidS Sep 24 '19 at 06:24
  • Yeah I don't see `/usr/lib` on there. That is weird. – trojanfoe Sep 24 '19 at 06:24

1 Answers1

3

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

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.

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] And another programmer informs me that he ran into this problem with Xcode 12.3. His solution was to downgrade to 12.2.

DavidS
  • 483
  • 5
  • 17