#Header file inclusion help

23 messages · Page 1 of 1 (latest)

rancid wasp
#

so the project tree is like this

- include/
    - shader.h
    - mesh.h
- mesh.c
- shader.c
- main.c

shader.h is included in mesh.h (which mesh.c includes) as well as main.c which gives rise to multiple definition errors. How to resolve this? I could post file contents if needed.

ashen juncoBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

forest raft
#

Are you making use of header guards?

clear patio
tame stirrup
#

does main.c include mesh.h?

rancid wasp
rancid wasp
clear patio
#

Okay, let's look at the first error:

mesh.c:(.text+0x0): multiple definition of `LoadShaders'; /tmp/main-a77ff5.o:main.c:(.text+0x0): first defined here
#

Where is LoadShaders declared and how

rancid wasp
clear patio
#

and how

#

How do you declare it?

rancid wasp
# clear patio How do you declare it?

okay wait, declarations are also present in shader.h, i was working on shader.c so for now in not using shader.c, neverthe less here is a brief of shader.h:

#
#ifndef SHADER_M_H
#define SHADER_M_H

#include "glad/glad.h"
#include <cglm/cglm.h>
#include <stdbool.h>
#include <stdio.h>         // printf()   FILE*
#include <stdlib.h>        // malloc()

unsigned int LoadShaders(const char* vertexPath, const char* fragmentPath);
void useShader(unsigned int programID);
void setBool(unsigned int programID, const char* name, bool value);
void setInt(unsigned int programID, const char* name, int value);
void setFloat(unsigned int programID, const char* name, float value);
int  loadShaderFromFile(const char* fileName, int shaderType);
void checkCompileErrors(unsigned int shader);
void ShaderCleanUp(unsigned int programID);

// constructor generates the shader on the fly
// ------------------------------------------------------------------------
unsigned int LoadShaders(const char* vertexPath, const char* fragmentPath)
{
    // 1. retrieve the vertex/fragment source code from filePath
    unsigned int programID;
    unsigned int vertex = loadShaderFromFile(vertexPath, GL_VERTEX_SHADER);
    unsigned int fragment = loadShaderFromFile(fragmentPath, GL_FRAGMENT_SHADER);

    programID = glCreateProgram();
    glAttachShader(programID, vertex);
    glAttachShader(programID, fragment);
    glLinkProgram(programID);
    checkCompileErrors(programID);
    // delete the shaders as they're linked into our program now and no longer necessary
    glDeleteShader(vertex);
    glDeleteShader(fragment);
    return programID;
}
clear patio
#

This is an entire definition, not just a declaration

#

In C you can't have definitions in headers

rancid wasp
#

shader.c is under construction

clear patio
#

Well this is your error

rancid wasp
#

okay lemme change that real quick

#

yup

#

worked out thanks

#

!solved