create account

Fixing C++ compilation bugs for the MacOS Catalina upgrade by cmichel

View this thread on: hive.blogpeakd.comecency.com
· @cmichel ·
$0.18
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:

```bash
/usr/local/Cellar/llvm/7.0.1/include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file
      not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.
```

Or any error indicating that a standard library couldn't be found:

```bash
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?

1.  Optionally, install a C++ compiler like clang / gcc through `brew` if one is missing.
2.  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.sdk` or a similar directory. To get the correct path for your system you can run the `xcrun --show-sdk-path` command.
3.  The C++ compiler needs to be told to look at this root path instead of `/usr/include`. This can be done by setting the `CPLUS_INCLUDE_PATH` env variable. It's important to also **include LLVM's normal include path** because this is where it should search first.
    ```bash
    # 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/include
    ```
    This should fix any `fatal error: 'xxx.h' file not found` errors.
4.  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 the `LIBRARY_PATH` env variable.
    ```bash
    export LIBRARY_PATH=$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib
    ```
5.  Make sure to add these `export` statements 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](https://github.com/imageworks/OpenShadingLanguage/issues/1055#issuecomment-581920327) for helping me figure out what's wrong.

* * *

Originally published at <https://cmichel.io/fixing-cpp-compilation-bugs-for-the-mac-os-catalina-upgrade/>
👍  , , , , ,
properties (23)
authorcmichel
permlinkfixing-cpp-compilation-bugs-for-the-mac-os-catalina-upgrade
categorymacos
json_metadata{"tags":["macos","catalina","Programming","C++"],"format":"markdown","app":"steemit/0.1"}
created2020-09-24 19:31:15
last_update2020-09-24 19:31:15
depth0
children1
last_payout2020-10-01 19:31:15
cashout_time1969-12-31 23:59:59
total_payout_value0.091 HBD
curator_payout_value0.091 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,855
author_reputation1,950,560,061,631
root_title"Fixing C++ compilation bugs for the MacOS Catalina upgrade"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id99,799,608
net_rshares1,112,250,929,384
author_curate_reward""
vote details (6)
@diyhub ·
<div class="pull-right"><a href="https://steempeak.com/trending/hive-189641"><img src="https://cdn.steemitimages.com/DQmV9e1dikviiK47vokoSCH3WjuGWrd6PScpsgEL8JBEZp5/icon_comments.png"></a></div>

###### Thank you for sharing this amazing post on HIVE!

- Your content got selected by our fellow curator @tibfox & you just received a little thank you via an upvote from our **non-profit** curation initiative!

- You will be **featured in** one of our recurring **curation compilations** and on our **pinterest** boards! Both are aiming to offer you a **stage to widen your audience** within and outside of the DIY scene of hive.

**Join** the official [DIYHub community on HIVE](https://peakd.com/trending/hive-189641) and show us more of your amazing work and feel free to connect with us and other DIYers via our discord server: https://discord.io/diyhub!

If you want to support our goal to motivate other DIY/art/music/homesteading/... creators just delegate to us and earn 100% of your curation rewards!

###### Stay creative & hive on!
properties (22)
authordiyhub
permlinkre-fixing-cpp-compilation-bugs-for-the-mac-os-catalina-upgrade-20200929t093029z
categorymacos
json_metadata"{"app": "beem/0.24.5"}"
created2020-09-29 09:30:30
last_update2020-09-29 09:30:30
depth1
children0
last_payout2020-10-06 09:30:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,041
author_reputation540,946,737,290,491
root_title"Fixing C++ compilation bugs for the MacOS Catalina upgrade"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id99,874,936
net_rshares0