# CPPLib\_log error when building with Xcode

**URL:** <https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550>\
**Category:** Compiler\
**Tags:** xcode, build-script, help-needed\
**Created:** [June 12, 2021, 3:23pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550 "2021-06-12T15:23:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![elidy](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/elidy/32/17894_2.png) [@elidy](https://forums.swift.org/u/elidy)\
**Post date:** [June 12, 2021, 3:23pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/1 "2021-06-12T15:23:02Z")

</div>

I'm trying to build Swift with Xcode following the [Getting Started Guide](https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md).

I'm running the following command:

```swift
utils/build-script --verbose-build --skip-build-benchmarks \
  --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \--sccache --release-debuginfo --swift-disable-dead-stripping --test \
  --xcode --skip-test-cmark

```

The error I get is the following:

`User/swift-project/swift/validation-test/BuildSystem/swift-cmake/Klass.swift:14:5: error: cannot find 'CPPLib_log' in scope`

```swift
The following build commands failed:
CompileSwift normal x86_64 /User/swift-project/swift/validation-test/BuildSystem/swift-cmake/Klass.swift
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
CompileSwift normal x86_64 /User/swift-project/swift/validation-test/BuildSystem/swift-cmake/Klass.swift
(3 failures)
ERROR: command terminated with a non-zero exit status 65, aborting

```

Any help troubleshooting appreciated!

Xcode version 12.5  
macOS BigSur 11.3.1

---

<div class="post-metadata">

**Author:** ![typesanitizer](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/typesanitizer/32/8661_2.png) [@typesanitizer](https://forums.swift.org/u/typesanitizer)\
**Post date:** [June 12, 2021, 5:00pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/2 "2021-06-12T17:00:55Z")

</div>

I'm not sure why that failure is happening but I suggest skipping the `--test` flag and trying to do a clean build without it until the issue is resolved. You can [separately run the tests](https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md#running-tests) using `lit.py`.

cc @Michael_Gottesman

---

<div class="post-metadata">

**Author:** ![jackmarch](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jackmarch/32/12927_2.png) [@jackmarch](https://forums.swift.org/u/jackmarch)\
**Post date:** [June 12, 2021, 5:49pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/3 "2021-06-12T17:49:53Z")

</div>

Same error here

(Seems you also used skip-test-cmark flag, guessing you had the same issue as me running those tests as well)

---

<div class="post-metadata">

**Author:** ![LucianoPAlmeida](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lucianopalmeida/32/2134_2.png) [@LucianoPAlmeida](https://forums.swift.org/u/LucianoPAlmeida)\
**Post date:** [June 12, 2021, 6:14pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/4 "2021-06-12T18:14:25Z")

</div>

I hit that few days ago, here is a workaround just to build using Xcode [[cmake] On Darwin, teach add\_swift\_host\_tool how to find swift's SDK/compat libs, fix the rpath of tools, and add tests. by gottesmm · Pull Request #37741 · apple/swift · GitHub](https://github.com/apple/swift/pull/37741#issuecomment-854777508)  
@typesanitizer Should we track this down on a JIRA ticket?

---

<div class="post-metadata">

**Author:** ![typesanitizer](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/typesanitizer/32/8661_2.png) [@typesanitizer](https://forums.swift.org/u/typesanitizer)\
**Post date:** [June 12, 2021, 7:59pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/5 "2021-06-12T19:59:15Z")

</div>

Filed SR-14768.

[https://bugs.swift.org/browse/SR-14768](https://bugs.swift.org/browse/SR-14768)

---

<div class="post-metadata">

**Author:** ![jackmarch](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jackmarch/32/12927_2.png) [@jackmarch](https://forums.swift.org/u/jackmarch)\
**Post date:** [June 12, 2021, 8:01pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/6 "2021-06-12T20:01:05Z")

</div>

> [@typesanitizer](#):
>
> I suggest skipping the `--test` flag and trying to do a clean build without it until the issue is resolved

I omitted the test flag but same issue unfortunately:

```swift
tils/build-script --skip-build-benchmarks \
  --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
  --sccache --release-debuginfo --swift-disable-dead-stripping \
  --xcode --clean

```

R.E this workaround:

> [@LucianoPAlmeida](#):
>
> I hit that few days ago, here is a workaround just to build using Xcode

Update: now the workaround has been updated to refer to a different line, it works!  
~~This only removed one of the errors for me unfortunately (sorry I accidentally closed the log so don't have more details), though I wasn't using `--debug-swift` flag if that makes any difference.~~ I'm building now to see if removing the logging line from Klass.swift works as an alternate workaround.

---

<div class="post-metadata">

**Author:** ![Michael\_Gottesman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_gottesman/32/280_2.png) [@Michael\_Gottesman](https://forums.swift.org/u/Michael_Gottesman)\
**Post date:** [June 12, 2021, 8:29pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/7 "2021-06-12T20:29:45Z")

</div>

I'll take a look. I have a feeling (without looking BTW so I could be wrong) about what the solution is.

EDIT: Also thanks for the bug report!

---

<div class="post-metadata">

**Author:** ![jackmarch](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jackmarch/32/12927_2.png) [@jackmarch](https://forums.swift.org/u/jackmarch)\
**Post date:** [June 12, 2021, 9:31pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/8 "2021-06-12T21:31:20Z")

</div>

> [@jackmarch](#):
>
> I'm building now to see if removing the logging line from Klass.swift works as an alternate workaround.

Just an update to this: I ran the following command after removing the logging line from the Klass file:

```swift
utils/build-script --skip-build-benchmarks \
  --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
  --sccache --release-debuginfo --swift-disable-dead-stripping \
  --xcode --clean

```

While this removed the Klass errors, my build failed later, not sure if related to me removing the logging line but thought I'd share just in case... Given this has to do with a test target, I'll try adding `--test` back to see if that fixes anything. **Update: It did not fix anything**

> Ld /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86\_64/RelWithDebInfo/lib/libTestPureSwiftSharedLib.dylib normal (in target 'TestPureSwiftSharedLib' from project 'Swift')
> 
> cd /Users/jackmarch/swift-project/swift
> 
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target x86\_64-apple-macos11.3 -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -L/Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86\_64/RelWithDebInfo/lib -L/Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/llvm-macosx-x86\_64/RelWithDebInfo/lib/RelWithDebInfo -L/Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/llvm-macosx-x86\_64/RelWithDebInfo/lib -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/RelWithDebInfo -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -F/Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86\_64/RelWithDebInfo/lib -filelist /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86\_64/validation-test/BuildSystem/swift-cmake/Swift.build/RelWithDebInfo/TestPureSwiftSharedLib.build/Objects-normal/x86\_64/TestPureSwiftSharedLib.LinkFileList -install\_name @rpath/libTestPureSwiftSharedLib.dylib -Xlinker -object\_path\_lto -Xlinker /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86\_64/validation-test/BuildSystem/swift-cmake/Swift.build/RelWithDebInfo/TestPureSwiftSharedLib.build/Objects-normal/x86\_64/TestPureSwiftSharedLib\_lto.o -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -L/usr/lib/swift -Xlinker -add\_ast\_path -Xlinker /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86\_64/validation-test/BuildSystem/swift-cmake/Swift.build/RelWithDebInfo/TestPureSwiftSharedLib.build/Objects-normal/x86\_64/TestPureSwiftSharedLib.swiftmodule -Xlinker -compatibility\_version -Xlinker 1 -import-objc-header /Users/jackmarch/swift-project/swift/validation-test/BuildSystem/swift-cmake/CPPLib.h -dynamiclib /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86\_64/RelWithDebInfo/lib/libTestCPPLib.a -lc++ -Xlinker -no\_adhoc\_codesign -Xlinker -dependency\_info -Xlinker /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86\_64/validation-test/BuildSystem/swift-cmake/Swift.build/RelWithDebInfo/TestPureSwiftSharedLib.build/Objects-normal/x86\_64/TestPureSwiftSharedLib\_dependency\_info.dat -o /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86\_64/RelWithDebInfo/lib/libTestPureSwiftSharedLib.dylib
> 
> clang: error: unknown argument: '-import-objc-header'
> 
> clang: error: cannot specify -o when generating multiple output files
> 
> Command Ld failed with a nonzero exit code
> 
> \*\*\*\* BUILD FAILED \*\*\*\*
> 
> The following build commands failed:
> 
> Ld /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86\_64/RelWithDebInfo/lib/libTestPureSwiftSharedLib.dylib normal
> 
> (1 failure)
> 
> ERROR: command terminated with a non-zero exit status 65, aborting

---

<div class="post-metadata">

**Author:** ![LucianoPAlmeida](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lucianopalmeida/32/2134_2.png) [@LucianoPAlmeida](https://forums.swift.org/u/LucianoPAlmeida)\
**Post date:** [June 12, 2021, 11:12pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/9 "2021-06-12T23:12:19Z")

</div>

Given your output paths ` /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/validation-test/` it is still trying to build validation tests... which to me (but I may don't fully understand the changes on cmake) it should not happen if you comment [https://github.com/apple/swift/blob/e731f013ceb12acb744f842fb3a4ef38d9c21c10/CMakeLists.txt#L1074](https://github.com/apple/swift/blob/e731f013ceb12acb744f842fb3a4ef38d9c21c10/CMakeLists.txt#L1074)

Edit: I just noted that the link on the comment of GitHub was pointing to the wrong line ..., just fixed =]

---

<div class="post-metadata">

**Author:** ![jackmarch](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jackmarch/32/12927_2.png) [@jackmarch](https://forums.swift.org/u/jackmarch)\
**Post date:** [June 12, 2021, 11:47pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/10 "2021-06-12T23:47:37Z")

</div>

> [@LucianoPAlmeida](#):
>
> Edit: I just noted that the link on the comment of GitHub was pointing to the wrong line ..., just fixed =]

the new line you've suggested to comment out instead has worked like a charm, cheers Luciano!

---

<div class="post-metadata">

**Author:** ![jackmarch](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jackmarch/32/12927_2.png) [@jackmarch](https://forums.swift.org/u/jackmarch)\
**Post date:** [June 13, 2021, 6:22pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/11 "2021-06-13T18:22:35Z")

</div>

Is commenting ` add_subdirectory(validation-test)` likely the reason so many of the tests are failing when I try to run them @LucianoPAlmeida ? (Note I changed the path from Ninja to Xcode, not sure if this is the reason as it says "warning: Building Xcode project is not supported yet. Skipping..."):

```swift
swift % utils/run-test --lit ../llvm-project/llvm/utils/lit/lit.py \
  ../build/Xcode-RelWithDebInfoAssert/swift-macosx-$(uname -m)/test-macosx-$(uname -m)

```

```swift
Testing Time: 377.40s
  Unsupported : 275
  Passed : 540
  Expectedly Failed: 25
  Failed : 6138

```

Has errors about swift-frontend not found:

> /Users/jackmarch/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86\_64/test-macosx-x86\_64/APINotes/Output/type\_changes.swift.script: line 1: swift-frontend: command not found

Running tests from Xcode in check-swift-all target doesn't work either, e.g. errors like:

> In file included from /Users/jackmarch/swift-project/swift/unittests/Localization/SerializationTests.cpp:13:  
> /Users/jackmarch/swift-project/swift/unittests/Localization/LocalizationTest.h:26:10: fatal error: 'gtest/gtest.h' file not found  
> #include "gtest/gtest.h"  
> ^ ~~~~~~~~~~~~~~  
> 1 error generated.

---

<div class="post-metadata">

**Author:** ![LucianoPAlmeida](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lucianopalmeida/32/2134_2.png) [@LucianoPAlmeida](https://forums.swift.org/u/LucianoPAlmeida)\
**Post date:** [June 13, 2021, 7:25pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/12 "2021-06-13T19:25:50Z")

</div>

Normally you run lit tests against a ninja build. So you build Xcode to work on a nice IDE, and for running lit tests you use a ninja build that I normally use:

// Ninja Build command

`./swift/utils/build-script --release --skip-build-benchmarks --swift-darwin-supported-archs 'x86_64' --sccache --skip-ios --skip-tvos --skip-watchos`

// And then for Testing  
`llvm-project/llvm/utils/lit/lit.py -sv --param swift_site_config=build/Ninja-ReleaseAssert/swift-macosx-x86_64/test-macosx-x86_64/lit.site.cfg swift/test/`

Note that the folder x86\_64 may be different if you are building on a M1 Mac ...  
But for lit tests I always used the ninja build, because as far as I know it will not work on Xcode one ... so in short you have to build both ninja and Xcode, and run lit against the ninja one =]

> [@jackmarch](#):
>
> Running tests from Xcode in check-swift-all target doesn't work either, e.g. errors like:
> 
> > In file included from /Users/jackmarch/swift-project/swift/unittests/Localization/SerializationTests.cpp:13:  
> > /Users/jackmarch/swift-project/swift/unittests/Localization/LocalizationTest.h:26:10: fatal error: 'gtest/gtest.h' file not found  
> > #include "gtest/gtest.h"  
> > ^ ~~~~~~~~~~~~~~  
> > 1 error generated.

This target I think will run the UnitTests(cpp unit tests under unittests folder) not the test/\*\* that we run using lit. But this error is already tracked on an issue [[SR-14352] Xcode fails to run Swift unittests · Issue #56711 · apple/swift · GitHub](https://bugs.swift.org/browse/SR-14352) and I'm not sure, but maybe [https://github.com/apple/swift/pull/36971](https://github.com/apple/swift/pull/36971) will fix it ...

---

<div class="post-metadata">

**Author:** ![jevonmao](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jevonmao/32/18113_2.png) [@jevonmao](https://forums.swift.org/u/jevonmao)\
**Post date:** [June 18, 2021, 4:13am UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/13 "2021-06-18T04:13:36Z")

</div>

What do you mean by "here is a workaround just to build using Xcode"? Sounds like you came up with a solution. I don't understand how to make it work, I'm getting the same build fail error from Klass.swift and com.apple.xcode.tools.swift.compiler.

---

<div class="post-metadata">

**Author:** ![elidy](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/elidy/32/17894_2.png) [@elidy](https://forums.swift.org/u/elidy)\
**Post date:** [June 18, 2021, 9:01am UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/14 "2021-06-18T09:01:37Z")

</div>

in the folder swift-project/swift you will find a CMakeLists.txt. Luciano's workaround consists in commenting out the line 1074 ` add_subdirectory(validation-test)` in this file and then run the build command again. Worked for me!:)

---

<div class="post-metadata">

**Author:** ![jevonmao](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jevonmao/32/18113_2.png) [@jevonmao](https://forums.swift.org/u/jevonmao)\
**Post date:** [June 18, 2021, 8:23pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/15 "2021-06-18T20:23:57Z")

</div>

Thanks. I will try that, but after commenting that line out, should I do an Xcode command+B build, or the much slower terminal build with:

```swift
utils/build-script --verbose-build --skip-build-benchmarks \
  --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \--sccache --release-debuginfo --swift-disable-dead-stripping --test \
  --xcode --skip-test-cmark

```

---

<div class="post-metadata">

**Author:** ![LucianoPAlmeida](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lucianopalmeida/32/2134_2.png) [@LucianoPAlmeida](https://forums.swift.org/u/LucianoPAlmeida)\
**Post date:** [June 18, 2021, 8:44pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/16 "2021-06-18T20:44:16Z")

</div>

Cmake will have to re-run, so I would recommend use build script =]

---

<div class="post-metadata">

**Author:** ![jevonmao](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jevonmao/32/18113_2.png) [@jevonmao](https://forums.swift.org/u/jevonmao)\
**Post date:** [June 18, 2021, 10:28pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/17 "2021-06-18T22:28:01Z")

</div>

Thank you so much, your solution worked!  
Now it's learning time for me, I have a lot of things to figure out from scratch before hopefully contributing to Swift.

---

<div class="post-metadata">

**Author:** ![Michael\_Gottesman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_gottesman/32/280_2.png) [@Michael\_Gottesman](https://forums.swift.org/u/Michael_Gottesman)\
**Post date:** [June 20, 2021, 8:12pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/18 "2021-06-20T20:12:55Z")

</div>

So I think the right solution here is to not disable --validation-test. Rather I think that we probably want to just disable this test for now with the Xcode generator. The Xcode generator has many issues and isn't the normal build people use (we generally use ninja). So I am going to throw up a patch that does just that.

---

<div class="post-metadata">

**Author:** ![Michael\_Gottesman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_gottesman/32/280_2.png) [@Michael\_Gottesman](https://forums.swift.org/u/Michael_Gottesman)\
**Post date:** [June 21, 2021, 8:06pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/19 "2021-06-21T20:06:17Z")

</div>

> <https://github.com/apple/swift/pull/37994>
>
> We should re-enable this once it is clear that there aren't issues with the
> Xco…de generator/host side swift cmake. The Ninja generator (the default) still
> is enabled.
> 
> \----
> 
> Patch inspired by this thread: https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/8

Its fixed. So you all should be good now.

---

<div class="post-metadata">

**Author:** ![LucianoPAlmeida](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lucianopalmeida/32/2134_2.png) [@LucianoPAlmeida](https://forums.swift.org/u/LucianoPAlmeida)\
**Post date:** [June 22, 2021, 12:28pm UTC](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550/20 "2021-06-22T12:28:13Z")

</div>

@Michael_Gottesman It seems like it introduced another problem

 ![Screen Shot 2021-06-22 at 09.23.42](https://global.discourse-cdn.com/swift/original/3X/d/0/d07abd1f3d618443e266988897c31b97e963254c.png)

Xcode build is expecting to link against libswift.  
I'm using `./swift/utils/build-script --xcode --release-debuginfo --debug-swift --skip-build-benchmarks --swift-darwin-supported-archs 'x86_64' --sccache --skip-ios --skip-tvos --skip-watchos --swift-disable-dead-stripping --skip-test-cmark` ad Xcode 12.5 (12E262)

[Next page](https://forums.swift.org/t/cpplib-log-error-when-building-with-xcode/49550.md?page=2)
