It seems that gl_Position doesn't let the shader link when inside a loop that uses a uniform variable as a end condition.
This isn't all the code, but commenting out gl_positon or changing the while loop to;
will then work
Hope someone can shed some light on this. Thanks.