0

I am right now trying to make my game engine work modular and for that i want to compile the different modules to .dll files and then include each whereever it is needed in my solution. I have defined the include directory for each project/module as the solution directory so that i can say #include <Module/Header.h> The dlls should compile and go directly into my solution debug folder. But for some reason i get these errors even though i have headerguards in every header (of course) and i cant tell what the problem is.

Error   LNK1120 8 unresolved externals  Run C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Debug\Run.exe 1   
Error   LNK2005 "public: static enum ProgramState Core::state" (?state@Core@@2W4ProgramState@@A) already defined in Camera.obj  Graphic C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Graphic\dllmain.obj   1   
Error   LNK2005 "public: static enum ProgramState Core::state" (?state@Core@@2W4ProgramState@@A) already defined in Camera.obj  Graphic C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Graphic\Graphic.obj   1   
Error   LNK2005 "public: static enum ProgramState Core::state" (?state@Core@@2W4ProgramState@@A) already defined in Camera.obj  Graphic C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Graphic\Model.obj 1   
Error   LNK2005 "public: static enum ProgramState Core::state" (?state@Core@@2W4ProgramState@@A) already defined in Camera.obj  Graphic C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Graphic\ShaderProgram.obj 1   
Error   LNK2005 "public: static enum ProgramState Core::state" (?state@Core@@2W4ProgramState@@A) already defined in Camera.obj  Graphic C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Graphic\stdafx.obj    1   
Error   LNK2005 "public: static enum ProgramState Core::state" (?state@Core@@2W4ProgramState@@A) already defined in Camera.obj  Graphic C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Graphic\Window.obj    1   
Error   LNK2019 unresolved external symbol "public: static void __cdecl Log::error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,bool)" (?error@Log@@SAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z) referenced in function "public: static void __cdecl Graphic::initGraphics(void)" (?initGraphics@Graphic@@SAXXZ)   Graphic C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Graphic\Graphic.obj   1   
Error   LNK2001 unresolved external symbol "public: static void __cdecl Log::error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,bool)" (?error@Log@@SAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N@Z)   Graphic C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Graphic\ShaderProgram.obj 1   
Error   LNK2001 unresolved external symbol "public: static unsigned int Time::programMS" (?programMS@Time@@2IA) Graphic C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Graphic\Graphic.obj   1   
Error   LNK2019 unresolved external symbol "public: __thiscall File::File(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0File@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "private: void __thiscall ShaderProgram::compileShader(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?compileShader@ShaderProgram@@AAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)    Graphic C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Graphic\ShaderProgram.obj 1   
Error   LNK2019 unresolved external symbol "public: void __thiscall File::read(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &)" (?read@File@@QAEXAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "private: void __thiscall ShaderProgram::compileShader(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?compileShader@ShaderProgram@@AAEXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)    Graphic C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Graphic\ShaderProgram.obj 1   
Error   LNK1120 4 unresolved externals  Graphic C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Debug\Graphic.dll 1   
Error   LNK2005 "public: static enum ProgramState Core::state" (?state@Core@@2W4ProgramState@@A) already defined in main.obj    Run C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Run\stdafx.obj    1   
Error   LNK2019 unresolved external symbol "public: __thiscall Model::Mesh::Mesh(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Mesh@Model@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _SDL_main   Run C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Run\main.obj  1   
Error   LNK2019 unresolved external symbol "public: __thiscall Model::Mesh::~Mesh(void)" (??1Mesh@Model@@QAE@XZ) referenced in function _SDL_main   Run C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Run\main.obj  1   
Error   LNK2019 unresolved external symbol "public: static void __cdecl Graphic::initGraphics(void)" (?initGraphics@Graphic@@SAXXZ) referenced in function _SDL_main    Run C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Run\main.obj  1   
Error   LNK2019 unresolved external symbol "public: static void __cdecl Graphic::initializeShaders(void)" (?initializeShaders@Graphic@@SAXXZ) referenced in function _SDL_main  Run C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Run\main.obj  1   
Error   LNK2019 unresolved external symbol "public: static void __cdecl Graphic::prepareRender(void)" (?prepareRender@Graphic@@SAXXZ) referenced in function _SDL_main  Run C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Run\main.obj  1   
Error   LNK2019 unresolved external symbol "public: static void __cdecl Graphic::quitRender(void)" (?quitRender@Graphic@@SAXXZ) referenced in function _SDL_main    Run C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Run\main.obj  1   
Error   LNK2019 unresolved external symbol "public: static void __cdecl Graphic::render(class Model::Mesh &)" (?render@Graphic@@SAXAAVMesh@Model@@@Z) referenced in function _SDL_main  Run C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Run\main.obj  1   
Error   LNK2001 unresolved external symbol "public: static struct SDL_Window * Window::window" (?window@Window@@2PAUSDL_Window@@A)  Run C:\Users\Linus\Documents\Visual Studio 2015\Projects\Solution\Run\main.obj  1   

here an example of my core and my camera class.

#if !defined CORE_H
#define CORE_H
#include "Time.h"
#include "stdafx.h"

enum class ProgramState {
    RUN,
    EXIT
};

class Core {
public:
    Core();
    static ProgramState state;
};

ProgramState Core::state = ProgramState::RUN;

#endif //CORE_H

#if !defined CAMERA_H
#define CAMERA_H
#include <windows.h>
#include <SDL\SDL.h>
#include <GL\glew.h>
#include <GLM\glm.hpp>
#include <Utility\Utility.h>
#include <Core\Core.h>



class Camera
{
public:
    Camera();
    ~Camera();

    static void setPosition(glm::vec3 Position);
    static void move(glm::vec3 Position);
    static void look(glm::vec3 direction);

    static glm::mat4 camMatrix() {
        cameraMatrix = projection * view; 
        return cameraMatrix; }

private:
    static glm::vec3 position;
    static glm::vec3 lookAt;
    const static glm::vec3 UP;

    static glm::mat4 projection;
    static glm::mat4 view;

    static glm::mat4 cameraMatrix;
};
#endif //CAMERA_H

#include "Camera.h"
#include "Window.h"
#include "Graphic.h"
#include <GLM/gtc/matrix_transform.hpp>
#include <GLM/gtx/transform.hpp>


glm::vec3 Camera::position = glm::vec3(0.0f, 0.0f, 0.0f);;
glm::vec3 Camera::lookAt = glm::vec3(0.0f, 0.0f, -1.0f);;
const glm::vec3 Camera::UP = glm::vec3(0.0f, 1.0f, 0.0f);
glm::mat4 Camera::projection = glm::perspective(70.0f, (float)1000 / (float)700, 0.04f, 10.0f);;
glm::mat4 Camera::view = glm::lookAt(position, position + lookAt, UP);
glm::mat4 Camera::cameraMatrix;


Camera::Camera()
{

}


Camera::~Camera()
{
}

void Camera::setPosition(glm::vec3 Position)
{
    position = Position;
}

void Camera::move(glm::vec3 Position)
{
    glm::vec3 cross = glm::cross(lookAt, UP);

    if (!(cross.x == 0.0f && cross.y == 0.0f))
        cross = glm::normalize(cross);

        position.x = position.x + (lookAt.x / 80.0f*Position.x);
        position.y = position.y + (lookAt.y / 80.0f*Position.y);
        position.z = position.z + (lookAt.z / 80.0f*Position.z);

}

void Camera::look(glm::vec3 direction)
{
        projection = glm::perspective(70.0f, (float)Window::size.x / (float)Window::size.y, 0.04f, 10.0f);
        lookAt = glm::mat3(glm::rotate(-direction.x/60.0f, UP))*lookAt;
        lookAt = glm::mat3(glm::rotate(direction.y/60.0f, glm::cross(lookAt, UP)))*lookAt;
        view = glm::lookAt(position, position + lookAt, UP);
        //if (!(lookAt.x == 0.0f && lookAt.y == 0.0f))
        //  lookAt = glm::normalize(lookAt);
        cameraMatrix = projection * view;
}
stimulate
  • 1,199
  • 1
  • 11
  • 30
  • I think it's impossible for us to know what you did wrong unless we get a [mcve] – AndyG Oct 04 '16 at 11:45
  • The line `ProgramState Core::state = ProgramState::RUN;` is a definition and must be placed in a .cpp file, not a .h file. This is causing your LNK2005 errors. As for the 'unresolved external symbol' errors, they could be due to not configuring your project to link the necessary .lib/.dll files, or when compiling those libraries, failing to use [`__declspec(dllexport)`](https://msdn.microsoft.com/en-us/library/3y1sfaz2.aspx). – David Scarlett Oct 04 '16 at 12:01
  • Thanks, i once heard it doesnt matter where you put the static definitions but thanks for clearing that up. now i added all my modules .dll files to the additional dependencies line in the project´s properties and i get the error "LNK1107 invalid or corrupt file: cannot read at 0x350" with the file Utility.dll. Weird because Core.dll seems to work. – stimulate Oct 04 '16 at 12:27

0 Answers0