25

Question: Is it possible to compile a program on linux using a .dll file?

Where this is going: This .dll will be used to write a php extension to some proprietary software from a third party.

Background and Research:

I have been given a library called proprietary.lib. I was curious, as I have never seen the .lib extension before, so I typed:

file proprietary.lib

The output was:

proprietary.lib:  current ar archive

I did some research and found that ar is more-or-less tar (and in fact, I guess tar has since replaced ar in most *nix environments).

Upon inspecting the ar manpage, I saw the t option, which displays a table listing of the contents of that archive. Cool. So I type:

ar t proprietary.lib

And get:

proprietary.dll
proprietary.dll
... (snip X lines) ...
random_hero
  • 253
  • 1
  • 3
  • 4
  • 5
    UNIX doesn't use DLLs. In Linux the corresponding file format is "so" (shared objects) and in Mac OS X it's "dylib" (dynamic libraries) and "bundle". – kennytm Mar 29 '10 at 14:30
  • 1
    You see, this is where the confusion comes in. From scouring comp.lang.c, it appears that "DLL" is a generic term for a library, that just so happens to be the name Windows uses for it. Is it as simple as recompiling that library into the ELF format? – random_hero Mar 29 '10 at 14:33
  • Yes it's that simple. You're beholden to the vendor of this library to get you a proper build. – Broam Mar 29 '10 at 20:24
  • 1
    @random_hero how did you deal with this type of situation ? – Lokesh Pandey Sep 29 '17 at 11:33
  • archives and dlls are totally different no idea what the question is but it's ust a bad extension. Rename it to `.ar` and double click it in linux – Evan Carroll Jan 25 '18 at 20:55
  • .lib is the common extension for Windows static libraries. Moreover, creating a Windows DLL will create a foobar.lib, foobar.exp and foobar.dll. – John Rocha Mar 25 '21 at 22:35
  • In *nix, `.a` is for static libraries and `.so` for shared or dynamic libraries. – John Rocha Mar 25 '21 at 22:35

5 Answers5

20

Recent development may have changed the situation: There is a loadlibrary function for Linux available, that makes it possible to load a Windows DLL and then call functions within.

So, if the .dll file you have actually is a Windows DLL, you may find a way to use it in you software.

Ber
  • 40,356
  • 16
  • 72
  • 88
8

.dll files are usually Windows shared libraries. (It's also possible that somebody on Linux has built a regular Linux library and called it .dll for some reason.)

It's possible you could link against them using Wine. Support for this was once in there as experimental - I don't know its current status.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
  • 2
    There is one Project in the Python world called [zugbruecke](https://github.com/pleiszenburg/zugbruecke), which let's you access and run Windows DLL on Linux or MacOS - and internally it uses Wine, too. – miku Jun 12 '18 at 23:04
8

You could try extracting the ar file (Debian packages are ar files, fwiw) and run file on the contents.

You're not going to be able to use Windows DLLs without translation. The only DLL files that I know of that work natively on Linux are compiled with Mono.

If someone gave you a proprietary binary library to code against, you should verify it's compiled for the target architecture (nothing like trying to use am ARM binary on an x86 system) and that it's compiled for Linux.

That being said...good luck. I hate programming against third-party libraries where I have the documentation and the source.

Broam
  • 4,602
  • 1
  • 23
  • 38
  • Tried extracting and re-running file command on the sole .dll file that was produced and the output was "data". – random_hero Mar 29 '10 at 17:28
  • If it's not seen as a shared object or some sort of executable file...you're out of luck. – Broam Mar 29 '10 at 20:25
  • @Broam Hi broam, is it possible to directly compile dll files with Mono ? Or do I need to convert the DLL files into C++ code and then compile it with Mono ? – Lokesh Pandey Sep 29 '17 at 11:32
  • You cannot compile using .dll files as source, as they are already compiled. – Broam Dec 11 '18 at 14:30
0

Yes We can use dll with the help of wine . just install wine64 in linux

sudo apt-get install wine64
-1

Normal DLL files are Windows' linked libraries, so they cannot run on Linux directly, however it's possible to compile DLL files specifically for Linux using .NET Core.

Sasino
  • 134
  • 2
  • 11