"final link failed: File truncated" when including gl/glu.h

Started by
3 comments, last by treiguts 12 years, 9 months ago
Whenever I include <gl\glu.h> in my file, I get

c:/program files/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: final link failed: File truncated

Question is: why I get this, what it is and how to fix it?
Advertisement
Is there any more information with the error? Does it mention what file was truncated? I imagine it is caused by a corrupt or unrecognised file being included in the linking process. Can you give us your linker command line? The file path looks very unusual, it contains lots of directory climbing. Maybe that is normal for code::blocks, I don't use it.

Are you including the correct header file? Some header files might include pragma directives to link to particular libraries. If you were accidentally including some Visual Studio headers into your project this could cause problems I think.
This is only error I get and it does not mention responsible file. I am new in this and I'm not familiar with linker command line :( Only libraries/header files I include is SFML, iostream and gl, glu.

But I noticed that when I remove all openGL code from my files, it compiles without errors. As you see, code is very basic. I can't put even one line of code - glClearDepth(1.f);


glClearDepth(1.f);
glClearColor(0.f, 0.f, 0.f, 0.f);

// Enable Z-buffer read and write
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);

// Setup a perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 1.f, 500.f);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

sf::Clock Clock;

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -200.f);
glRotatef(Clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
glRotatef(Clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
glRotatef(Clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);



glBegin(GL_QUADS);

glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);

glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f( 50.f, 50.f, 50.f);
glVertex3f( 50.f, -50.f, 50.f);

glVertex3f(-50.f, -50.f, -50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, -50.f, 50.f);

glVertex3f(50.f, -50.f, -50.f);
glVertex3f(50.f, 50.f, -50.f);
glVertex3f(50.f, 50.f, 50.f);
glVertex3f(50.f, -50.f, 50.f);

glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, -50.f);
glVertex3f( 50.f, -50.f, 50.f);

glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(-50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, -50.f);
glVertex3f( 50.f, 50.f, 50.f);

glEnd();
Interesting. I cannot see why the presence or absence of a header file should result in a linker error, unless it is due to my initial guess at a #pragma dragging in additional linker directives.

Have you tried doing a "clean" build? I don't use code::blocks but this option might have another name like "rebuild all" or something. What version of code::blocks do you have? Some light Googling suggests that a particular version of the IDE might have an issue. The suggestion in that thread is to ensure you have the latest stable version. Another alternative would be to switch to Visual C++, which is an excellent IDE.

Can you determine where the glu.h is being included from? If you do a full search of your hard drive(s), and find all glu.h files. Go into each of them and temporarily add a #error directive to them, with some unique code (make a backup of the file first). Then rebuild your program and you can determine from the error messages which headers are being included. Ensure they are ones related to your code::blocks install and not some prior install of visual studio or other IDE. You might want to grep for #pragma directives in this file or files that it includes.
I am using Code Blocks 10.05
Glu.h and gl.h is included from codeblocks/mingw/include.
This is all pragma and includes it has. I saw it includes gl.gl.h also, so I removed mine include, thought it goes in circle with includes - no changes. In gl.h there is no pragmas or includes.

#if __GNUC__ >= 3
#pragma GCC system_header
#endif

#include <stddef.h> /* for wchar_t */
#include <GL/gl.h>


Edit: After 10min posting this, I resolved problem. Appears because of SFML that I was using, I had to link (correct order) opengl and glu before SFML files. Did little gogling and translating .

Still, thanks rip-off for help and patience :)

This topic is closed to new replies.

Advertisement