3

我正在开发一个项目(跨平台,但在这种情况下只有 Windows 很重要),它创建了许多共享库(它们在某种程度上相互依赖)。所有声明函数或结构/类/枚举/等的头文件。可以在单独的 /include 文件夹中找到,但源文件被分组到模块中。

我为 _declspec 导入/导出创建了一个宏,但我的问题是:

我应该有一个不同的预处理器指令来触发每个库的导出版本吗?由于库可以使用属于其他库的标头,因此将这些符号视为导入重要吗?

从我在模拟项目中测试的结果来看,您可以将它们全部作为导出符号,它们仍然可以工作,但这是一种好的做法吗?

谢谢你。

4

1 回答 1

0

you should create a macro to declare export on class/function you wish to export out from your library. all include headers (of your dependency) should be declared as Import. i don't follow you how exporting all everytime is working for you (it shouldn't).

here is an example -

on the 1st library define in the .h file. in the project file define a preprocessor __your_module_name>_DLL__

library 1 header file:

#ifdef __<your_module_name>_DLL__
#define <your_module_name>_EXPORT __declspec(dllexport)
#else
#define <your_module_name>_EXPORT __declspec(dllimport)
#endif

class <your_module_name>_EXPORT someName
{
    ....
}

on 2nd library if it imports the 1st library header file and assuming __<your_module_name>_DLL__ preprocess is not define on its project file, the someName class will be imported rather than exported.

this will allow you to use the cross dependencies correctly during compilation.

于 2014-05-14T12:39:26.917 回答