sansub
sansub

Reputation: 73

I can't compile a solution due to "Error LNK2028: unresolved token..."

I have a dll programmed in C++, and a exe programmed in Visual C++.

I have the functions in dll declared as:

string __declspec( dllexport ) ConfigureHAT(T_STRING pathFile);

And in the exe project I include all the headers files and the dll file.

I call the function in dll:

string ret = ConfigureHAT("file.txt");

And when the executable project is compiled, it fails with the next errors:

1>HATdllTester.obj : error LNK2028: unresolved token (0A000317) "class std::basic_string,class std::allocator > __cdecl ConfigureHAT(class std::basic_string,class std::allocator >)" (?ConfigureHAT@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z) referenced in function "private: void __clrcall HATdllTester::mainWindow::buttonConfigure_Click(class System::Object ^,class System::EventArgs ^)" (?buttonConfigure_Click@mainWindow@HATdllTester@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)

1>AssemblyInfo.obj : error LNK2028: unresolved token (0A000316) "class std::basic_string,class std::allocator > __cdecl ConfigureHAT(class std::basic_string,class std::allocator >)" (?ConfigureHAT@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z) referenced in function "private: void __clrcall HATdllTester::mainWindow::buttonConfigure_Click(class System::Object ^,class System::EventArgs ^)" (?buttonConfigure_Click@mainWindow@HATdllTester@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)

1>AssemblyInfo.obj : error LNK2019: unresolved external symbol "class std::basic_string,class std::allocator > __cdecl ConfigureHAT(class std::basic_string,class std::allocator >)" (?ConfigureHAT@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z) referenced in function "private: void __clrcall HATdllTester::mainWindow::buttonConfigure_Click(class System::Object ^,class System::EventArgs ^)" (?buttonConfigure_Click@mainWindow@HATdllTester@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)

1>HATdllTester.obj : error LNK2001: unresolved external symbol "class std::basic_string,class std::allocator > __cdecl ConfigureHAT(class std::basic_string,class std::allocator >)" (?ConfigureHAT@@$$FYA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z)

Can anybody help me? I read a lot of similar messages with the same error, but no one solves my problem.

Thanks.

EDIT

Finally, I solve the problem including the .lib file generated in the dll project into Project Properties -> Linker -> Input -> Additional Dependencies.

Upvotes: 7

Views: 28813

Answers (2)

Andrei Krasutski
Andrei Krasutski

Reputation: 5257

This helped me when I changed CLR MyProjectCLR.vcxproj project file and added a link to C MyProjectC.vcxproj project

<ItemGroup>
    <ProjectReference Include=".\MyProjectC.csproj">
        <Project>{f6ead438-e6cf-4df6-b2f4-d33d533c5343}</Project>
    </ProjectReference>
</ItemGroup>

Upvotes: 0

bluish
bluish

Reputation: 27400

I'd try changing Visual Studio project configuration. Under General > Common Language Runtime Support set /clr instead of /clr:pure.

Upvotes: 3

Related Questions