rugdealer rugdealer - 1 year ago 249
Swift Question

/usr/bin/ld: cannot find -lstdc++ for Ubuntu while trying to "swift build" Perfect2 project


I've followed the installation steps for Swift3 and Perfect2
and I've cloned the PerfectTemplate test project proposed by Perfect and I've tried
swift build

Error Message:

warning: minimum recommended clang is version 3.6, otherwise you may
encounter linker errors. Linking ./.build/debug/PerfectTemplate
/usr/bin/ld: cannot find -lstdc++ clang: error: linker command failed
with exit code 1 (use -v to see invocation) :0: error: link
command failed with exit code 1 (use -v to see invocation)
:0: error: build had 1 command failures error: exit(1):
/etc/swift301/usr/bin/swift-build-tool -f

What I've tried:

I've gone on different SO questions that seemed similar but all on different projects and attempted to try their solutions without luck:

For example:

/usr/bin/ld: cannot find -lstdc++

I also noticed the warning coming from the clang version, I am aware that my current version is 3.4, but that is what was installed via
sudo apt-get install clang
as mentioned in the documentation.

I've also tried installing the 3.6 version of clang with:
sudo apt-get install clang-3.n

However, after when I try
swift build
again I get the following error:

error: invalid inferred toolchain: could not find


How do I get rid of the
/usr/bin/ld: cannot find -lstdc++
error, so I can build the PerfectTemplate project?

Answer Source

Try this. It might not work, but it's worth a shot.

Update packages and dependencies:

sudo apt-get update

Then install clang 3.6:

sudo apt-get install clang-3.6
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100

I hope this helps, but apologies if it doesn't. Best of luck!

If this error appears:

/usr/bin/ error: cannot open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../libstdc++.‌​so: No such file or directory

It's most likely that the symbolic link points to an inexisting file.

In my case it was pointing to:

/usr/lib/ -> /usr/lib/

Which was incorrect because did not exist in that area. Simply find it's location via: sudo find / -name which gave me:


Then recreate the link with:

sudo rm /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib/
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download