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:
Code:
# Main cmake file
cmake_minimum_required(VERSION 2.6)
# Main project name is ARMaker
project(HelloOpenGL)
# Find packages
FIND_PACKAGE(OpenGL)
FIND_PACKAGE(GLUT)
# Include dirs
include_directories(${OPENGL_INCLUDE_DIR})
include_directories(${GLUT_INCLUDE_DIR})
# Add all files to the configuration
file(GLOB HelloOpenGL_SRC
"*.h"
"*.cpp"
)
# Create an executable
add_executable(HelloOpenGL ${HelloOpenGL_SRC})
# Add libraries
target_link_libraries(HelloOpenGL ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES})
Here is the .cpp file:
Code:
#include <iostream>
#if defined(__APPLE__) || defined(MACOSX)
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#endif
using namespace std;
void display(void)
{
/* clear all pixels */
glClear (GL_COLOR_BUFFER_BIT);
/* draw white polygon (rectangle) with corners at
* (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
*/
glColor3f (1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();
/* don't wait!
* start processing buffered OpenGL routines
*/
glFlush ();
}
void init (void)
{
/* select clearing (background) color */
glClearColor (0.0, 0.0, 0.0, 0.0);
/* initialize viewing values */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
/*
* Declare initial window size, position, and display mode
* (single buffer and RGBA). Open window with "hello"
* in its title bar. Call initialization routines.
* Register callback function to display graphics.
* Enter main loop and process events.
*/
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("hello");
init ();
glutDisplayFunc(display);
glutMainLoop();
return 0; /* ISO C requires main to return int. */
}
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
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?
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
Re: Win7 64-bit Qt + CMake + GLUT
Quote:
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:
Quote:
#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).