Is there any difference between class __declspec(dllexport) class_name
and __declspec(dllexport) class class_name
?
I know it seems odd. But a strange thing happened to my code. First I open my c++ Dll project in Visual Studio 2017 and add a class as usual. Compiling process is fine. But when I use another console to use my Dll, the linking process told me that unresolved external symbol referenced. What confused me most is that my new class's constructor and destructor functions are those missing symobls. Here I use the implicitly-declared default constructor and destructor.
I tried to explicit the constructor and destructor, It doesn't work and it still told me that I missed these two function.
I tried to check the calling convention. The dll and console are all set to __cdecl
and I believe that's not the reason.
I suppose there is something wrong with my "#include
". I tried, but nothing good happend.
I accidently exchange the order of the name of the class and right result came out.
Now, I'm really confused about __declspec(dllexport)
. If there is no difference between these two, how to explain this?
Note that I define the PATHPLANNINGLIB_EXPORTS
macro in the preprocessor definitions.
#ifdef PATHPLANNINGLIB_EXPORTS
#define PATHPLANNINGLIB_API __declspec(dllexport)
#else
#define PATHPLANNINGLIB_API __declspec(dllimport)
#endif
namespace CCSP_PlanningAlgorithm
{
using PathMap = std::map<SERobot*, std::vector<WayPoint>>;
//PATHPLANNINGLIB_API class MOutput //sucess declartion
class PATHPLANNINGLIB_API MOutput //failed declartion, why??
{
public:
long path_result_ID;
PathMap path_map;
};
}//CCSP_PlanningAlgorithm
I expected everything goes fine. I just use this class to save my final data result. But the linking process failed and I can't run my program.
The test console program gave me this error message:
LNK2019 无法解析的外部符号 "__declspec(dllimport) public: __cdecl CCSP_PlanningAlgorithm::MOutput::MOutput(void)" (__imp_??0MOutput@CCSP_PlanningAlgorithm@@QEAA@XZ),该符号在函数 "public: static void __cdecl MyTestCase::myStaticTest(void)" (?myStaticTest@MyTestCase@@SAXXZ)