I have an application that uses a third party DLL. Is there a way in Visual Studio for Mac to write an application to access it the same way as I can on windows?
-
I'm pretty sure that Visual Studio for Mac isn't going to suddenly make it possible to natively execute Windows binaries on the Macintosh. So...unless I'm misunderstanding your question, no. – Cody Gray - on strike Nov 30 '16 at 00:20
-
2You should contact the third party and ask for a Mac version of their library. – 500 - Internal Server Error Nov 30 '16 at 00:23
-
I can't verify it, but it seems likely that .NET core/standard DLLs would work – BradleyDotNET Nov 30 '16 at 00:30
-
The source code of the DLL is available, written in C (http://www.astro.com/ftp/swisseph/). Since VS-Mac is based on Mono and Xamarin as far as I know, it seems that there could be a potential that this could happen. – SteveFerg Nov 30 '16 at 00:31
-
@CodyGray isn't that precisely what something like Ionic does for JAVA and web languages? I don't think that's outside the scope of possibility at all. – sparkholiday Sep 03 '17 at 11:40
-
1No. It doesn't make *Windows binaries* execute on the Macintosh or any other platform. You would need a compiler that generated native Macintosh-compatible binaries. Microsoft doesn't make one. @spark – Cody Gray - on strike Sep 03 '17 at 11:41
-
@Cody, Ah, so it's a waaaaay lower level issue. Yeah, that doesn't seem like an issue that'll be tackled. – sparkholiday Sep 03 '17 at 11:59
2 Answers
It depends:
- Managed .NET DLL: Can be imported and used the same way as in VS on Windows
- Native DLL: can't be used directly. You'll need to build it for your target system, OSX in your case.
If you have C/C++ code you should be able to build it for OSX (with GCC for example) if it doesn't have some foreign (Windows) platform specific code. Then you can use the compiled *.so / *.dylib file directly. But you'll need to tell the .NET Runtime (Mono for example on OSX) to use the different file using a DllMap configuration file (see http://www.mono-project.com/docs/advanced/pinvoke/dllmap/ for examples).
The sources you've linked look like they're for Unix, so the chance to be able to build them on OSX are pretty good (there's a Makefile and the resulting binary would be libswe.so on Unix). You could try to pass the -dynamiclib
parameter to GCC to get a OSX specific libswe.dylib (What are the differences between .so and .dylib on osx? seems to be a good answer about dylib)
If you have the binary of your DLL for OSX, you just need a configuration file for your .NET application, which could look like this:
<configuration>
<dllmap os="osx" dll="libswe.dll" target="libswe.dylib"/>
<configuration/>
It tells the .NET Runtime to import the symbols from libswe.dylib
instead of libswe.dll
if the current OS is OSX.

- 1
- 1

- 141
- 5
No.
Although you might think that because you have an IDE with the same name as the Windows counterpart the binaries it produces are not transferable.
An answer on Super User gives some more information:
There's no real DLLs in OS X, Linux, or any POSIX for that matter. They don't make the differentiation.
Why?
A lot of Mac stuff, for one, is self-contained (.app's are really just folders after all).
Although...
Another queston on SO asks the same thing, and an answer says:
Finally Microsoft released .NET Core which is completely platform independent.
... now .NET applications can be developed on Mac or Linux machine using the lightweight IDE Visual Studio Code and Visual Studio for Mac IDE has been released where Mono on MacOS X is integrated.
So if the supplier of the library (DLL) you want to use has created a version of it with the .NET Core framework, you might be in luck.