Is it possible to use the same DLL for clients using both Windows and Linux

I'm looking to create a C ++ library that can be used by both Linux and Windows clients. The special functionality of the OS will be connected by the client, implementing the interfaces provided by the library.

Can this be achieved? Do I need to recompile my C ++ project on Linux again.

PS: I am using CodeBlocks IDE


source to share

3 answers

The short answer is no, you still need to compile your library for each target platform - however, assuming your code is written in such a way that it is cross-platform, you can configure your assembly to target it as a Windows environment. and on Linux with a bit of fuss. I am now using CMake to create Visual Studio projects for Windows environments and Makefiles for Linux.



I'm pretty sure Linux won't accept .dll :) And yes, you will need to recompile. Unless you are running Windows as a virtual machine under linux that asks the question.



It certainly cannot be the same binary: shared objects. ELF format for Linux, DLL "PE" format for Windows. And dynamic loading has different semantics for both systems. See Levine link and downloader for details .

You can, if you do this, have the same source code that produces two different files (DLL on Windows, Dynamic Shared Object on Linux).

But you probably need some conditional compilation tricks like #ifdef WINDOWS


You can use libraries that provide you with a generic abstraction for such things. For example, both GTK / Glib and Qt have some mechanism to provide a general abstraction of a dynamically linked (or dynamically loaded - ie dlopen -ed) library.

You probably want to read The Program Library (at least for Linux).



All Articles