shader programme does not link

Hello to everyone!

When calling create_programme_from_files the vertex and fragment shaders compile, but the Programme does not link. gl_log writes to a text file for documentation. From the log file I get the following output:

creating shader from test.vert…
shader compiled. index 1
creating shader from test.frag…
shader compiled. index 2
created programme 3. attaching shaders 1 and 2…
ERROR: could not link shader programme GL index 3
programme info log for GL index 3:
ERROR: Definition for “void main()” not found.

Here are the functions for creating the shaders and the programme:


void parse_file_into_str(const char* file_name, std::string shader_str)
{
	std::ifstream file(file_name);
	while (file.good())
	{
		std::string line;
		std::getline(file, line);
		shader_str.append(line + "
");
	}
	file.close();
}


bool create_shader(const char* file_name, GLuint* shader, GLenum type)
{
	gl_log("creating shader from %s...
", file_name);
	std::string shader_string;
	parse_file_into_str(file_name, shader_string);
	const GLchar* shader_str = shader_string.c_str();
	*shader = glCreateShader(type);
	glShaderSource(*shader, 1, &shader_str, NULL);
	glCompileShader(*shader);
	//check for compile errors
	int params = -1;
	glGetShaderiv(*shader, GL_COMPILE_STATUS, &params);
	if (GL_TRUE != params)
	{
		gl_log_err("ERROR: GL shader index %i did not compile
", *shader);
		_print_shader_info_log(*shader);
		return false;
	}
	gl_log("shader compiled. index %i
", *shader);
	return true;
}


bool create_programme(GLuint vert, GLuint frag, GLuint* programme)
	{
	*programme = glCreateProgram();
	gl_log("created programme %u. attaching shaders %u and %u...
", *programme, vert, frag);
	glAttachShader(*programme, frag);
	glAttachShader(*programme, vert);

	glLinkProgram(*programme);
	//check if link was successful
	GLint params = -1;
	glGetProgramiv(*programme, GL_LINK_STATUS, &params);
	if (GL_TRUE != params)
	{
		gl_log_err("ERROR: could not link shader programme GL index %u
", *programme);
		_print_programme_info_log(*programme);
		return false;
	}

	assert(is_valid(*programme));
	
	glDeleteShader(vert);
	glDeleteShader(frag);
	return true;
}

GLuint create_programme_from_files(const char* vert_file_name, const char* frag_file_name)
{
	GLuint vert, frag, programme;
	assert(create_shader(vert_file_name, &vert, GL_VERTEX_SHADER));
	assert(create_shader(frag_file_name, &frag, GL_FRAGMENT_SHADER));
	assert(create_programme(vert, frag, &programme));
	return programme;
}

Hopefully you can help me and thank you in advance.

Your shader sources are probably empty because of this:


void parse_file_into_str(const char* file_name, std::string shader_str)
{
    std::ifstream file(file_name);
    while (file.good())
    {
        std::string line;
        std::getline(file, line);
        shader_str.append(line + "
");
    }
    file.close();
}

shader_str is neither a pointer nor a reference. When you call this function, a copy is passed into the
function, the copy is modified localy and discarded when the function returns. So when you call this
function on an std::string, it is not modified and you are passing an empty string into glShaderSource.

Thanks a lot. This solved the problem.

How about if you delete the asterisk * at GLuint* programme,
GLuint programme, instead.