Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved Externals when using source code from another folder

Tags:

c++

I'll explain my problem as best as possible.

Basically i have two projects in one visual studio 2010 solution. One project is the source code for a game engine that i'm making, and it compiles into a .dll. The second project just contains the main.cpp file which includes files from the Engine project. I've setup the test project to include the Engine project's source directiry (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 would look like

Graphics.h

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

Graphics.cpp

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

The source for the engine as mentioned above is in a separate folder to main.cpp. I've tried putting all the code into main.cpp's folder and i can compile with no problems. Having it in another folder causes the unresolved externals for the functions i use in main.cpp.

Thanks for any help!

like image 980
rocklobster Avatar asked Feb 14 '26 04:02

rocklobster


1 Answers

First you need to export the symbols via _declspec(dllexport).

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

When you import the header, you tell it to import the symbols with _declspec(dllimport). This dual functionality can be achieved with macros.

Second, you need to include the generated .lib file in the project settings of the project that contains main.cpp.

like image 102
Luchian Grigore Avatar answered Feb 15 '26 16:02

Luchian Grigore