GLSL: define a constant for both vertex and fragment shader

I have a constant for defining an array in the vertex shader. I want to use this constant also in the fragment shader to define another array of the same size. Naive attempts fail (simply use the constant of the vertex shader in the fragment shader or using a #define from the vertex shader). Is this somehow possible?

The only idea I can come up with is using something like an include statement, which seems to be added (source), but I didn't yet find the time to implement this.

There is a reason why glShaderSource and glCompileShaderProgram both take an array of strings. It's so that you can effectively insert code before your actual shader text or otherwise implement your own "include" system.

The issue here is that you now need to break your shaders down into pieces:

1. The header preamble. The first thing in the first string needs to be a version declaration. Following that should be any extensions of note.
2. Any collective definitions, like the ones you're trying to add to the shader.

Vertex and fragment shaders are two separate programs that are compiled independently of each other. Any definitions that you want to use in both shaders have to be included in the source of both shaders; definitions do not carry over from one shader to another.

I assume most developers implement some kind of include system - whether it's by using the ARB_shading_language_include extension, or by passing shader source files through the C preprocessor before compiling them, or some other method.