Hello,
you must add the lib file of the dll to your project.
Regards, Guido
how to export a class pointer with a name space in vs2015?
in module A
file1.c
namespace vehicle_control {
class FusionNodeRunnable {
int speed;
}
}
file2.h
extern vehicle_control::FusionNodeRunnable _declspec(dllexport) Fusion;
file2.cpp
vehicle_control::FusionNodeRunnable _declspec(dllexport) Fusion;
in module B
pFusion is accessed during pre-compling phase, but error occured during linking, it prompts
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "class vehicle_control::FusionNodeRunnable fusion" (?fusion@@3VFusionNodeRunnable@vehicle_control@@A) Simulator_Fusion D:\WorkInHH\YCZL\imm_tracker\Simulator_Fusion_x64\Simulator_x64\Simulator_Fusion\simulator\simulator.obj 1
how to solve this problem?
3 answers
Sort by: Most helpful
-
Guido Franzke 2,196 Reputation points
2021-01-07T07:38:49.543+00:00 -
Viorel 118K Reputation points
2021-01-07T08:05:18.62+00:00 In my opinion, if module A is a Static Library, then __declspec(dllexport) is not needed.
If module A is a DLL, then __declspec(dllexport) can be used, but it must be replaced with __declspec(dllimport) when file2.h is included into module B.
This can be done with a macro. Try creating a new DLL using Visual Studio dialogs (Windows Desktop Wizard template) and select DLL type and “Export symbols” option. It will create a project with sample exported functions, data, and classes, and which uses special macros. Use Add Reference dialog in project B to add a reference to project A.
Is A a DLL or Static Library?
-
Jeanine Zhang-MSFT 9,771 Reputation points Microsoft Vendor
2021-01-08T07:01:59.833+00:00 Hi,
According to the Doc:
In C++ object files, Name decoration encodes the calling convention, class or namespace scope, and return and parameter types of a function. The encoded string becomes part of the final decorated function name. This name is used by the linker to resolve, or match, calls to the function from other object files. To fix this issue, make sure the function declaration, definition, and calls all use the same scopes, types, and calling conventions.
In the header file you're declaring the variables in the namespace. I suggest you could declare them with the extern keyword and then in a source file you do the definition.
Best Regards,
Jeanine
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.