Q:

GLSL shader compilation

When i'm compiling a shader does it have to be complete? Can i use glCompileShader on a shader without a main() function? The OpenGL reference documentation has a nice writeup on program linking errors, but i can't find one for shader linking, so i have to ask here.
I want to have the ability to have each part of a shader in a different file. So f.e. i'll have a material calculating function and i'll have a "main" shader with the main function that'll only reference the material calculating function. Right now i have my shaderes as arrays of strings that they can read from a file, then i put together an array of string pointeres and compile that into a single shader (vertex, fragment, geometry). But if i could compile each invidividual shaders (parts of vertex shaders, instead of the whole vertex shader put together in an array of strings) and put them together when i'm linking the program, that would make the code much clearer and i could move the shader compilation code from the program managing code to the shader object itself (the one that load the string from file and exposes it).

A:

The compilation model for OpenGL is described on the Wiki. But for your needs, I would suggest you simply use the fact that glShaderSource takes multiple strings. These strings effectively act as header files; the shader stitches them together and compiles them as a single unit.
The "linking" model within a shader stage is not something I would... rely on. Not because of the specification, but because it's not widely used. And that means it's more likely to have driver bugs in it. Stick to the path most commonly used and just use multiple source strings. That way, your code is more likely to work.

