This is probably just caused by me lacking c++/cli knowledge, but I can't seem to find this question asked anywhere.
I have a project called ManagedProject that is compiled with /CLR and has a (c++/cli) ref class called RefClass.cpp, and a native C++ class called CppClass.cpp.
I am able to call the constructor of CppClass from RefClass.
However, I am unable to call CppClass from a separate project "OtherProject" that is also compiled with /clr. OtherProject only has Other.cpp. OtherProject has a Reference to ManagedProject so I am able to call RefClass, but even though I am able to #include "CppClass.h", I get LNK2019 AND LNK2028 errors when I try to call CppClass's constructor.
I get the same errors when calling it from a non-/clr native class.
Here is a code sample:
ManagedProject
RefClass.cpp:
// has a .h file with the constructor declaration & instance variable int test;
#include "CppClass.cpp"
RefClass:RefClass(int test){
this->test = test;
CppClass inst(42); //This works
}
CppClass.cpp:
// has a .h file with the constructor declaration & instance variable int test2;
CppClass:CppClass(int test2){
this->test2 = test2;
}
OtherProject
Other.cpp:
#include "CppClass.cpp"
int wmain(/*args*/){
RefClass^ refinst = gcnew RefClass(64); //This works
CppClass inst(42); //This fails, I get LNK2019 & LNK2028 at Other.obj
}
Actual error output: Note: here SQLPrecheckReport is CppClass, and appzsqlmigrate.cpp is Other.cpp, appzsqlmigrate is the name of OtherProject.
32>appzsqlmigrate.obj : error LNK2028: unresolved token (0A000B59) "public: __cdecl SQLPrecheckReport::SQLPrecheckReport(int)" (??0SQLPrecheckReport@@$$FQEAA@H@Z) referenced in function "int __cdecl wmain(int,wchar_t * * const)" (?wmain@@$$HYAHHQEAPEA_W@Z)
32>appzsqlmigrate.obj : error LNK2028: unresolved token (0A000B5A) "public: __cdecl SQLPrecheckReport::~SQLPrecheckReport(void)" (??1SQLPrecheckReport@@$$FQEAA@XZ) referenced in function "int __cdecl wmain(int,wchar_t * * const)" (?wmain@@$$HYAHHQEAPEA_W@Z)
32>appzsqlmigrate.obj : error LNK2019: unresolved external symbol "public: __cdecl SQLPrecheckReport::SQLPrecheckReport(int)" (??0SQLPrecheckReport@@$$FQEAA@H@Z) referenced in function "int __cdecl wmain(int,wchar_t * * const)" (?wmain@@$$HYAHHQEAPEA_W@Z)
32>appzsqlmigrate.obj : error LNK2019: unresolved external symbol "public: __cdecl SQLPrecheckReport::~SQLPrecheckReport(void)" (??1SQLPrecheckReport@@$$FQEAA@XZ) referenced in function "int __cdecl wmain(int,wchar_t * * const)" (?wmain@@$$HYAHHQEAPEA_W@Z)