expected ‘#extension <name> : <action>’

If you are writing GLSL-shaders directly in a char-array instead of loading them from a file, and want to use #define or #extension and so on, you might get these errors:

0(1) : error C0114: expected ‘#extension <name> : <action>’
(0) : error C0000: syntax error, unexpected $end at token “<EOF>”

Say your fragment shader look like this:

static const char fragment_shader[] = \
“#extension GL_EXT_gpu_shader4 : enable”
“uniform vec4 test;”

“void main(void)”
“{“
       “gl_FragColor = vec4(0, 0, 1, 1)*test;”
“}”;

When this get’s compiled, the “#extension GL_EXT_gpu_shader4 : enable” line is not properly read because there are no new line or a semicolon that can say that the line is read. When you creat this array, the shader really looks like this:

“#extension GL_EXT_gpu_shader4 : enableuniform vec4 test;void main(void){gl_FragColor = vec4(0, 0, 1, 1)*test;}”

A one-line shader.

Solution

To overcome this problem, you can manually add new-lines to the lines that needs this by using the char ‘\n’:

static const char fragment_shader[] = \
“#extension GL_EXT_gpu_shader4 : enable\n”
“uniform vec4 test;”

“void main(void)”
“{“
“gl_FragColor = vec4(0, 0, 1, 1)*test;”
“}”;

If the “#extension ..” line got shader code above as well, add a \n to the line above, or before #:

static const char fragment_shader[] = \
“uniform vec4 test;”
“\n#extension GL_EXT_gpu_shader4 : enable\n”

“void main(void)”
“{“
“gl_FragColor = vec4(0, 0, 1, 1)*test;”
“}”;

I know this might help somebody. Other solutions to similar problems are to use the Advanced Save function in Visual Studio to change the encoding of the file, or to pass in the array-length when writing compiling the shader.

This entry was posted in GLSL, OpenGL. Bookmark the permalink.

4 Responses to expected ‘#extension <name> : <action>’

  1. Pingback: Windows Client Developer Roundup 070 for 5/23/2011 - Pete Brown's 10rem.net

  2. Yevgeny says:

    Thanks a lot for your tip! I’ve got a similar error message, but the reason was in my text file format: somehow there were only CR symbols without LF at the end of lines. I started thinking of the shader-compiler bug, but your solution helped.

  3. jrwpct says:

    You rock! Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.