Execute dll files using Swift


I want to run dll files in xcode using swift, as i am new to swift I don't know how to run, so help me with this.

DLL is the Windows dynamic library format. Xcode is an IDE designed mostly for coding on Apple's platforms, which don't use DLLs. But you can use a Windows Swift toolchain on Windows, and if you have a C header that describes the DLL you're trying to use, you may be able to import that header in Swift and just link against your DLL.

Hi John_McCall,

I created console application for mac in visual studio using C#, it's creating dll files i want to execute those files using swift, is that possible?

The answer here depends on whether these “dll files” are:

  • Actual Windows DLL files

  • Mach-O shared libraries (with your Windows-focused development environment using the term DLL in a generic sense)

Calling the former from Swift on the Mac would be… well… challenging. Calling the latter is relatively straightforward.

You can distinguish these cases using file. In Terminal, run this command:

% file /path/to/your/file

What do you get back?

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

Assuming we are talking .net dlls in Mono or Xamarin, you probably want use the Mono projects Embeddinator 4000. https://github.com/mono/Embeddinator-4000


DLL files produced by .NET toolchains contain bytecode that relies on an additional runtime to execute.

@esummers is right, you need to use a tool like Embeddinator-4000 that can surface the .NET code to native code (in this case Swift) before you can use it on Mac/Linux.

For Windows, you can use a tool that is a little simpler, but imposes some limitations on what APIs can be surfaced: https://github.com/3F/DllExport


Drop everything you are doing, dotnet is not meant for console applications, as you can see it produces 200 DLLs (fake DLLs, they are IL archives for the dotnet VM) and you'll need the runtime whenever you publish the app, or move computer

Focus on Swift, you can use this library to help kickstart your console app https://github.com/apple/swift-argument-parser

If you were using dotnet for networking stuff, Swift has all you need

Terms of Service

Privacy Policy

Cookie Policy