Note that there are some explanatory texts on larger screens.

plurals
  1. POManaged C++ unresolved token
    primarykey
    data
    text
    <p>I'm new to managed C++.</p> <p>I have two managed C++ projects in a single .sln, Project Lib and Project LibTest. LibTest makes use of Lib.</p> <p>Lib compiles and links fine. The project is set as a .dll.</p> <p>LibTest is also compiled as .dll, but when it goes into linking, I get "unresolved token" on all of the Lib::methods. Those methods definitions are defined in the Lib .cpp file.</p> <p>If I moved the definitions into the Lib.h file, everything works.</p> <p>I have already modified LibTest's Reference to depend on Lib project.</p> <p>What am I missing?</p> <p><strong>EDIT</strong>: Okay here's exactly what I have and it still doesn't work.</p> <p>First off, I'm using Visual Studio 2008 SP1.</p> <p>Secondly, when I did a similar exercise in C#, it worked fine.</p> <p>I created an empty C++ CLR project. I added a Lib project. I added a managed class. VSTD generated Lib.h and Lib.cpp. The constructor is automatically generated.</p> <p>Then I added another project to my solution; I called it LibTest. I added another managed class called LibTest. LibTest.h and LibTest.cpp are generated. I tried to instantiate Lib in LibTest constructor, but during linking it simply said:</p> <p>1>LibTest.obj : error LNK2020: unresolved token (06000002) Lib::.ctor</p> <p>Here's the exact code:</p> <p><strong>Lib Project (compiled as .dll project)</strong></p> <pre><code>//Lib.h #pragma once ref class Lib { public: Lib(void); }; //Lib.cpp #include "Lib.h" Lib::Lib(void) { } </code></pre> <p><strong>LibTest Project (compiled as application.exe)</strong></p> <pre><code>// LibTest.h #pragma once ref class LibTest { public: LibTest(void); }; // LibTest.cpp #include "LibTest.h" #include "Lib.h" LibTest::LibTest(void) { Lib^ lib = gcnew Lib; } int main() { return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload