views:

110

answers:

1

I have a solution created using visual studio 2008 named, "Solution", and i have two projects in that solution, project "A" and project "B". when i do a thing like below it shows fatal errors in the bottom. I have given in project A->properties->Additional include Directries as ../B

project B

B.h

#include <iostream>

using namespace std;
class B
{
public:
    B();
    ~B();
};

B.cpp

#include "B.h"

B::B()
{

}

B::~B()
{

}

project A

A.h

#include <iostream>

using namespace std;
class A
{
public:
    A();
    ~A();
};

A.cpp

#include "A.h"
#include "B.h"
A::A()
{
    B b;
}

A::~A()
{

}

Main.cpp in project A

#include "B.h"

int main()
{
    B b;
    system("pause");
}

when i run it says

Error 3 fatal error LNK1120: 2 unresolved externals H:\Sol\Debug\A.exe

Error 2 error LNK2001: unresolved external symbol "public: __thiscall B::B(void)" (??0B@@QAE@XZ) A.obj

Error 1 error LNK2001: unresolved external symbol "public: __thiscall B::~B(void)" (??1B@@QAE@XZ) A.obj

+1  A: 

It doesn't look like you are exporting class B out of project B. So project A sees the declaration of class B but can't find its implementation. What does project B build?

sean e
B.obj and some others
buddhi
Does project B link? Does it produce a dll? Does it produce a .lib that project A is supposed to link with? If all it produces is some .obj files, then why - what is the purpose of project B?
sean e
Thanks! i had not included obj files
buddhi
If you are manually adding obj files to the link command for project A, you may as well not even have project B (just include the source files directly in project A). Alternatively, make project B produce a static lib that project A links against.
sean e