what values to use to compile shaders?

hi all. im having trouble compiling my shaders. here is what i believe to be the relevant code.

static const char *vshader =
	    		"#version 430 core"
	    		"layout (location = 0) in vec4 vPosition;"
	    		"void main()"
	    		"{"
	    		"	gl_Position = vPosition;"
	    		"}";

	    static const char *fshader =
	    		"#version 430 core"
	    		"out vec4 fcolor;"
	    		"void main()"
	    		"{"
	    		"	fColor = vec4 (0.0, 0.0, 1.0, 1.0);"
	    		"}";

		GLuint prog = glCreateProgram();
	    GLuint vert = glCreateShader(GL_VERTEX_SHADER);
	    GLuint frag = glCreateShader(GL_FRAGMENT_SHADER);
	    glShaderSource(vert, 1, &vshader, 0);
	    glShaderSource(frag, 1, &fshader, 0);
	    glCompileShader(vert);
	    glCompileShader(frag);
	    glAttachShader(prog, vert);
	    glAttachShader(prog, frag);
	    glLinkProgram(prog);
	    glUseProgram(prog);

i believe the problem is with glShaderSource(). i dont know what values to use.
thanks for the help.

You should check if the shader compiled with glGetShader(shader_id, GL_COMPILE_STATUS, &status), and the errors/warnings of the compiles with glGetShaderInfoLog(). You can check the link status with glGetProgram(program_id, GL_LINK_STATUS, &status), and the link errors/warnings with glGetProgramInfoLog().

The reason it’s not working is that you’ve spelled fcolor two different ways in the fragment shader.

More significantly, you need some newline characters. When C concatenates adjacent string literals, it doesn’t insert newlines (or any other whitespace).

At a minimum, the #version directive needs to be terminated with a newline. At the moment, the “core” at the end of the first line and the “layout” at the beginning of the second line will be combined into a single “corelayout” token.

I don’t think that you need any other newlines in this particular case, but more complex shaders will have problems (e.g. a “//” comment will extend to the end of the shader, not the end of a single string literal).