标题保护

时间:2016-10-04 11:41:06

标签: c++ dll compilation header linker

我现在正试图让我的游戏引擎工作模块化,为此我想将不同的模块编译成.dll文件,然后在我的解决方案中包含它们所需的每一个。 我已经将每个项目/模块的include目录定义为解决方案目录,这样我就可以说#include <Module/Header.h> dll应该编译并直接进入我的解决方案调试文件夹。 但由于某种原因我得到这些错误,即使我在每个标题中都有标题(当然),我不知道问题是什么。

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   

这里是我的核心和我的相机类的一个例子。

#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;
}

0 个答案:

没有答案