PDA

View Full Version : dll from VS



nbo10
November 6th, 2007, 10:56 PM
A while back I wrote a little dll, in c++, with microsoft visual studio. The dll called a c function in another library. I used this dll to call the c function from c# programs. Now I want to use this dll in a c++ program under linux. Can I do this and if so how do I do this? Thanks

Wybiral
November 6th, 2007, 11:52 PM
I don't think you can. Linux uses a different different dynamic library format and since it was compiled in VS it's likely the machine code wouldn't even be compatible.

nbo10
November 7th, 2007, 04:37 PM
Is there a way I can recompile it into something usefull for linux? I can also recomplie it on a Sun station under unix if that would help me out. Thanks

dashnak
November 7th, 2007, 04:42 PM
You could try something with the mono project:
www.mono-project.com/

nbo10
November 7th, 2007, 04:55 PM
I don't want to use .net.

pmasiar
November 7th, 2007, 08:06 PM
You could try something with the mono project:
www.mono-project.com/

Don't mind this advice - it is just another example how misleading advice here can be.

dashnak did not bothered to explain hos mono, written in C#, could be helpful to compile C++ .DLL.

I am not expert, but IIRC mingw or something is compatibility library between Linux and Windows. As all these efforts, it is far from perfect: it is hard to make systems compatible if profits of MSFT are based on being incompatible :-)

IMHO you are experiencing a case of vendor lock-in. maybe this lesson will teach you to avoid it next time... :-)

DMills
November 7th, 2007, 09:18 PM
Ok, so you have a dll written in C++, first question:

Is it really straight C++ without any compiler specific extensions?
If so, you should be able to compile it to an object file with something like:


g++ -W -Wall -g -c dll.cpp -odll.o

If that works then just use the normal process for linking a shared library (google for it, this is too long already).

Now, in all probability that will fail with many pages of error messages, all that __DLLSPEC__ and stdcall cruft is unnecessary under Linux, some suitable #defines will get rid of it for you, but now comes the interesting bit, any use of Microsoft specific functions and classes will have to be revised to use either standard C++ or the Posix (or even Linux specific) equivalents.

Some things have no direct equivalent, because the whole architecture is so different, WaitForMultipleObjects for example is a pain in the **** to implement under Linux, and obviously all the MFC stuff is missing.

There **MIGHT** be an easier (If horribly clunky) way....
The WINE project has a library that can load (and provide linux native access to) windows DLLs on X86 hardware, and it even sometimes works, but it is a fairly hideous way to do such things.

Note that DLLs and ELF shared libraries have rather different run time symbol resolution behaviour and while this is unlikely to bite you for something simple, it can be a problem if doing anything hairy.

Regards, Dan.