John said:
I have a visual studio c++ project which is a dynamic dll.
It's made for windows, and has windows.h and other windows specific
headers.
I want to compile the same project for linux and for mac os.
Do you have any suggestions how to do that?
I read about some library's like wxwidgets, boost, qt and similar.
Do I have to use one of them?
Thanks in advance.
Porting, especially from Windows code (that is usually ignorant of
portability issues) is a highly non-trivial task. You simply can not
expect to find some easy drop-in replacement library that will make
Windows symbols magically work on Linux and Mac OS.
Happily for you porting a shared library is likely to be easier than
porting an application.
Despite what people here say or of your attempts already, trying to
supply all those Windows headers definitions yourself is the wrong thing
to do (and also it is not porting, it is creating an emulation layer,
again a non-trivial task).
The right thing to do is change your library project, so it uses
functions provided by standard or portable interfaces, like the standard
C library, the standard C++ library, boost library, POSIX/XSI functions,
etc, instead of the Windows ones.
In doing this you will find that you will need to include some more
portable libraries in your project. The 3 libraries you mentioned are
all very good ones indeed. As others said, many people (including me)
find boost an invaluable library to have, even if you are not porting.
Depending on how vendor-specific the previous code has been written,
this may be a difficult task. However, for a shared library, you are
still likely to be fine.
Beware that even if using standard or portable interfaces, you still
have to be careful for your resulting program to be portable. For
example getenv("PATH") will return the PATH environment variable, but if
you later parse it as a semi-colon ";" separated list of directories
than you are still off the Linux world, although getenv("PATH") is a
POSIX call. Also if you try to create a file with
ofstream("device.00:FA:9B:65:5A:F0") you are now off the Windows world
(since Windows file names may not include ":" character) even though you
would be using the standard C++ ofstream class. To generalize, file
names are not portable, even though the interfaces you use to access
files are portable.
Have fun,
Timothy Madden