I don't think that you and those who have responded so far are looking at the same page from the same angles...
Yes, a C++ library is really just header and .cpp files.
No, a C++ library is not an OS. Everything you can do--for example, play a sound--is only doable because there exist OS functions you can call to do that. Every OS is different, and some are easier to do things with than others. The C++ libraries (like SMFL) are designed to hide all that from you and make life easier.
For example, in my "Clear the Screen" Article, I present two ways to clear the screen: one for Windows and one for POSIX (Unix, Linux, Mac OS X).
http://cplusplus.com/articles/4z18T05o/#OSSpecificWays
Obviously, if I wanted to create a library to do this stuff, the user won't want to have to do anything to it to make it compile equally easily on Windows and on Linux. It should "just work".
Making it "just work" is where all the macros and makefile stuff comes in, so that choosing to compile and link with the correct code is done automatically for the people using your library.
The comments at the end of the Article address this very issue, by saying to compile a different .cpp depending on what OS you are compiling.
http://cplusplus.com/articles/4z18T05o/#HeaderFiles
You can also use macros to identify what code to compile:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
// ClearScreen.hpp
// #include <disclaimer.h>
#ifdef _WIN32
// Windows version here
#include <windows.h>
void ClearScreen()
{
// Windows code goes here
}
#else
// POSIX version here
#include <unistd.h>
#include <term.h>
void ClearScreen()
{
// POSIX code goes here
}
#endif
|
When compiling under a Windows environment, the _WIN32 macro is automatically defined, so only the stuff on lines 5..13 get compiled. Otherwise only the stuff on lines 15..24 get compiled.
Hope this helps.