Unresolved Externals when using source from another folder

I will explain my problem as best I can.

Basically I have two projects in one visual studio 2010 solution. One project is the source code for the game engine I am building and it compiles to a .dll. The second project only contains the main.cpp file, which includes files from the Engine project. I have set up a test project to include the directiry of the Engine project source (headers and cpp), but I am getting unresolved externals. All my engine classes are inside a namespace.

main.cpp

#include <Engine/input.h>
#include <Engine/graphics.h>
#include <Engine/sound.h> 

using namespace Engine; 

int main()
{
    Renderer* renderer = new Renderer();
    etc.
}

      

Then in my code it will look like

Graphics.h

namespace Engine
{
    class Renderer 
    {
         void draw();
    }
}

Graphics.cpp

namespace Engine
{
    void Renderer::draw()
    {
    }
}

      

The source for the engine mentioned above is in a separate main.cpp folder. I tried to put all the code in the main.cpp folder and I can compile with no problem. The presence in another folder causes unresolved external functions for the functions that I am using in main.cpp.

Thanks for any help!

+3


source to share


2 answers


First you need to export symbols via _declspec(dllexport)

.

namespace Engine
{
    _declspec(dllexport) class Renderer 
    {
         void draw();
    }
}

      



When you import a title, you tell it to import symbols with _declspec(dllimport)

. This dual functionality can be achieved with macros.

Second, you need to include the generated file .lib

in the project settings of the project that contains main.cpp

.

+2


source


Looks like you haven't included Graphics.h in Graphics.cpp



0


source







All Articles