1

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.

Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
Granjero
  • 340
  • 3
  • 13
  • After searching for some info on that problem, I came to the conclusion that the problem is in the reference. It might not be done right. I think this can help even more: http://msdn.microsoft.com/en-us/library/ms235590(v=vs.80).aspx – AlexSavAlexandrov Jan 12 '12 at 23:54

1 Answers1

2

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?

Steve Wellens
  • 20,506
  • 2
  • 28
  • 69
  • It's impossible to have an executable project, and another one to test it? I remember I did something like that with C#, so I tought it would be the same. – Granjero Jan 12 '12 at 22:37
  • 1
    C# supports multiple main methods with you telling the compiler which one to use (by the class name that it's in) for a specific build. C++ doesn't support that kind of thing directly, though something similar could probably be cobbled together with clever project/makefile configuration. – Michael Burr Jan 13 '12 at 00:43
  • 1
    @Granjero: You may have two executables, but you would have to use Inter-Process Communication to test one using the other. I suspect that is not what you intend however. – Sion Sheevok Jan 13 '12 at 15:12
  • No, I supose that the easiest way is to make a dll then :P – Granjero Jan 13 '12 at 23:25