swift build: error: could not build Objective-C module 'Darwin' - swift

I'm trying to run the 'example-package-dealer' from the Swift Package Manager repo but it's failing to build resulting with this error:
/usr/local/include/string.h:26:10: error: 'dpkg/macros.h' file not found
#include <dpkg/macros.h>
<unknown>:0: error: could not build Objective-C module 'Darwin'

Related

Not able to compile swift on Ubuntu 18.04

I installed swift toolchain using instructions from swift.org. While compiling helloworld code I am getting below error.
warning: 'helloworld': failed loading cached manifest for 'helloworld': disk I/O error
error: 'helloworld': Invalid manifest
<unknown>:0: error: unable to open output file '/usr2/xyz/.cache/clang/ModuleCache/IJ5GUC7XMAO5/SwiftShims-1TLN9ZL6HKTHR.pcm': 'No such file or directory'
<unknown>:0: error: could not build C module 'SwiftShims'
I tried removing '/usr2/xyz/.cache/clang/ModuleCache', but did not work. Please help in resolving this issue.

Unable to cross-compile Swift code on linux

When I try compile a swift code on linux (in my x64 machine), with the command swift build -c release --arch arm64 I am getting this error:
<unknown>:0: error: could not find module '_Concurrency' for target 'arm64-unknown-linux-gnu'; found: x86_64-unknown-linux-gnu, at: /home/kleber-manjaro/swift-5.5.2-RELEASE-ubuntu20.04/usr/lib/swift/linux/_Concurrency.swiftmodule
Anyone can tell me what is causing this and how to fix it?

'React/RCTBridgeModule.h' file not found #import <React/RCTBridgeModule.h>

When I am trying to make XCFramework from the famous command line, I am facing the below error:
#import "Headers/private_framework.h"
^
../private_framework.h:9:9: error: 'React/RCTBridgeModule.h' file not found
#import <React/RCTBridgeModule.h>
<unknown>:0: error: could not build Objective-C module 'private_framework'
** BUILD FAILED **
The following build commands failed:
CompileSwift normal arm64
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
My private framework project has react-native dependencies. I am on Xcode 12.4. I have already tried the below steps:
Deleted derived data and clean build.
Deintegrated pods and did pod install.
Using the latest cocoa pod version.
sudo Xcode-select --reset.

Errors when running unit tests in Kitura

I am new to the Kitura and Xcode and facing some issues when adding test files.
It seems to be related to the #testing directive.
I have setup the same as shown on Kitura website.
When I invoke in the console swift build then swift test I get following error:
Compile Swift Module 'testTests' (1 sources)
Linking ./.build/debug/testPackageTests.xctest/Contents/MacOS/testPackageTests
Undefined symbols for architecture x86_64:
"__TFC4test3OkoCfT_S0_", referenced from:
__TFC9testTests8OkoTests8test_addfT_T_ in OkoTests.swift.o
"__TMaC4test3Oko", referenced from:
__TFC9testTests8OkoTests8test_addfT_T_ in OkoTests.swift.o
ld: symbol(s) not found for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/*user*/Projects/Kitura/test/.build/debug.yaml test
However when I comment out line #testable import test and type swift build then swift test then I get following error:
Compile Swift Module 'testTests' (1 sources)
/Users/*user*/Projects/Kitura/test/Tests/testTests/OkoTests.swift:6:17: error: use of unresolved identifier 'Oko'
let o = Oko()
^~~
<unknown>:0: warning: 'cacheParamsComputed' is deprecated
<unknown>:0: warning: 'cacheAlphaComputed' is deprecated
<unknown>:0: warning: 'keepCacheWindow' is deprecated
<unknown>:0: error: 'memoryless' is unavailable
Metal.MTLCommandBufferError:19:14: note: 'memoryless' has been explicitly marked unavailable here
case memoryless
^
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/*user*/Projects/Kitura/test/.build/debug.yaml test
When I try to test it from Xcode generated project instead (swift package generate-xcodeproj) then I get compile error:
Without Testing files, everything works properly.
Below I present project structure:
I believe the issue is that Swift is not able to compile unit tests for modules that contain a main.swift file (i.e., modules that are meant to be compiled into executables as opposed to libraries for use in other projects). I cloned your repo and was able to compile and run unit tests after 1) removing main.swift and 2) uncommenting the testable import statement.

Swift compile error: "cannot load underlying module for 'CoreGraphics'" with `import Foundation`

With Swift DEVELOPMENT-SNAPSHOT-2016-02-08-a, I'm trying to build a project using swift build but as soon as I add the line import Foundation I get the error:
[I] ~/Dropbox/Projects/test
↪ swift build --clean; and swift build
Compiling Swift Module 'test' (1 sources)
<unknown>:0: error: cannot load underlying module for 'CoreGraphics'
<unknown>:0: note: did you forget to set an SDK using -sdk or SDKROOT?
<unknown>:0: note: use "xcrun -sdk macosx swiftc" to select the default OS X SDK installed with Xcode
<unknown>:0: error: build had 1 command failures
error: exit(1): ["/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/bin/swift-build-tool", "-f", "/Users/me/Dropbox/Projects/test/.build/debug/test.o/llbuild.yaml"]
Running xcrun -sdk macosx results in "no such SDK: 'machos'" error:
↪ xcrun -sdk macosx swift build 0#10:34:03
<unknown>:0: warning: no such SDK: 'macosx'
<unknown>:0: warning: no such sysroot directory: 'macosx'
<unknown>:0: error: cannot load underlying module for 'Darwin'
error: exit(1): ["/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/bin/swiftc", "--driver-mode=swift", "-I", "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/lib/swift/pm", "-L", "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-02-08-a.xctoolchain/usr/lib/swift/pm", "-lPackageDescription", "-target", "x86_64-apple-macosx10.10", "/Users/me/Dropbox/Projects/test/Package.swift"]
This is with only main.swift, whose contents are:
import Foundation
print("Hello, world!")
No dependencies are defined in Packages.swift.
Really don't know what's going on here. This compiles fine on my Ubuntu 14.04 DigitalOcean VPS as well as within Xcode 7.3 Beta 5.
OS X 10.11.3
↪ swift --version 0#10:21:16
Apple Swift version 3.0-dev (LLVM a7663bb722, Clang 4ca3c7fa28, Swift 1c2f40e246)
Target: x86_64-apple-macosx10.9
Do you have the stable release of Xcode.app in your [/Applications] directory? If you just have Xcode-beta.app, that's likely what's causing this error. Try creating a symlink of Xcode-beta.app to Xcode.app:
$ ln -s /Applications/Xcode-beta.app /Applications/Xcode.app
(Kudos to anton for the answer).