Results 1 to 4 of 4

Thread: Win7 64-bit Qt + CMake + GLUT

  1. #1
    Join Date
    Sep 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Question Win7 64-bit Qt + CMake + GLUT

    Hello everyone, This is my first post to the forums. I am enrolled in a class that requires me to use Qt (so I am also new to Qt). I am running on a Windows 7 machine with Qt 5.3. We also have downloaded the latest version of CMake (3.0.1) as a builder. I have linked the builder in Qt options (CMake.exe). I believe I am having issues with my GLUT files/paths. When I build/run the .cpp file I recieve the following errors:

    [img=http://s29.postimg.org/4wgoykq0z/qt_errors.jpg]

    I am using the CMakeLists.txt file when opening a project to build. Here is the CMakeLists.txt file:
    Qt Code:
    1. # Main cmake file
    2.  
    3. cmake_minimum_required(VERSION 2.6)
    4.  
    5. # Main project name is ARMaker
    6. project(HelloOpenGL)
    7.  
    8. # Find packages
    9. FIND_PACKAGE(OpenGL)
    10. FIND_PACKAGE(GLUT)
    11.  
    12. # Include dirs
    13. include_directories(${OPENGL_INCLUDE_DIR})
    14. include_directories(${GLUT_INCLUDE_DIR})
    15.  
    16.  
    17. # Add all files to the configuration
    18. file(GLOB HelloOpenGL_SRC
    19. "*.h"
    20. "*.cpp"
    21. )
    22.  
    23. # Create an executable
    24. add_executable(HelloOpenGL ${HelloOpenGL_SRC})
    25.  
    26.  
    27. # Add libraries
    28. target_link_libraries(HelloOpenGL ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES})
    To copy to clipboard, switch view to plain text mode 

    Here is the .cpp file:
    Qt Code:
    1. #include <iostream>
    2.  
    3. #if defined(__APPLE__) || defined(MACOSX)
    4. #include <GLUT/glut.h>
    5. #include <OpenGL/gl.h>
    6. #include <OpenGL/glu.h>
    7. #else
    8. #include <windows.h>
    9. #include <gl/gl.h>
    10. #include <gl/glu.h>
    11. #include <gl/glut.h>
    12.  
    13. #endif
    14.  
    15.  
    16.  
    17. using namespace std;
    18.  
    19. void display(void)
    20. {
    21. /* clear all pixels */
    22. glClear (GL_COLOR_BUFFER_BIT);
    23.  
    24. /* draw white polygon (rectangle) with corners at
    25.  * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
    26.  */
    27. glColor3f (1.0, 1.0, 1.0);
    28. glBegin(GL_POLYGON);
    29. glVertex3f (0.25, 0.25, 0.0);
    30. glVertex3f (0.75, 0.25, 0.0);
    31. glVertex3f (0.75, 0.75, 0.0);
    32. glVertex3f (0.25, 0.75, 0.0);
    33. glEnd();
    34.  
    35. /* don't wait!
    36.  * start processing buffered OpenGL routines
    37.  */
    38. glFlush ();
    39. }
    40.  
    41. void init (void)
    42. {
    43. /* select clearing (background) color */
    44. glClearColor (0.0, 0.0, 0.0, 0.0);
    45.  
    46. /* initialize viewing values */
    47. glMatrixMode(GL_PROJECTION);
    48. glLoadIdentity();
    49. glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
    50. }
    51.  
    52. /*
    53.  * Declare initial window size, position, and display mode
    54.  * (single buffer and RGBA). Open window with "hello"
    55.  * in its title bar. Call initialization routines.
    56.  * Register callback function to display graphics.
    57.  * Enter main loop and process events.
    58.  */
    59. int main(int argc, char** argv)
    60. {
    61. glutInit(&argc, argv);
    62. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    63. glutInitWindowSize (250, 250);
    64. glutInitWindowPosition (100, 100);
    65. glutCreateWindow ("hello");
    66. init ();
    67. glutDisplayFunc(display);
    68. glutMainLoop();
    69. return 0; /* ISO C requires main to return int. */
    70. }
    To copy to clipboard, switch view to plain text mode 

    My professor claims it is due to the linkage between Qt and the GLUT files. I have a hunch it cannot process the GLUT.lib file. Has anyone seen this issue or can help me so I can properly build and run my code? All of my course content will be of this format so once I figure this out I will be set.

    Thanks,
    Steven

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Win7 64-bit Qt + CMake + GLUT

    What you are seeing are linker errors. You aren't using Qt at all in the code you posted (and I wonder why you are posting this to a Qt forum...), so your professor is off the mark. Were your GLUT libraries built using the same compiler as your project uses? You can't mix and match Visual C++ and gcc binaries for example - they're incompatible. If you simply downloaded pre-built GLUT from somewhere, be sure the version you use matches your build tool-chain. Are your GLUT libraries also built using the same compilation options (32 vs 64 bit, debug vs release, for instance)? You can't mix and match either of these pairs, especially with MSVC compilers.

    I've used CMake, but I'm not intimately familiar with it. Assuming you are mixing oranges with oranges on your binaries, shouldn't you have declarations in your CMakeLists.txt file that provide the paths to the .lib files you want to link in, just as you have provided paths to the include files?

  3. #3
    Join Date
    Sep 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Win7 64-bit Qt + CMake + GLUT

    How I was told to set it up was to use file>open in Qt. Navigate to the directory with the CMakeLists.txt file (also has a .cpp file next to it), then build using the CMakeLists and a CMake compiler. After it compiles I receive an error that involves not being able to find the glut_include_dir. After I hit finish, my files are visible under the projects navigation, then I open the .cpp file. After the .cpp file is open, I build/compile the program and receive the errors I listed on the first post. I do not know why the errors are occurring or how to fix them.

    Thanks

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Win7 64-bit Qt + CMake + GLUT

    How I was told to set it up was to use file>open in Qt.
    Qt is a C++ development toolkit. Qt Creator is the integrated development environment you are confusing with the toolkit. CMake is not a compiler. It is a tool, like make, nmake, or the Qt Creator IDE which reads a project configuration file (in this case CMakeLists.txt) and builds the project(s) defined within it. This may or may not include compiling the C++ source code, which uses a compiler (and that could be gcc or Microsoft's Visual C++ compiler, depending on what you have installed).

    If you don't have an environment variable "GLUT_INCLUDE_DIR" defined, or it is pointing to the wrong place, then that will result in your CMake error. It is telling you that CMake can't find the include directories that GLUT_INCLUDE_DIR is pointing to if it is defined at all.

    The CMake misconfiguration isn't affecting your source code compilation, because the compiler apparently can find the GLUT include files. This is totally unrelated to anything you've told CMake. These lines:

    #include <gl/gl.h>
    #include <gl/glu.h>
    #include <gl/glut.h>
    are telling the compiler where to look for your OpenGL and GLUT include files, and your directory layout seems to be appropriate for it to find them. Thus, you can compile your program, but you can't link it because you haven't told the linker where to look for the library files. Possibly there is a GLUT_LIBRARY_DIR or some similar environment variable that needs to be set to point there. That is probably something that needs to be added to your CMakeLists.txt file (and successfully run through CMake).

Similar Threads

  1. Linking glut to Qt
    By Mashkur in forum Qt Tools
    Replies: 1
    Last Post: 14th October 2012, 19:18
  2. How to Link glut to Qt
    By Mashkur in forum Newbie
    Replies: 1
    Last Post: 14th October 2012, 17:54
  3. How to link glut.h?
    By connect_qt in forum Newbie
    Replies: 3
    Last Post: 15th November 2011, 23:14
  4. Linking GLUT with QT
    By TheBogeyMan in forum Newbie
    Replies: 1
    Last Post: 10th October 2011, 19:41
  5. Qi with glut
    By hudi in forum Qt Programming
    Replies: 7
    Last Post: 14th April 2010, 12:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.