swift-nio-ssl: fatal error: 'memory' file not found

I was trying to test out the new nio-http-client on Ubuntu 18.04 and I’m getting the following error when it is building this framework:

In file included from ~/TestHTTPClient/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/ssl/t1_enc.cc:136:
~/TestHTTPClient/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/openssl/ssl.h:145:
~/TestHTTPClient/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/openssl/base.h:463:10: fatal error: 'memory' file not found
#include <memory>

I’ve verified that there is a memory.h file in /usr/include. I couldn’t find any references to this issue elsewhere. Would anyone have any tips for where to go next to figure out why this error is happening?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (8 by maintainers)

Most upvoted comments

Try installing libstdc++-12-dev. Your clang has selected a newer gcc, so you need the associated libstdc++.

Thanks. On Fedora (38) the fix is: sudo dnf install libstdc++-devel

Thank you @Lukasa. Installing libstdc++-12-dev has likely solved the problem.

If anybody reads this today, if you see a similar error, it’s likely that you’re on Linux and you haven’t got the libstdc++-9-dev package installed. That’s the name of this package on Ubuntu/Debian, will be slightly different for Fedora/CentOS.

To debug this, please send the output of clang -v (be sure to use the clang from the error message) and find /usr/include -name memory.

This should look something like

root@13454ee90b71:/Users/johannes/devel/swift-nio-ssl# clang -v
clang version 10.0.0 (git@github.com:apple/llvm-project.git 3647999e44ce50ad929d350218000661d4622ca6)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7     # JW: only if you got an old libstdc++ installed
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/7.5.0 # JW: only if you got an old libstdc++ installed
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/8     # JW: only if you got an old libstdc++ installed
Found candidate GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/9     # JW: THIS IS THE ONE WE WANT
Selected GCC installation: /usr/bin/../lib/gcc/aarch64-linux-gnu/9            # JW: GOOD! It picked the right one.
Candidate multilib: .;@m64
Selected multilib: .;@m64
root@13454ee90b71:/Users/johannes/devel/swift-nio-ssl# swift build^C
root@13454ee90b71:/Users/johannes/devel/swift-nio-ssl# find /usr/include/ -name memory
/usr/include/c++/9/tr1/memory
/usr/include/c++/9/memory       # JW: THIS IS THE IMPORTANT ONE
[...]

@Ponyboy47 Thanks for posting the issue. #include <memory> is a C++ thing that does not include memory.h but rather a C++ header, for example /usr/include/c++/7/memory.

It seems like you don’t have libstdc++ installed on your system. The easiest way to fix this is probably

apt-get install build-essential

which contains all the essential build tools. You could also just install libstdc++-7-dev.

Thanks! sudo apt install libstdc++-12-dev solved the issue.

Awesome, glad this worked. In the end, Swift should just always use its own clang, otherwise things like this will continue to happen. I did file a bug about this earlier so I hope in the future, this won’t be an issue.

So I figured it out! I remove cpp-8 (and all the clang packages since the clang executable was included with swiftenv). Now it is building just fine. I only have cpp and cpp-7 packages now