SFML community forums

Help => General => Topic started by: Haikarainen on December 10, 2011, 11:52:19 pm

Title: What is that "SFML_API" I'm seing in every class d
Post by: Haikarainen on December 10, 2011, 11:52:19 pm
This question isn't directly related to SFML as I've seen it elsewhere, but it sure is related to C++.

So what is that SFML_API I see in every class definition anyway? I've tried to find a term about what it is, and what it might do, but with no luck. Not even the most advanced tutorials out there brings this up.

Tried googleing, scavenging general c++ tutorials, getting clues by trying to get compiler errors. But nothing.

I'm really curious about this, and been for a long while, Want to know how I can use this for my own good.
Title: What is that "SFML_API" I'm seing in every class d
Post by: Laurent on December 10, 2011, 11:59:34 pm
When building a shared library, you must (Windows) / can (Linux) decide which classes/functions/variables are exported, and which are not. For example, on Windows, you must use the __declspec(dllexport) keyword in front of everything that you want to export. But when you want to use the compiled library, you have to use a different keyword, __declspec(dllimport), because you import the class/function/variables from the DLL.

So, as the keyword can change according to the platform, and according to whether you build or use the library, it's hidden behind a macro. All the magic stuff with lots of preprocessor expressions is done in the definition of the macro.