Can u help fix: "C:\Swift\mingw64\bin\ld: cannot find C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk: Permission denied"

Hello Community, I need your help:
I want to code in VCS and copile and run the program on Swift for windows on windows 11. However I search for my file and compile it.
"C:\Swift\bin\swiftc.exe" -swift-version 4 "CORRECT\PATH\IS\HERE" -o "C:\Swift\RuntimeEnv\HelloWorld.exe"

C:\Swift\mingw64\bin\ld: cannot find C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk: Permission denied

Successfully compiled

C:\Swift\RuntimeEnv\HelloWorld.exe

And then when I press RUN it tells me "compile first" as an error message.
I tried running it as an administrator, I saved the file as a local file and not in the cloud and dont know what to do.
Pretty new and want to get into app dev and coding in general so I´d love ur help
Thank you

It looks like you used an old attempt to run swift on Windows using MinGW. I recommend first removing all Swift installations and then reinstalling Swift according to the instructions on swift.org.

The command you used (with appropriate paths in the command) should then be OK to compile a simple Swift file, but why compiling for such an old Swift version, just drop any version argument for a new Swift file which does not contain very old, nowadays incompatible code. Also, for a "real" Swift project you should use the Swift Package Manager. To edit such a project you should use Visual Studio Code with the Swift extension by the Swift server group.

So try a fresh start and read the instructions on swift.org, other instructions you might find in the internet might be outdated since a long time.

1 Like

Hey Stefan, thanks for the quick response!
I now deinstalled the "old version" of Swift and installed the newest Windows version from swift.org.
Thats actually what I tried before installing the Compiler.
My method on writing and running Swift Code is the following:
Open a new terminal, checked with swift --version the version installed:

compnerd.org Swift version 5.9 (swift-5.9-RELEASE)
Target: x86_64-unknown-windows-msvc

I think thats all right, then I create a new text File, select Swift as the language,
wrote the Hello World programm print("Hello World")

then I want to run it and it gives me not the normal "run" button in the top right corner, only a "Swift Playground Run" button, but after pressing it, it doesnt execute anything.
Running the code from the terminal with

swift HelloWorld.swift

gives me the error

:0: error: could not load the swift standard library

and thats were I switched to the Compiler, because on friends Laptop the Copiler with the older version works just fine.

If I want to Run the Code without debugging the error

unable to find executable for Swift.playground\HelloWorld.swift.exe
image

appears with the options Cancel and Open´launch.json´

the json file is:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: Debugging in Visual Studio Code
"version": "0.2.0",
"configurations": [

    {
        "type": "lldb",
        "request": "launch",
        "name": "Debug",
        "program": "Swift.playground/HelloWorld.swift",
        "args": [],
        "cwd": "Swift.playground"
    }
]

}

the Debug console says:
Console is in 'commands' mode, prefix expressions with '?'.

I am sorry for spamming but I want to get you as much information as possible

Thank you for your response!
Sorry If I am beeing stupid in some way

Calling swift HelloWorld.swift runs HelloWorld.swift as a script in the interpreter mode. To my knowledge this is not yet working on Working (you might also encounter problems with the Swift playgrounds or the REPL on Windows). According to my understanding the main focus for Swift on Windows is to get all new language features like macros working on Windows first, compare this GitHub task board for the progress on Windows.

So use swiftc HelloWorld.swift and the then run the compiled program HelloWorld.exe.

And as I said you should then use a Swift Package Manager project (initialize a new one inside a new empty folder with swift package init --type executable). If you have installed the Swift extension by the Swift Server Group in Visual Studio Code, such a project is correctly recognized (just drag the project folder into the Visual Studio Code window), i.e. the dependencies (other Swift packages referenced in Package.swift of the project) are downloaded and you can edit your code and build and run your program. There is then no need to formulate any JSON file.

Okay so I made 2 new empty folders, One called swift one called swiftpm.
Opened swift in VSC, made a new file "HelloWorld"
used swiftc HelloWorld.swift and it threw HelloWorld.exe, HelloWorld.exp and HelloWorld.lib at me.
Opened the compiled HelloWorld.exe despite the warning

It showed me an 13000 Charakter Code looking like this:
MZ��������������������@����������������������������������������� �!�L�!This program cannot be run in DOS mode.

$�������J-ϸL��L��L��a42�L��e3�� L���>�� L��L��6L��e3��L��e3��aL��e3�� L��L�� L��6̡�L��6̣�L��RichL��������������������������PE��d����(e����������"� %����:���������������@������������������������p����������������������������������������������*��H����*���������������P��\������������0����#������������������������������"��@����������� �����������������������������.text���l����������������������� ��.rdata������ ��������������������@��@.data�������@������*��������������@���.pdata��\���P������,��������������@��@.sw5prt�����������.��������������@��@.sw5prtc����p������0��������������@��@.sw5tymd�����������2��������������@��@.sw5tyrf�����������4��������������@��@.sw5rfst�����������6��������������@��@.sw5flmd�����������8��������������@��@.sw5asty�����������:��������������@��@.sw5repl�����������<��������������@��@.sw5reps�����������>��������������@��@.sw5bltn�����������@��������������@��@.

Lol

in the swiftpm folder I ran your line swift package init --type executable and as you said with my swift extension by the swift server group it recognized the project.

Still cant Run my Hello World porgram, am I still doing something wrong?
thank you for sticking with me

Hey Stefan, my first respones was filtered due to a spam lol
I followed ur instruction and made 2 folder, one called swift and one swiftpm
in swiftpm I executed swift package init --type executable and as u said VSC recognised the the project properly.
in the swift folder i used swiftc HelloWorld.swift and got 3 new files,
HelloWorld.exe, HelloWorld.exp and HelloWorld.lib
I wanted to run .exe despite the warning

The file is not displayed in the text editor because it is either binary or uses an unsupported text encoding.

and It threw tons of code like this at me:


(cant paste the code because of spam filter)

To run this code (I know its prly wrong but still tried) it wants me to install some binary code extension (it says it is for Linux systems optimized only)
and I get this Error:
A system error occurred (ENOENT: no such file or directory, open '/PROLEAD/Report.dat')

If I want to run the main.swift from swiftpm I again get an error.

Thank you again for the quick response

Maybe you should find a person who already knows a bit more about programming and can sit together with you and help you.

1 Like

Thank You, ig thats what I am going to do

...just one more addition because otherwise you might be too frustrated maybe :wink::

We have two different (!) methods described above:

  • One is a single Swift file, compiled with swiftc. The result (the executable file HelloWorld.exe) is to be called directly via the command HelloWorld.exe inside a command line windows where you first went to the directory containing HelloWorld.exe.

  • The second method is a Swift Package Manager project, created via swift package init --type executable for a project that should be executable (i.e. is not a library). This is then built via swift package build, or for a release version (which is faster but the compiling takes longer and it cannot be debugged) via swift package build -c release. The result is an executable file (*.exe) in the subfolder .build\debug for a debug version or in .build\release for a release version. (Search how to display a so called hidden file e.g. a directory whose name starts with a dot inside a file explorer window. There is a setting in the file explorer to always show them.)

And as already mentioned Visual Studio Code (not Visual Studio, Visual Studio is just a prerequisite that has to be installed, but is not used for editing or compiling) with the mentioned extension works fine with the second case.

1 Like