Visual C ++ / CLI - CLR Class - Error LNK2020 - How to Fix?

I have a project where I have to connect to a C-based library and I was not able to access functions from C # using DLLImport. I have to use a C ++ / CLI based project to use these functions. (more to this story, but not important).

I studied C ++ over 10 years ago, so sorry if that seems naive.
Last year, I acquired several books on the implementation of C ++ / CLI, and I have some idea of ​​what is connected with this - I just delved into these books for this project. (I was a programmer for a long time).

I thought it was better to start a small example project to familiarize yourself with what will be involved in it, to make sure that I can compile, etc. I started a project using Visual Studio 2008 SP1; Visual C ++> CLR> Class Library. In the project - I want to use both managed and native from DLL. So the / clr switch is used.

I used other names in real code; but it is very, very close. (there are currently no other files or features)

Title:

//myWrapper.h
#pragma once
using namespace System;
namespace myWrapper {
  public ref class myWrappedService {
         myWrappedService();
         bool Connected(String ^user,String ^password,String ^domain);
  }
};

And the implementation has it.

//myWrapper.cpp
//This is the main DLL file
#include "stdafx.h"
#include "myWrapper.h"
using namespace System;
public ref class myWrappedService
   {
      public:
            myWrappedService() {}
            bool Connected(String ^user,String ^password,String ^domain)
            {
               //just a simple result to start - no real functionality
               bool result = false;
               return result;
            }
   };

This is code that compiles but receives linker errors.

error LNK2020: unresolved token (06000002) myWrapper.myWrappedService :: Connected

fatal error LNK1120: 1 unresolved external.

- #. , - - , CLI. ( , , , , ).

+3
2
namespace myWrapper {

. .h , - myWrapper:: myWrappedService. .cpp , , : myWrappedService. , , . Connected, .

sad_man . :: myWrappedService:: Connected(). . , .

, .h. , . .cpp , , .h. .cpp:

#include "stdafx.h"
// Note: header file removed

using namespace System;

namespace myWrapper {

    public ref class myWrappedService
    {
    public:
        myWrappedService() {}
        void Connect(String ^user, String ^password, String ^domain)
        {
            throw gcnew NotImplementedException;
        }
    };
}
+4

cpp . cpp . ++/Cli cpp. cpp - .

:

//myWrapper.h
#pragma once
#include "stdafx.h"
using namespace System;
namespace myWrapper {
  public ref class myWrappedService {
         myWrappedService();
         bool Connected(String ^user,String ^password,String ^domain);
  }
};

//myWrapper.cpp
//This is the main DLL file
#include "stdafx.h"
#include "myWrapper.h"
using namespace System;
namespace myWrapper
{
  myWrappedService::myWrappedService() {}
  bool myWrappedService::Connected(String ^user,String ^password,String ^domain)
  {
      bool result = false;
      return result;
  }
} 

( ):

//myWrapper.h
//This is the main DLL file
#include "myWrapper.h"
using namespace System;
namespace myWrapper
{
public ref class myWrappedService
   {
      public:
            myWrappedService() {}
            bool Connected(String ^user,String ^password,String ^domain)
            {
               //just a simple result to start - no real functionality
               bool result = false;
               return result;
            }
   };
}
   // Remember? this was your cpp.

EDIT: . , , cpp .

+2

All Articles