Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include only certain libraries on an operating system

When writing an app that one wants to have compile on mac, linux and windows, what is the best way of managing the different libraries that will need to be included on the various operating systems. For example, using the glut opengl toolkit requires different includes on each operating system.

like image 409
Paul Wicks Avatar asked May 06 '26 09:05

Paul Wicks


2 Answers

Your question is actually two questions in one:

1) How do I write my C++ code to include the right include files on the right platform?

2) How do I write my Makefile to work on different platforms?

The C++ code question is already answered - find the platform-specific defines and use them to figure out what platform you're on.

Automake or scons are quite complex, and are worth your time only if you intend to release your code to a wide audience. In the case of in-house code, a "generic" makefile with per-platform include is usually sufficient. For Windows, you can get GNU Make for Windows (available from here, or use nmake and limit yourself to the subset of syntax common between all platforms.

If you just need to worry about header files, then the preprocessor will do everything you need. If you want to handle differing source files, and possibly different libraries you'll need a tool to handle it.

Some options include:

  • The Autotools
  • Scons
  • CMake

My personal favorite is CMake. The Autotools uses a multi-stage process that's relatively easy to break, and scons just feels weird to me. Cmake will also generate project files for a variety of IDEs, in addition to makefiles.

like image 22
Branan Avatar answered May 07 '26 22:05

Branan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!