
Fixing C++ compilation bugs for the MacOS Catalina upgrade
Fixing C++ compilation bugs for the MacOS Catalina upgrade
I recently updated to macOS Catalina and encountered several issues with programs that use a C/C++ compiler.
If you see any of these errors this post might be helpful for you:
/usr/local/Cellar/llvm/7.0.1/include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file
not found
#include_next
^~~~~~~~~
1 error generated.
Or any error indicating that a standard library couldn't be found:
ld: library not found for -ldl
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
What's the issue?
The issue is that macOS Catalina doesn't use the /usr/include and /usr/lib/ directories anymore for all C++ headers and libraries.
A lot of projects rely on these directories to exist, can't find the files and then break.
Instead they are under the xcode path and you need to tell the C/C++ compiler where to find these libraries now.
How to fix it?
- Optionally, install a C++ compiler like clang / gcc through
brewif one is missing. - Install Xcode through the App store to get access to the developer command-line tools.
This will install the C++ header files and libraries, albeit, in a different directory. They will be installed in/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdkor a similar directory. To get the correct path for your system you can run thexcrun --show-sdk-pathcommand. - The C++ compiler needs to be told to look at this root path instead of
/usr/include. This can be done by setting theCPLUS_INCLUDE_PATHenv variable. It's important to also include LLVM's normal include path because this is where it should search first.
This should fix any# adjust your llvm and CLT include paths to match your setup export CPLUS_INCLUDE_PATH=/usr/local/opt/llvm/include/c++/v1:/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/includefatal error: 'xxx.h' file not founderrors. - You might still run into linker errors like
ld: library not found for -lxxx. The linker also needs to be told to look for libraries in the CommandLineTools/Xcode paths by setting theLIBRARY_PATHenv variable.export LIBRARY_PATH=$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib - Make sure to add these
exportstatements to your.bash_rc,.zshrc,.bash_profile, or whatever shell you use, to make these adjusted environment variables available in all terminals.
Resources
Thanks a lot to this GitHub post for helping me figure out what's wrong.
Originally published at https://cmichel.io/fixing-cpp-compilation-bugs-for-the-mac-os-catalina-upgrade/
Leave Fixing C++ compilation bugs for the MacOS Catalina upgrade to:
Read more #macos posts
Best Posts From cmichel
We have not curated any of cmichel's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From cmichel
- How I gamed EOS Defi projects and still got rekt
- Progress Report - September 2020
- How to install an old package version with brew
- Fixing C++ compilation bugs for the MacOS Catalina upgrade
- Progress Report - August 2020
- Progress Report - July 2020
- Obfuscating EOSIO smart contracts
- Progress Report - June 2020
- Progress Report - May 2020
- Typing transformations in TypeScript
- 8 EOSIO WASM intrinsics you might not have heard about
- EOSIO C++ IntelliSense in VSCode
- Testing EOSIO smart contracts with Hydra
- Progress Report - March 2020
- Progress Report - February 2020
- How to check if an EOS account has a smart contract
- Launching EOS Token Portfolio
- How to deploy a create-react-app with github-actions
- Progress Report - January 2020
- How to rollback to an older EOSIO.CDT version with brew