Menu

Linker Errors using GLUT

starcreek
2008-07-16
2012-09-26
  • starcreek

    starcreek - 2008-07-16

    hi, im using Dev-C++ 4.9.9.2 on a Microsoft XP Home Edititon.

    My mission today is the linker errors, undefined refrences towards the glut function calls.

    I Believe i've linked everything accordingly and i did try and change the order.

    Lets start by looking at the Window Management functions, inside main()
    :
    int main(int argc, char **argv)
    {
    glutInit(&argc, argv); // inits GLUT and process's any cmmd line args
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // specifies whetehr to use an RGBA or color-index color model
    glutInitWindowSize(500, 500); // the size, in pixels, of my window
    glutInitWindowPosition(100, 100); // specifies the screen loc for the upper left corner of my window
    glutCreateWindow(argv[0]); // creates a window with an OpenGL Context
    init(); // void init(void)
    glutDisplayFunc(display); // first and most important event!
    glutReshapeFunc(reshape); // indicates what action should be taken when the window is resized
    glutMainLoop(); // last function, all windows are now shown -rendering effective
    return 0;
    }

    hmm, i like it! Five routine tasks to init a window! But..

    Compiler: Default compiler
    Executing g++.exe...
    g++.exe "C:\Folder\Cube.cpp" -o "C:\Folder\Cube.exe" -ansi -pg -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -lopengl32 -lglu32 -Lglut32.lib -lWinMM -lgdi32 -lglaux -lglut32 -lgmon -pg -g3
    C:\DOCUME~1\Owner\LOCALS~1\Temp/ccErlaaa.o(.text+0x26): In function glutInit_ATEXIT_HACK': C:/Dev-Cpp/include/gl/glut.h:486: undefined reference toglutInitWithExit@12'
    C:\DOCUME~1\Owner\LOCALS~1\Temp/ccErlaaa.o(.text+0x51): In function glutCreateWindow_ATEXIT_HACK': C:/Dev-Cpp/include/gl/glut.h:503: undefined reference to
    glutCreateWindowWithExit@8'
    C:\DOCUME~1\Owner\LOCALS~1\Temp/ccErlaaa.o(.text+0x7b): In function glutCreateMenu_ATEXIT_HACK': C:/Dev-Cpp/include/gl/glut.h:549: undefined reference to__glutCreateMenuWithExit@8'
    collect2: ld returned 1 exit status

    Execution terminated

    "C:\Dev\Include\GL" contains all my headers, so im able to use them as pre-pro-directs. I have all my .lib files in the path "C:\Dev-C++\lib\GL" which contains .lib files. The dynamic's are within "C:\Dev-C++\bin" no sub-directory.

    I did google these errors, and MinGW GLUT said that im using -lglut32 insted of -LGlut32.lib? I took their advice but non that command doesnt help.

     
    • cpns

      cpns - 2008-07-17

      You have really answered your own question, but I cannot fathom how you cannot see it!

      > I have all my .lib files in the path "C:\Dev-C++\lib\GL" which contains .lib files.

      But you have no -L"C:\Dev-C++\lib\GL" switch to tell the linker to look there! And as you have been told they should normally be be libXXX.a files not XXX.lib files.

      > The dynamic's are within "C:\Dev-C++\bin" no sub-directory.

      It is irrelevant to your problem, since the DLLs are only referenced ar runtime, but that is not a great idea. Where are you going to put them if you deploy your application on a machine without Dev-C++ installed? The DLLs merely need to be either in teh same folder as the executable, or in a location specified in the PATH environment variable. If it works where you have placed them it will be more by luck than judgement, and I suspect will not run outside of the IDE unless you have added the that to the PATH environment variable.

      > MinGW GLUT said that im using -lglut32 insted of -LGlut32.lib?
      If it really sad that it was wrong. -l is not the same thing as -L. -l specifies a library with shortened form name. If teh library conforms to the GNU naming convention of libXXX.a then -lXXX will link it. -L on the other hand specifies a library path where libXXX.a will be searched for, so specifying -LGlut32.lib will look for a folder called "Glut32.lib" not a file. Moreover it will look for it in the current working directory, which will be wherever your project is.

      Clifford

       
    • starcreek

      starcreek - 2008-07-17

      the mission continues.

      Compiler: Default compiler
      Executing g++.exe...
      g++.exe "C:\Folder\Cube.cpp" -o "C:\Folder\Cube.exe" -ansi -pg -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -lopengl32 -lglu32 -lglut32 -L"C:\Dev-Cpp\lib\GL" -L"C:\Dev-Cpp\lib" -lWinMM -lgdi32 -lglaux -lgmon -pg -g3
      C:\DOCUME~1\Owner\LOCALS~1\Temp/cc6pjaaa.o(.text+0x26): In function glutInit_ATEXIT_HACK': C:/Dev-Cpp/include/gl/glut.h:486: undefined reference toglutInitWithExit@12'
      C:\DOCUME~1\Owner\LOCALS~1\Temp/cc6pjaaa.o(.text+0x51): In function glutCreateWindow_ATEXIT_HACK': C:/Dev-Cpp/include/gl/glut.h:503: undefined reference to
      glutCreateWindowWithExit@8'
      C:\DOCUME~1\Owner\LOCALS~1\Temp/cc6pjaaa.o(.text+0x7b): In function glutCreateMenu_ATEXIT_HACK': C:/Dev-Cpp/include/gl/glut.h:549: undefined reference to__glutCreateMenuWithExit@8'
      collect2: ld returned 1 exit status

      Execution terminated

      The files that i presume to correct these errors have been specified in the linker options. The order does not seem to matter.

      -L"C:\Dev-Cpp\lib" tries to find libglut32.a
      -L"C:\Dev-Cpp\lib\GL" tries to find glut32.lib ( isnt that just -lglut32 )

      Couldnt i just have them both in one folder and link that path?

       
    • cpns

      cpns - 2008-07-17

      > Couldnt i just have them both in one folder and link that path?

      You can do what you like, its your build. You might even have tried it rather than asking for permission!

      However I would have two issues with that:

      (1) It's a good idea to keep libraries that you have added to the defaut installation separate. You won't then blow away your libraries if you need to reinstall, and you might want to install newer or modified versions of existing libraries without replacing the originals.

      (2) You have to ask yourself why what you have done does not work.

      Now it looks to me like you have done something very strange. If you added your library paths to Project->Project options->Directories->Libraries, all the -L<path> specifiers will have appeared together, but you seem to have two inserted in the middle of your -l<library> specifiers. Now this shouldn't matter, but it does kind of indicate that you may be deparately trahsing without really understanding what is going on. Specifying -L"C:\Dev-Cpp\lib" twice is also unnecessary. We ask you to post the Compile Log, but you might try reading it yourself first you know!

      Oh wait... I have just realised from your log that you are not using the Project facility. I strongly urge you to do so. It makes management of the build options far simpler. Anything you change in Tools->Compiler options will be applied to all subsequent projects and direct builds, and you would not normally want that.

      I wonder why you have the -pg option set. You probably don't want that. If you don't know what it is, you certainly don't want it, and you should stop setting options without understanding what they are for.

      > The order does not seem to matter
      Link order does matter! Any references in one library must be resolved in that library or one subsequently listed. The linker cannot resolve a reference that is defined in a previously listed library (unless you use the grouping options). You might do well to check out the command line section the linker manual: http://sourceware.org/binutils/docs/ld/Options.html#Options

      Clifford

       
    • Wayne Keen

      Wayne Keen - 2008-07-18

      Have you checked out the thread in this forum titled "Please Read Before Posting a Question"?

      There is a section in there on getting started withy Glut that has detailed directions on what
      to get, where to get it, where to put it, how to link it etc. There is also a section in there
      on the compile log, including headers, and linking libraries that goes into some of the mechanics
      that you might find helpful.

      Wayne

       
      • cpns

        cpns - 2008-07-18

        I think you may have suggested that to him previously. It seems that he has been trying to get this to work since February!

         
    • starcreek

      starcreek - 2008-07-18

      hey Dr. Wayne, I appreciate your reply,

      Yeah, i do know what you guys have under OpenGL/GLUT. I noticed that your main() is similar to mine and you get it to work by linking -lglut32 -lopengl32 ,So now im really confused. I have all my files in the right folder/path and it still does not work! I hate saying that, but thats what it has come down to. Obviously im doing something wrong that i cant see. Let me start over. And triple check.

      i have all my files relevent to GLUT, OpenGL, GLU, GLEE, in these paths:

      .lib and .a files -L"C:\Dev-Cpp\lib\GL"
      .dll files -L"C:\Dev-Cpp\bin"
      Header files -L"C:\Dev-Cpp\include\GL"

      this is not what i have setup in my linker options and is not what you guys have under OpenGL/GLUT regarding your link options. But i went ahead and tried it anyway, all orders. Is it suppose to be -L<C:\Dev-Cpp\bin> i tried that as well but no success.

      what i have in my linker options are as follows:
      -lglut32 -lopengl32 -lglu32

      I need glu for the viewing transformations

      all my files are of the latest version. At least that i can get my hands on.

      > I wonder why you have the -pg option set.

      I do not have the -pg under the linker options and yes i dont know what its for i might of did it my accident, how do i removed it mght be my probelm?

      > I have just realised from your log that you are not using the Project Facility

      I would like this to be a non-project application, i know what my projects require as far as the linker options go. i did remove the unnesessary -l files, such as -lWinMM -lgdi32 that are irrelevent and do not help/persist the problem.

      Compile log:

      compiler: Default compiler
      Executing g++.exe...
      g++.exe "C:\Folder\Cube.cpp" -o "C:\Folder\Cube.exe" -ansi -pg -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -L"C:\Dev-Cpp\lib\GL" -lglut32 -lglu32 -lopengl32 -L<C:\Dev-Cpp\lib\GL> -lgmon -pg -g3
      C:\DOCUME~1\Owner\LOCALS~1\Temp/ccgpaaaa.o(.text+0x26): In function glutInit_ATEXIT_HACK': C:/Dev-Cpp/include/gl/glut.h:486: undefined reference toglutInitWithExit@12'
      C:\DOCUME~1\Owner\LOCALS~1\Temp/ccgpaaaa.o(.text+0x51): In function glutCreateWindow_ATEXIT_HACK': C:/Dev-Cpp/include/gl/glut.h:503: undefined reference to
      glutCreateWindowWithExit@8'
      C:\DOCUME~1\Owner\LOCALS~1\Temp/ccgpaaaa.o(.text+0x7b): In function glutCreateMenu_ATEXIT_HACK': C:/Dev-Cpp/include/gl/glut.h:549: undefined reference to__glutCreateMenuWithExit@8'
      collect2: ld returned 1 exit status

      Execution terminated

      GLUTAPI void APIENTRY glutInitWithExit(int argcp, char *argv, void (cdecl *exitfunc)(int));

      i got that from the glut.h and its one of my undef ref's again my version number is 3.7.6

       
    • cpns

      cpns - 2008-07-18

      > Header files -L"C:\Dev-Cpp\include\GL"
      You don't specify the header location to the linker, it is the pre-processor that needs to know where header files are not the linker (via -I<path> directives), As it happens it does not actually appear in your log in any case, begging the question of where it is reading the headers from? Are you sure that you did not copy or move them to c:\dev-cpp\include, and are you sure that if there are headers in both folders that the ones it is using are the correct ones - i,e. match the version of the library you are using?

      Now looking the the error messages themselves (and you might well ask why I never mentioned it before), they are internal references. It is not complaining about references made in your code to symbols in the library, but rather references made in the library header to symbols in the library. It also shows the the header file in question is in C:/Dev-Cpp/include/gl, which as I noted above you have not specified as an include path. unless you used #include </gl/glut.h> in the code I cannot see how this works. Which brings me to another point, you chose not to include complete code, so I cannot see how you included the header.

      So, (and I expect a direct and accurate answer to these one, I think it will be vital):
      (1) Where exactly did you get your library and headers from (post the links)?
      (2) Do you have multiple glut.h or other GL/Glut related headers?
      (3) If you do, are they all identical, or from different versions/platforms?
      (4) You mentiond glut32.lib originally; you did not simply rename it libglut32.a did you?

      > .dll files -L"C:\Dev-Cpp\bin"
      You don't specify the DLL location to the linker, that is a runtime issue, it is the OS that needs to know where they are when the program is executed not linked. It does no harm however exactly because it does nothing, but if you wan to see the problem, it is a good idea to remove redundancy.

      > Is it suppose to be -L<C:\Dev-Cpp\bin>
      I posted a link to the linker manual, so you might have looked for yourself - that's why I posted it! When I posted -L<path> it was meant to imply that all of <path> including the brackets is to be replaced with an actual path. Sorry, I thought it a common typographical convention in computing, but perhaps only in certain domains. The linker manual uses italics for that purpose, but that is not an option on this forum. The quotes are only necessary for paths containing spaces and you should avoid those in any case.

      > what i have in my linker options are as follows:
      > -lglut32 -lopengl32 -lglu32

      For the time-being, to remove any doubts about link order use: -( -lglut32 -lopengl32 -lglu32 -)

      The -( -) options cause the linker to iterate the libraries between them so that link order does not matter, at the cost of some build time but as I said let's just remove the doubt for the time-being - for a small build like this it is negligible.

      > I do not have the -pg under the linker options
      Be aware that as well as the options that you explicitly add, all the options that you can set via the dialog box switches also ass options ot teh command line. This one switches on profiling. It instruments the object code so that it can be used with the GNU gprof tool. -lgmon is the profiling library and is there for the same reason.

      > I would like this to be a non-project application,
      Why!? You want to make it harder than is necessary? It causes the compiler options and the linker options to be issued on the same command line, making it much harder for us to see what is going on. That said other than the -L<C:\Dev-Cpp\lib\GL>, and profiling options, the log looks much cleaner. Unfortunately I think all the mess you had there was just distracting us from the real problem.

      Not using a project also makes things harder for you. All those redundant libraries you had were presumably necessary for some other build - that code will now no longer build until you put them back - a project would have meant you wouldn't have to do that because the options and build configuration are stored with the project. I recommend only placing options that do not affect code generation under Tools->Compiler Options, such as warning level options.

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.