C++ Cross Platform Dynamic Libraries; Linux and Windows

后端 未结 3 1883
孤街浪徒
孤街浪徒 2020-12-12 21:16

I need some help on writing cross-platform code; not an application, but a library.

I am creating a library both static and dynamic with most of the development done

3条回答
  •  情歌与酒
    2020-12-12 21:30

    You can pretty easily do it with #ifdef's. On Windows _WIN32 should be defined by the compiler (even for 64 bit), so code like

    #ifdef _WIN32
    #  define EXPORTIT __declspec( dllexport )
    #else
    #  define EXPORTIT
    #endif
    
    EXPORTIT int somefunction();
    

    should work OK for you.

提交回复
热议问题