Managed C++ unresolved token

I'm new to managed C++.

I have two managed C++ projects in a single .sln, Project Lib and Project LibTest. LibTest makes use of Lib.

Lib compiles and links fine. The project is set as a .dll.

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.

If I moved the definitions into the Lib.h file, everything works.

I have already modified LibTest's Reference to depend on Lib project.

What am I missing?

EDIT: Okay here's exactly what I have and it still doesn't work.

First off, I'm using Visual Studio 2008 SP1.

Secondly, when I did a similar exercise in C#, it worked fine.

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.

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:

1>LibTest.obj : error LNK2020: unresolved token (06000002) Lib::.ctor

Here's the exact code:

Lib Project (compiled as .dll project)

//Lib.h
#pragma once

ref class Lib
{
public:
  Lib(void);
};


//Lib.cpp
#include "Lib.h"

Lib::Lib(void)
{
}

LibTest Project (compiled as application.exe)

// 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;
}

Managed C++ works just like C# regarding types in different assemblies. What this means is that you need to declare your Lib class as public:

public ref class Lib

And you should not include Lib.h in your LibTest project. When you add the reference to the Lib project, the compiler will be able to resolve any symbols found there.

Your current code includes Lib.h, and so the linker searches for the Lib class in the LibTest assembly and looks for the constructor there.

Linker Tools Error LNK2020, I'm new to managed C++. I have two managed C++ projects in a single .sln, Project Lib and Project LibTest. LibTest makes use of Lib. Lib compiles and links fine  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more Link errors - unresolved token/external symbol for unmanaged C++/CLI wrapper

If you're using managed extensions, setting the reference correctly should be all you need.

If you're using standard C++ functions, you probably need to define your functions using __declspec(dllexport) and __declspec(dllimport). See MSDN for details.

__declspec(dllexport) is what adds specific functions into the export library, and __declspec(dllimport) tells the importing library (LibTest) that it needs to import those symbols from the DLL.

You receive linker warnings when you build Managed Extensions , unresolved token 'token'. Similar to C++. Copy. // LNK2020.cpp // compile with: /​clr /LD ref struct A { A(int x); LNK2020 will also occur if you create a variable of a managed template type, but do not also instantiate the type. Calling C functions from a C project (shared lib) in same Visual Studio solution as my C++ class giving linker errors 0 LNK2028 unresolved token when calling WinINET from C++/CLI

In project LibTest, property->Configuration properties->Linker->Input->set Additional Dependecies, include Lib.lib

LNK2020: unresolved token, with /clr, 'unresolved external symbol "symbol" ' Managed Extensions for C++ projects that are created as DLLs by default do not link to native C/C++  I just created my first C++/CLI project (Visual Studio 2008), it's a Library to allow my C# app access an point of sale tally printer. My library builds well and trivial functions work when called from a C# exe. However as soon as I include a WinGDI call (DeleteObject in this case), the linker complains with “unresolved token” errors.

Here's the final modification as proposed by Bojan. Thanks Bojan!

Note: dont't forget to add "Lib" to your "LibTest" Reference!

Lib Project (compiled as .dll project)

//Lib.h

#pragma once

public ref class Lib
{
public:
  Lib(void);
};

//Lib.cpp

#include "Lib.h"

Lib::Lib(void)
{
}

LibTest Project (compiled as application.exe)

// LibTest.h

#pragma once

ref class LibTest
{
public:
  LibTest(void);
};

// LibTest.cpp

#include "LibTest.h"

LibTest::LibTest(void)
{
  Lib^ lib = gcnew Lib;
}

int main()
{
  return 0;
}

[Solved] VS 2008 LNK 2028 errors, Discussions on Managed Extensions for Visual C++ .NET; Updated: 3 May 2020. Another good reason to use unmanaged code is when an API is intended to be used from C++ and is too complicated and technical to be conveniently used from managed code. This project creates a C++ CLR (managed) Class Library called UnmanagedWrap which uses an unmanaged class called Unmanaged.

Managed and unmanaged C++: error LNK2020: unresolved token , Is, by chance, your project 'managed C++ '? This Stack Overflow question might help: "Managed C++ unresolved token"[^]. Managed C++ works just like C# regarding types in different assemblies. What this means is that you need to declare your Lib class as public: public ref class Lib And you should not include Lib.h in your LibTest project. When you add the reference to the Lib project, the compiler will be able to resolve any symbols found there.

Managed and unmanaged C++: error LNK2020: unresolved token, Hi, ultimately I want to call some unmanaged C++ class that contains some DirectShow code of mine from my C# classes, but for the time being  Managed C++ and C++/CLI are two different beasts. Managed C++ is a hideous extension to C++ that should never have seen the light of day. C++/CLI is officially a separate language, so new keywords can be added, and is much nicer to work with. – Eclipse Sep 22 '08 at 17:03

Undefined reference/unresolved external symbol errors in C++/C , Hi, ultimately I want to call some unmanaged C++ class that contains some DirectShow code of mine from my C# classes, but for the time being I'd be happy if I  What I have is an unmanaged C++ DLL with exported classes which references an unmanaged C++ static library. I have source for both and each is in its own project. If I now understand correctly I can use the static library as-is compiled as native and convert the DLL that references it to mixed mode by changing the classes I wish to access from

Comments
  • Wow..I must say..coming from unmanaged C++..I have ALWAYS wanted the development environment (in this case the VSTD IDE) to manage the #include, and all the library linking without me having to explicitly specify it. This is pretty amazing! I wish to tell the whole unmanaged C++ world of this! (I'm only 6 years behind! =p)
  • Thank you, Bojan; problem solved. I wish I could have voted for you 10 times..but stackoverflow only allows 1. ;-)
  • Anytime - I'm glad it helped :)