Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working on a cross platform library

What are the best practices on writing a cross platform library in C++?

My development environment is Eclipse CDT on Linux, but my library should have the possibility to compile natively on Windows either (from Visual C++ for example).

Thanks.

like image 494
Alon Gubkin Avatar asked Jun 03 '10 16:06

Alon Gubkin


1 Answers

To some extent, this is going to depend on exactly what your library is meant to accomplish.

If you were developing a GUI application, for instance, you would want to focus on using a well-tested cross-platform framework such as wxWidgets.

If your library depends primarily on File IO, you would want to make sure you use an existing well-tested cross-platform filesystem abstraction library such as Boost Filesystem.

If your library is none of the above (i.e. there are no existing well-tested cross-platform frameworks for you to use), your best bet is to make sure you adhere to standard C++ as much as possible (this means don't #include <linux.h> or <windows.h>, for instance). When that isn't possible (i.e. your library reads raw sound data from a microphone), you'll want to make sure the implementation details for a given platform are sufficiently abstracted away so that you minimize the work involved in porting your library to another platform.

like image 153
Mark Rushakoff Avatar answered Oct 06 '22 01:10

Mark Rushakoff