1

I'm trying to create an Glut window with Qt creator. All my code has been done on another computer. Now, I want to compile it on my own.

I've added the Glut32 library files in the following folders:

  • glut32.lib into a lib/ foler in my project directory
  • glut32.dll into my project directory
  • glut.h into a GL/ folder in my project directory

In my pro files, I've added the following lines:

LIBS += -L$$PWD/lib/glut32.lib
LIBS += Opengl32.lib

And in my code, I've the following includes:

#include <gl/GL.h>
#include "GL/glut.h"

Qt does not report any error with the last include!

So, when I try to compile my code, I've many errors which say:

error LNK2019: unresolved external symbol

All those errors belongs to glut functions which cannot be found. So, did I do something wrong when I included the glut32 library?

Thanks.

Manitoba
  • 8,522
  • 11
  • 60
  • 122

1 Answers1

1

Maybe it helps you to know, that you can output messages in your pro file, eg: message("Location of glut32.lib" + $$PWD/lib/glut32.lib). So you could check, whether your path is ok. Also note, that you add libraries with -l<LibName> and library paths with -L<LibPath>, so you should try to replace -L$$PWD/lib/glut32.lib by -l$$PWD/lib/glut32.lib

For further options refer to the qmake variable reference

AquilaRapax
  • 1,086
  • 8
  • 22
  • Thanks for your answer. I'm quite new with Qt creator, so can you tell me where I am supposed to add the lib cmds? All I have set up is the pro file. – Manitoba May 10 '12 at 12:12
  • Mainly in your .pro file, as you wrote in your question, there can be a line that looks similar to `LIBS += ...`. Sometimes there also exist .pri files, which can be included in pro files, and are mostly used to share build steps. The syntax is similar to the one in .pro files. In QtCreator you can add Libraries, without modifying the pro file by yourself. You can find a guide on how to do this at http://doc.qt.nokia.com/qtcreator-2.3/creator-project-qmake-libraries.html I think it will place relative paths in your pro-file, but you should check this. – AquilaRapax May 10 '12 at 12:46
  • I just tested it for myself with QtCreator 2.2, noticing the following: The lib was located in the path $$PWD/libraries. To make the project compiling, i added to the pro-file `LIBS += -L$$PWD/libraries`. There was no need to add the lib directly. The other thing i noticed, was: When adding a lib with `LIBS += -l` you aren't allowed to add the `.lib` extension, qmake will do this for you (portability reasons i guess). So `#LIBS += -l$$PWD/libraries/glut32` worked, `#LIBS += -l$$PWD/libraries/glut32.lib` didn't. – AquilaRapax May 10 '12 at 21:04
  • What did you put as include? "GL/glut.h" or or something else? – Manitoba May 11 '12 at 10:03
  • I used `#include "GL/glut.h"` since the header is located in my code-tree. `#include <...>` is used, if you include "external" headers, but this shouldn't make any difference. The only difference between both is, that the compiler searches in a wider range of folders when using the second one. But if it would have been an include problem, you would have received other error messages. The `unresolved symbol`-error in combination with libs is mostly the result of libs that are not found or libs, that do not match the definitions in the headers. – AquilaRapax May 11 '12 at 10:30
  • I've the following code in my pro file: http://pastebin.com/kraMPM7T And in my cpp file, I've this include: #include "GL/glut.h". Here is the structure of my project: http://pastebin.com/fMmaFktw The problem is I still have the LNK2019 errors. – Manitoba May 11 '12 at 11:56
  • Dumb question, but are the symbol errors related to glut? Could you post some of those errors? I didn't check this now, since i have no QtCreator at the moment, but for me your pro file looks good and should work. – AquilaRapax May 11 '12 at 12:06
  • I got exactly 10 errors like that: `main.obj:-1: erreur : LNK2019: symbole externe non résolu _glutSwapBuffers@0 référencé dans la fonction "void __cdecl RenderScene(void)" (?RenderScene@@YAXXZ)`. After translation, it says: `main.obj:-1: error: LNK2019: unresolved external symbol _glutSwapBuffers@0 referenced in function "void __cdecl RenderScene(void)" (?RenderScene@@YAXXZ)` – Manitoba May 11 '12 at 12:13
  • Can you upload the (minimized-to-the-error) project somewhere, inlcuding your glut libs and headers? I would try this on my computer and see what happens. – AquilaRapax May 11 '12 at 12:24
  • 1
    Ok, i didn't test it with QtCreator, but with VS2010 and had the same linker errors. Now i can say, that your lib(date: 1998) does not match with the header(date: 1997). I downloaded a newer glut version from http://user.xmission.com/~nate/glut.html (very slow site!), replaced the files and everything compiled without errors. – AquilaRapax May 11 '12 at 13:01