30

After updating Xcode Version to 10.0 beta start getting "ld: library not found for -lstdc++.6" error. same code working fine in Xcode 9.2

Also updated macOS to 10.13.5

vks
  • 303
  • 1
  • 3
  • 7

7 Answers7

14

You'll have this issue when targeting iOS App. It's stated in the Release note:

Deprecation Notices:

Building with libstdc++ was deprecated with Xcode 8 and is not supported in Xcode 10 when targeting iOS. C++ projects must now migrate to libc++ and are recommended to set a deployment target of iOS 7 or later. Besides changing the C++ Standard Library build setting, developers should audit hard-coded linker flags and target dependencies to remove references to libstdc++ (including -lstdc++, -lstdc++.6.0.9, libstdc++.6.0.9.tbd, and libstdc++.6.0.9.dylib). Project dependencies such as static archives that were built against libstdc++ will also need to be rebuilt against libc++. (40885260)

Source: Release Notes of XCode Beta 2

Side Note:
You need to be logged to access the page.
Link might break in next beta release (URLs change), but it's in the part Developers/Download

XCode 10 being officially released with its release note, it's still as such:

Building with libstdc++ was deprecated with Xcode 8 and is not supported in Xcode 10 when targeting iOS. C++ projects must now migrate to libc++ and are recommended to set a deployment target of macOS 10.9 or later, or iOS 7 or later. Besides changing the C++ Standard Library build setting, developers should audit hard-coded linker flags and target dependencies to remove references to libstdc++ (including -lstdc++, -lstdc++.6.0.9, libstdc++.6.0.9.tbd, and libstdc++.6.0.9.dylib). Project dependencies such as static archives that were built against libstdc++ will also need to be rebuilt against libc++. (40885260)

Larme
  • 24,190
  • 6
  • 51
  • 81
  • Thanks for you reply. yes issue is with C code in Xcode beta version. for now i starting using Xcode 9.4.1 and it is working fine without code rebuilt – vks Jul 04 '18 at 05:33
  • I am also facing same issue in my iOS project. how to resolve this issue in Xcode 10. – iSara Sep 19 '18 at 13:12
  • 1
    @iSara As said, it has been removed. Did you read the full message? If you static lib was using `stdC++`, then it has to be rebuilt with c++ instead. If it's a third party, notify them, wait for them to do so. – Larme Sep 19 '18 at 13:14
  • @Larme I have removed -lstdc++ and added -lc++ library and now i am facing different issue like "std::ostream::flush()", referenced from: -[MAFConsoleLogger logMessage:withLevel:andInfo:] in libMAFLogger.a(MAFConsoleLogger.o) ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) can you please tell me detail what are the step i need to follow to solve this issue. – iSara Sep 19 '18 at 14:26
  • 1
    And what is `MAFConsoleLogger`? Apparently you have a static lib name as such. Well, it needs to be rebuilt using `libc++` instead of `libstdc++`. In other words, it was also depending on `libstdc++`, but since it's unsupported now, you have to rebuild it. – Larme Sep 19 '18 at 14:28
  • @Larme can you please give details about how to rebuild it Thanks in advance. – iSara Sep 19 '18 at 14:30
  • 1
    Where did you get that library? Ask the one who built to adapt it. – Larme Sep 19 '18 at 14:31
  • @Larme Ok, I will check with them and Thank you very much for your feedback. – iSara Sep 19 '18 at 14:38
  • For me it was simply Deployment Target. Thanks for posting this. – shs Sep 24 '18 at 04:25
  • 1
    I am trying to compile an outdated project that I have downloaded, is there any other answer than "it is deprecated and does not work anymore"? – Lukas Feb 18 '19 at 14:27
13

The quick solution is to copy all libstdc++.* file from old Xcode(9.4) to new Xcode(10.x)

For device :

cp /Applications/Xcode9.4.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libstdc++.* /Applications/Xcode10.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/

For Simulator :

cp /Applications/Xcode9.4.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/libstdc++.* /Applications/Xcode10.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/

Shamsher Singh
  • 297
  • 2
  • 8
7

As said above lstdc++ is removed from Xcode 10. To fix this,

  1. Go to Target -> BuildPhases -> Link Binary With Libraries

  2. Search for lstdc++ and remove it.

  3. Now you might get error in some framework which uses the above said "lstdc++" library. Now either you have to update those framework or remove it so that Xcode can build it successfully.

rajtharan-g
  • 432
  • 5
  • 14
5
  1. If you are using an external Makefile for building C++ libraries, add

CXXFLAGS += -stdlib=libc++ your external library Makefile and removed instances of -stdlib=stdlibc++

  1. If not, ignore the above step, just go to Project>Target>Link Binary with libraries>
    • Remove (-) libstdc++.6.0.9.tbd
    • Add (+) libc++.tbd
ir2pid
  • 5,604
  • 12
  • 63
  • 107
1

This was failing for me when trying to do a make install. Instead, I ran make install -stdlib=libc++, which did the trick.

user394430
  • 2,805
  • 2
  • 28
  • 27
0

I was trying to compile C program and got ld: library not found for -lc++

Because of deprecation as mentioned and the work around that to tell C++ to read from old mac sdk /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk

# 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
# then set correct var for compiler lib
export LIBRARY_PATH=$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib

nice walkthrough at fixing-cpp-compilation-bugs-for-the-mac-os-catalina-upgrade

Ahmed Shehab
  • 1,657
  • 15
  • 24
-2

Simply go to build settings, Link binary with libraries and there remove this.It resolved my issue.

user1828845
  • 1,304
  • 1
  • 10
  • 17