最终,我希望最终得到一组源文件,这些源文件可以根据编译平台的不同而编译为Windows或Linux动态库。
问题似乎是Windows要求对标头文件声明和源文件定义都进行注释。 DLL Tutorial For Beginners
Linux动态链接库似乎仅在源文件定义中需要注释。
我可以#define预处理程序字符串以处理源代码定义的差异。
#if (_MSC_VER >= 1900) // (Visual Studio 2015 version 14.0)
#define EXPORTED __declspec(dllexport)
#else
#define EXPORTED __attribute__((visibility("default")))
#endif
Windows和Linux都忽略空的#define语句。
答案 0 :(得分:0)
您可能无法在Windows中使用注释。您可以使用DEF文件声明导出功能.def files C/C++ DLLs
对于Linux,您需要使用注释,例如:
int
#ifdef __GNUC__
__attribute__((visibility("default")))
#endif
myfunction(int param) {
return 0;
}
答案 1 :(得分:0)
这解决了Windows需要功能的问题 DLL标头和DLL源文件中的注释 而Linux只需要将LIB源函数 带注释的。 Windows和Linux都忽略空的#define 声明。
//
// Dynamic Link Library for Linux and Windows
//
// If not >= Visual Studio 2015 (version 14.0) then
// Linux is assumed
//
// This file is inlcluded in all of the LIB/DLL Source
// and the LIB/DLL caller.
//
#if (_MSC_VER >= 1900) // (Visual Studio 2015 version 14.0)
// Windows Function Definition (LIB/DLL Source)
#define EXPORTED_DEF __declspec(dllexport)
// DLL_EXPORT is defined at top of LIB/DLL Source of exported functions
#if defined DLL_EXPORT
// Windows Function Declaration (DLL Header)
#define EXPORTED_DEC __declspec(dllexport) // DLL Export
#else
// Windows Function Declaration (Caller Header)
#define EXPORTED_DEC __declspec(dllimport) // DLL Import
#endif
#else
// Linux Function definition (LIB/DLL Source)
#define EXPORTED_DEF __attribute__((visibility("default")))
#define EXPORTED_DEC // Linux cannot see this
#endif