문제

I'm trying to build a solution with 2 projects and get these error messages:

ColliderTest.obj : error LNK2028: undefined token (0A000080) "public: __thiscall Rect::Rect(int)" (??0Rect@@$$FQAE@XZ) referenced in function "void __cdecl myFunction(void)" (?myFunction@@$$FYAXXZ)

ColliderTest.obj : error LNK2019: unresolved external symbol "public: __thiscall Rect::Rect(int)" (??0Rect@@$$FQAE@XZ) referenced in function "void __cdecl myFunction(void)" (?myFunction@@$$FYAXXZ)

The code:

  • In the project "Collider" I have these files:

Collider.h

#pragma once

class Rect{

    int x;
    int y;
    unsigned int w;
    unsigned int h;

public:
    Rect(int x);
};

Collider.cpp

#include "Collider.h"

Rect::Rect(int x){
    this->x = x;
}
  • The project "ColliderTest" has a reference to the project Collider, and this file:

ColliderTest.cpp

#include "../app/Collider.h"

void myFunction();

void myFunction(){

    Rect rect(4);
}

Also, each project has a main.cpp file with an empty main() function, to avoid the complains of the compiller about the entry point.

도움이 되었습니까?

해결책

Both projects have a main function?

That means you are building two executable. Executables typically do not export functions.

You need one executable and one class library (dll).

BTW: If you have an empty main function, how will you know if your program ran?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top