I keep getting this error when trying to import Darwin or Foundation using command line swift.
Anyone have any ideas?
Welcome to Swift version 5.5.2-dev.
Type :help for assistance.
1> import Foundation
:5:9: note: in file included from :5::5: import "copyfile.h"
^
error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/copyfile.h:41:9: error: unknown type name 'uint32_t'
typedef uint32_t copyfile_flags_t;
^
:5:9: note: in file included from :5::5: import "copyfile.h"
^
error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/copyfile.h:62:44: error: unknown type name 'uint32_t'
int copyfile_state_get(copyfile_state_t s, uint32_t flag, void * dst);
^
:5:9: note: in file included from :5::5: import "copyfile.h"
^
error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/copyfile.h:63:44: error: unknown type name 'uint32_t'
int copyfile_state_set(copyfile_state_t s, uint32_t flag, const void * src);
^
:30:9: note: in file included from :30::30: import "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/tgmath.h"
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/tgmath.h:13:10: note: in file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/tgmath.h:13:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/tgmath.h:13: #include <math.h>
^
/usr/local/include/math.h:29:12: note: in file included from /usr/local/include/math.h:29:/usr/local/include/math.h:29:
include <math.h>
^
error: /usr/local/include/math.h:22:12: error: '/usr/include/math.h' file not found
% xcrun swift --version
swift-driver version: 1.26.21 Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
Target: x86_64-apple-macosx12.0
And if you run swift via xcrun:
% xcrun swift
Welcome to Swift version 5.5.2-dev.
Type :help for assistance.
1> import Foundation
2> ^D
$ xcrun swift --version
swift-driver version: 1.26.21 Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
Target: x86_64-apple-macosx12.0
$ xcrun swift
Welcome to Swift version 5.5.2-dev.
Type :help for assistance.
1> import Foundation
:5:9: note: in file included from :5::5: import "copyfile.h"
^
error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/copyfile.h:41:9: error: unknown type name 'uint32_t'
typedef uint32_t copyfile_flags_t;
^
:5:9: note: in file included from :5::5: import "copyfile.h"
^
error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/copyfile.h:62:44: error: unknown type name 'uint32_t'
int copyfile_state_get(copyfile_state_t s, uint32_t flag, void * dst);
^
:5:9: note: in file included from :5::5: import "copyfile.h"
^
error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/copyfile.h:63:44: error: unknown type name 'uint32_t'
int copyfile_state_set(copyfile_state_t s, uint32_t flag, const void * src);
^
:30:9: note: in file included from :30::30: import "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/tgmath.h"
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/tgmath.h:13:10: note: in file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/tgmath.h:13:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/tgmath.h:13: #include <math.h>
^
/usr/local/include/math.h:29:12: note: in file included from /usr/local/include/math.h:29:/usr/local/include/math.h:29:
include <math.h>
^
error: /usr/local/include/math.h:22:12: error: '/usr/include/math.h' file not found
[1] The difference between macOS 12.2 and 12.2.1 doesn’t matter in this context, although you should update because the latter some some important security fixes.
$ codesign -v -v --strict --deep /Applications/Xcode.app
/Applications/Xcode.app: the code cannot be read by the verifier (file system permissions etc.)
This is surprising since I only completely reinstalled Xcode recently.
The output was too large to put on the reply. So I put it in a text
file on drop box.
Thanks. Unfortunately that shows the working case, where you ran it with sudo, and I was looking for the failing case.
I've downloaded the developer's site Xcode. Xcode-beta.app
OK, just to be clear, the non-beta versions of Xcode are available from the developer web site. It’s fine to use the beta if you like, but just don’t think that you have to use it.
How do I make swift point to this version of Xcode?
When you run a developer tool from the command-line, it ‘trampolines’ over to the tool in your currently selected Xcode. To select a specific Xcode, use xcode-select. For more on that, see its man page.
This is what I got after I switch path to the beta version of Xcode.
Not sure what the extension point errors are... Maybe I missed something?
Still getting the same error though....
Thanks
Richard
$ sudo xcode-select --switch /Users/richardlam/workDev/Xcode-beta.app
Password:
(base) [richardlam@RLMacBook-Pro-2018 workDev]$ swift
2022-03-09 09:49:46.364 xcodebuild[45517:1960526] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
2022-03-09 09:49:46.364 xcodebuild[45517:1960526] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
2022-03-09 09:49:47.665 xcodebuild[45518:1960554] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
2022-03-09 09:49:47.665 xcodebuild[45518:1960554] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
Apple Swift version 5.6 (swiftlang-5.6.0.323.60 clang-1316.0.20.8)
Target: x86_64-apple-macosx12.0
Welcome to Swift!
Subcommands:
swift build Build Swift packages
swift package Create and work on packages
swift run Run a program from a package
swift test Run package tests
swift repl Experiment with Swift code interactively (default)
Use swift --help for descriptions of available options and flags.
Use swift help <subcommand> for more information about a subcommand.
Welcome to Apple Swift version 5.6 (swiftlang-5.6.0.323.60 clang-1316.0.20.8).
Type :help for assistance.
1> import Darwin
expression failed to parse:
:5:9: note: in file included from :5::5: import "copyfile.h"
^
error: /Users/richardlam/workDev/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/copyfile.h:41:9: error: unknown type name 'uint32_t'
typedef uint32_t copyfile_flags_t;
^
:5:9: note: in file included from :5::5: import "copyfile.h"
^
error: /Users/richardlam/workDev/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/copyfile.h:62:44: error: unknown type name 'uint32_t'
int copyfile_state_get(copyfile_state_t s, uint32_t flag, void * dst);
^
:5:9: note: in file included from :5::5: import "copyfile.h"
^
error: /Users/richardlam/workDev/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/copyfile.h:63:44: error: unknown type name 'uint32_t'
int copyfile_state_set(copyfile_state_t s, uint32_t flag, const void * src);
^
:30:9: note: in file included from :30::30: import "/Users/richardlam/workDev/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/tgmath.h"
^
/Users/richardlam/workDev/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/tgmath.h:13:10: note: in file included from /Users/richardlam/workDev/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/tgmath.h:13:/Users/richardlam/workDev/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/tgmath.h:13: #include <math.h>
^
/usr/local/include/math.h:29:12: note: in file included from /usr/local/include/math.h:29:/usr/local/include/math.h:29:
include <math.h>
^
error: /usr/local/include/math.h:22:12: error: '/usr/include/math.h' file not found
Wow, that’s quite weird. If you launch the Xcode app and then create a new project from the macOS > Command Line Tool target, are you about to build, run, and debug that?
Does your Mac have SIP enabled? You can test that with the following command:
% csrutil status
System Integrity Protection status: enabled.
Wow, that’s quite weird. If you launch the Xcode app and then create a new project from the macOS > Command Line Tool target, are you about to build, run, and debug that?
I can build, run and debug it with no problem. Everything works using the Xcode app.
It's only when I run swift on the command line that I have issues.
% csrutil status
I get the following:
[richardlam@RLMacBook-Pro-2018 workDev]$ csrutil status
System Integrity Protection status: enabled.
It's only when I run swift on the command line that I have issues.
OK.
Do you have system-like headers installed in /usr/local/include? Looking at the log output you posted [1], I see paths like /usr/local/include/math.h. Does that file exist? If so, it’s possible that it’s messing up the C importer.
If you do have such files, temporarily move the whole /usr/local/include directory aside and see if that improves things.
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple
[1] Again, if you surround text with triple backquote delimiters, that’ll make it render nicely.
Moving /usr/local/include seems to fix it. Thanks
However I'm not sure what was using the /usr/local/include.
It must have been something else I installed. What's the best practice for these header files?
I might run into problems once I start using something else which uses these header files.
Do you have Homebrew installed? Unless you are using a non-standard location, /usr/local/include is where Homebrew installs packages. It is searched first before /usr/include, so if a Homebrew package installed its own version of the C std headers (math.h, stdio.h, etc.), then they will take precedence over the system header files and cause the problems you've having. /usr/local/include is also a popular place for other packages.
I would try an experiment of renaming /usr/local/include/math.h to something else, then try running things to see if it makes a difference or if you run into other problems. It may be superflous.
It might. However, if it's a package that hasn't been updated since you last updated, you will still have the problem.
Do you know if you've installed anything else besides Homebrew packages in /usr/local? They could be culprits, too. Do you have the GCC suite installed?
Sorry. Don't know which package might be using /usr/local/include? Could be any number of things.
I do have gcc installed. I should probably reinstall it..?