IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Error LNK2005 && LNK4098


Sujet :

C++

  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2016
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 24
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2016
    Messages : 39
    Par défaut Error LNK2005 && LNK4098
    Bonjour

    Sous VS2015, je suis en train d'apprendre à utiliser Opengl à l'aide de glfw et de glew. Le but étant d'avoir un programme orienté objet.
    En ce moment je suis au stade de charger les shaders

    Le problème est le suivant : depuis que j'essai d'implémenter le code pour charger les shaders (qui est celui ci : http://www.opengl-tutorial.org/fr/be...irst-triangle/ ), j'obtient cette erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    1>------ Début de la génération*: Projet*: Opengl_1, Configuration*: Debug Win32 ------
    1>  PrimitiveShape.cpp
    1>main.obj : error LNK2005: "unsigned int __cdecl LoadShaders(char const *,char const *)" (?LoadShaders@@YAIPBD0@Z) déjà défini(e) dans Application.obj
    1>PrimitiveShape.obj : error LNK2005: "unsigned int __cdecl LoadShaders(char const *,char const *)" (?LoadShaders@@YAIPBD0@Z) déjà défini(e) dans Application.obj
    1>LINK : warning LNK4098: conflit entre la bibliothèque par défaut 'MSVCRT' et les autres bibliothèques*; utilisez /NODEFAULTLIB:library
    1>F:\Documents\Programmation\Visual Studio 2015\Projects\Opengl_1\Debug\Opengl_1.exe : fatal error LNK1169: un ou plusieurs symboles définis à différentes reprises ont été rencontrés
    ========== Génération*: 0 a réussi, 1 a échoué, 0 mis à jour, 0 a été ignoré ==========
    Voila voila j'espère avoir été assez clair

    Merci pour votre future aide

  2. #2
    Expert confirmé
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Décembre 2015
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Décembre 2015
    Messages : 1 599
    Par défaut
    Bonjour,

    Le linker indique qu'il trouvé 3 fois la définition de LoadShaders(), dans main.cpp, PrimitiveHape.cpp et Application.cpp, c'est 2 fois de trop.
    Il faut voir ton code, et vérifier si par exemple il n'y a pas des inclusions inadaptées.

  3. #3
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2016
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 24
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Février 2016
    Messages : 39
    Par défaut
    Merci pour ta réponse dalfab , j'ai bien vérifié et je n'ai trouvé aucune redéfinition ou inclusion de ShaderLoader

    Pour plus de clarté voici l'entiereté du programme :

    Application.h :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
    #include <iostream>
    #include "Window.h"
    #include "PrimitiveShape.h"
     
    using namespace std;
     
    class Application
    {
    public:
    	Application();
    	void Init();
    	void Start();
    	void Stop();
    	void Run();
    	void PrintInfo();
     
    	GLFWwindow* GetWindow();
    	~Application();
     
    private:
    	Window screen;
    	PrimitiveShape point;
    	bool running;
    	float initialTime, finalTime, dTime, fps;
    };
    Apllication.cpp :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
     
    #include "Application.h"
     
    Application::Application()
    {
    }
     
    void Application::Init()
    {
    	initialTime = glfwGetTime();
    }
     
    void Application::Start()
    {
    	running = true;
    	Run();
    }
     
    void Application::Stop()
    {
    	running = false;
    	glfwSetWindowShouldClose(screen.window, GLFW_TRUE);
    }
     
    void Application::Run()
    {
    	while (!glfwWindowShouldClose(screen.window) && running)
    	{
    		glClear(GL_COLOR_BUFFER_BIT);
    		point.Draw();
     
    		glfwSwapBuffers(screen.window);
    		PrintInfo();
    		glfwPollEvents();
    	}
    }
     
    void Application::PrintInfo()
    {
    	finalTime = glfwGetTime();
    	dTime = finalTime - initialTime;
    	fps = 1 / dTime;
    	initialTime = finalTime;
    	cout << "FPS: " << fps << endl;
    }
     
    GLFWwindow* Application::GetWindow()
    {
    	return screen.window;
    }
     
    Application::~Application()
    {
    	screen.~Window();
    }
    Window.h :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    #include <GL\glew.h>
    #include <GLFW\glfw3.h>
    struct Window
    {
    	Window();
    	~Window();
     
    	GLFWwindow* window;
    	int width, height;
    };
    Window.cpp :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    #include "Window.h"
     
    Window::Window()
    {
    	width = 500, height = 500;
     
    	glfwInit();
     
    	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
     
    	window = glfwCreateWindow(width, height, "Opengl_1", NULL, NULL);
    	glfwMakeContextCurrent(window);
     
    	glewExperimental = GL_TRUE;
    	glewInit();
    }
     
    Window::~Window()
    {
    	glfwDestroyWindow(window);
    	glfwTerminate();
    }
    PrimitiveShape.h :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
    #include <GL\glew.h>
    #include "math.h"
    #include "ShaderLoader.h"
     
    class PrimitiveShape
    {
    public:
    	PrimitiveShape();
    	void Draw();
     
    private:
    	Vector3f Vertices[3];
    	GLuint VBO, VAO, programID;
    };
    PrimiveShape.cpp :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
     
    #include "PrimitiveShape.h"
     
    PrimitiveShape::PrimitiveShape()
    {
    	Vertices[0] = Vector3f(-1.0f, -1.0f, 0.0f);
    	Vertices[1] = Vector3f(1.0f, -1.0f, 0.0f);
    	Vertices[2] = Vector3f(0.0f, 1.0f, 0.0f);
     
    	//programID = LoadShaders("VertexShader.glsl", "FragmentShader.glsl");
     
    	glGenVertexArrays(1, &VAO);
    	glBindVertexArray(VAO);
     
    	glGenBuffers(1, &VBO);
    	glBindBuffer(GL_ARRAY_BUFFER, VBO);
    	glBufferData(GL_ARRAY_BUFFER, sizeof(Vertices), Vertices, GL_STATIC_DRAW);
     
    }
     
    void PrimitiveShape::Draw()
    {
    	//glUseProgram(programID);
    	glEnableVertexAttribArray(0);
    	glBindBuffer(GL_ARRAY_BUFFER, VBO);
    	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid *)0);
    	glDrawArrays(GL_TRIANGLES, 0, 3);
    	glDisableVertexAttribArray(0);
    }
    InputHandler :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    void InputHandler(GLFWwindow *window, int key, int action)
    {
    	Application *app = 	static_cast<Application*>(glfwGetWindowUserPointer(window));
     
    	if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
    		app->Stop();
    }
    ShaderLoader:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
     
    #include <fstream>
    #include <string>
    #include <vector>
     
    using namespace std;
     
    GLuint LoadShaders(const char * VertexShader_FilePath, const char * FragmentShader_FilePath);
     
    GLuint LoadShaders(const char * VertexShader_FilePath, const char * FragmentShader_FilePath)
    {
    	//Create
    	GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
    	GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
     
    	//Read the Vertex Shader file
    	string VertexShaderCode;
    	ifstream VertexShaderStream(VertexShader_FilePath, ios::in);
    	if (VertexShaderStream.is_open()) {
    		string Line = "";
    		while (getline(VertexShaderStream, Line))
    			VertexShaderCode += "\n" + Line;
    		VertexShaderStream.close();
    	}
    	else {
    		printf("Impossible to open %s !\n", VertexShader_FilePath);
    		return 0;
    	}
     
    	// Read the Fragment Shader code from the file
    	string FragmentShaderCode;
    	ifstream FragmentShaderStream(FragmentShader_FilePath, ios::in);
    	if (FragmentShaderStream.is_open()) {
    		std::string Line = "";
    		while (getline(FragmentShaderStream, Line))
    			FragmentShaderCode += "\n" + Line;
    		FragmentShaderStream.close();
    	}
    	else {
    		printf("Impossible to open %s !\n", FragmentShader_FilePath);
    		return 0;
    	}
     
    	GLint Result = GL_FALSE;
    	int InfoLogLength;
     
    	// Compile Vertex Shader
    	printf("Compiling shader : %s\n", VertexShader_FilePath);
    	char const * VertexSourcePointer = VertexShaderCode.c_str();
    	glShaderSource(VertexShaderID, 1, &VertexSourcePointer, NULL);
    	glCompileShader(VertexShaderID);
     
    	// Check Vertex Shader
    	glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
    	glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    	if (InfoLogLength > 0) {
    		vector<char> VertexShaderErrorMessage(InfoLogLength + 1);
    		glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
    		printf("%s\n", &VertexShaderErrorMessage[0]);
    	}
     
    	// Compile Fragment Shader
    	printf("Compiling shader : %s\n", FragmentShader_FilePath);
    	char const * FragmentSourcePointer = FragmentShaderCode.c_str();
    	glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer, NULL);
    	glCompileShader(FragmentShaderID);
     
    	// Check Fragment Shader
    	glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
    	glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    	if (InfoLogLength > 0) {
    		std::vector<char> FragmentShaderErrorMessage(InfoLogLength + 1);
    		glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
    		printf("%s\n", &FragmentShaderErrorMessage[0]);
    	}
     
    	// Link the program
    	printf("Linking program\n");
    	GLuint ProgramID = glCreateProgram();
    	glAttachShader(ProgramID, VertexShaderID);
    	glAttachShader(ProgramID, FragmentShaderID);
    	glLinkProgram(ProgramID);
     
    	// Check the program
    	glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
    	glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
    	if (InfoLogLength > 0) {
    		std::vector<char> ProgramErrorMessage(InfoLogLength + 1);
    		glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
    		printf("%s\n", &ProgramErrorMessage[0]);
    	}
     
    	glDetachShader(ProgramID, VertexShaderID);
    	glDetachShader(ProgramID, FragmentShaderID);
     
    	glDeleteShader(VertexShaderID);
    	glDeleteShader(FragmentShaderID);
     
    	return ProgramID;
    }
    et le main :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
    #include "Application.h"
    #include "InputHandler.h"
     
    static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
    {
    	InputHandler(window, key, action);
    }
     
    int main()
    {
    	Application App;
    	App.Init();
    	glfwSetKeyCallback(App.GetWindow(), key_callback);
    	glfwSetWindowUserPointer(App.GetWindow(), &App);
    	App.Start();
     
    	return 0;
    }
    C'est long mais on moins c'est clair

  4. #4
    Expert confirmé
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Décembre 2015
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Décembre 2015
    Messages : 1 599
    Par défaut
    Tu nommes un fichier ShaderLoader, j'ai l'impression que le début correspondrait à un shaderloader.h et la fin serait shaderLoader.cpp et j'espère que tu n'inclues pas 3 fois cela.

Discussions similaires

  1. Réponses: 23
    Dernier message: 15/08/2008, 05h14
  2. Réponses: 1
    Dernier message: 20/02/2007, 17h17
  3. Error LNK2005
    Par usbeck dans le forum C++
    Réponses: 8
    Dernier message: 17/08/2006, 09h39
  4. [MFC]error LNK2005
    Par annedjomo dans le forum MFC
    Réponses: 3
    Dernier message: 07/08/2006, 21h15
  5. Réponses: 2
    Dernier message: 31/10/2005, 13h40

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo