4

After upgrading my MacBook Pro to OS X 11.1 Big Sur, I am unable to get compilation of c++ programs using gcc to work.

I am using CLion with CMake, and I get the following error when reloading the CMake configuration

ld: library not found for -lgcc_s.10.4

The things that I have tried are installing Xcode, it installed without error.

I have tried to create a symlink as suggested here https://github.com/Paxa/fast_excel/issues/33

$ cd /usr/local/lib
$ sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.4.dylib

It appears that the library libSystem.B.dylib is not present. Some sites mention that the libraries starting with Big Sur reside in some "shared cache", which I have no idea of what it is and how to access it, let alone make ld access it on its own.

Any suggestions on how to solve this are very welcome. Thank you!

Jon Lachmann
  • 381
  • 1
  • 3
  • 10

4 Answers4

3

According to this answer you should use: g++-10 -o main main.cpp

  • The correct path of brew installed g++ in MacOS is:
$ which g++-10
> /usr/local/bin/g++-10
--
$ which g++ 
> /usr/bin/g++ //this is alias of clang (same for lyb)

If you use CMakeLists.txt file you will configure it like this:

set(CMAKE_CXX_COMPILER "/usr/local/bin/g++-10" CACHE STRING "C compiler" FORCE)
set(CMAKE_C_COMPILER "/usr/local/bin/gcc-10" CACHE STRING "C++ compiler" FORCE)
set(CMAKE_CXX_STANDARD 17)
Mike
  • 342
  • 4
  • 13
2

In general, gcc tends not to work on more recent versions of Mac OS. The solution is to use the build in C/C++ compilers. To automatically use these, instead of GCC, set these environment variables:

CC="clang"
CXX="clang++"

This will use the built in Mac compilers. Once doing this, I have yet to run into an issue with compiling that wasn't due to the actual code being compiled.

1

Thank you for all the answers highlighting different things that could solve the issue. What ended up working was to run brew reinstall gcc, and pointing CLion (or plainly CMake as Mike mentioned) to use the correct compiler (something that I had already done, but I want to mention it here if anyone else finds this question and has the same problem), the paths that I use are

/usr/local/Cellar/gcc/10.2.0/bin/gcc-10
/usr/local/Cellar/gcc/10.2.0/bin/g++-10

These paths are actually just the explicit locations that are linked from

/usr/local/bin/g++-10
/usr/local/bin/gcc-10

Also, as Matt Braunstein mentioned, it is possible to use clang that is supplied with Mac OS X, something I did while figuring out how to solve my issues with gcc.

My thoughts on the problem is that somehow, installing gcc with homebrew didnt install everything needed as it appeared to already be installed from a previous version, the reinstall command seemed to rectify this.

Again, thank you for the answers that helped me find this solution, and possible workarounds.

Jon Lachmann
  • 381
  • 1
  • 3
  • 10
0

I spent hours trying to solve this compilation problem with cmake, the original statement in CMakeLists.txt for library linkage is!

link_directories(/usr/local/lib)
target_link_libraries(Program libsndfile.dylib)

With error message after make:

ld: library not found for -lsndfile

The solution that works is to add the entire path like this:

target_link_libraries(Program /usr/local/lib/libsndfile.dylib)

There is no need to have this in Ubuntu, but somehow the new MacOS requires it.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
wcc2
  • 1
  • 1