freeglut program almost works

I want to use freeglut, but the only way I can get the following program to work is by adding “opengl32” to the library list “libfreeglut.a” and “libfreeglut_static.a”, which defeats the point. I want to build x64 - openglut has the files for it, but opengl32 is not helpful in the scheme of things.

Q: how do I make this test code totally freeglut?


#include<iostream>
#define GLUT_DISABLE_ATEXIT_HACK
//#include<GL/glut.h>
#include<GL/freeglut.h>
void display() {
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
}
int main(int argc, char **argv)
{
	//-->init glut
	glutInit(&argc, argv);
	std::cout<<"so far..."<<std::endl;
    glutInitWindowSize(512,512);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutCreateWindow("Test Program :: fglut test hello world");
    glutDisplayFunc(display);
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glutMainLoop(); // Infinite event loop
    return 0;
std::cout<<"Test 1..."<<std::endl;

return 0;

}

window + console output as expected.
Won’t compile unless -l opengl32 library is added.

if its just “freeglut” library and header, compiling error:


src\main.o: In function `Z7displayv':
C:\Users\Technologist\Marble\glfw_opengl\fglut_test\Debug/../src/main.cpp:12: undefined reference to `glClear@4'
C:\Users\Technologist\Marble\glfw_opengl\fglut_test\Debug/../src/main.cpp:13: undefined reference to `glFlush@0'
src\main.o: In function `main':
C:\Users\Technologist\Marble\glfw_opengl\fglut_test\Debug/../src/main.cpp:24: undefined reference to `glClearColor@16'
collect2.exe: error: ld returned 1 exit status


The OpenGL DLL is called opengl32.dll for both 32-bit and 64-bit versions. You can’t build OpenGL programs without it. You also need GLEW (or similar) if you want to use anything beyond OpenGL 1.1 on Windows.

Excellent thank you! That was the piece I needed. I was compiling with 64bit GLEW headers/libraries (in other examples) & freeglut which was going nicely except for the opengl32, which I didn’t know could compile with 64 bit compiler.

Do I continue to link against -l opengl32 I have been using? And when you say that opengl32 64bit is named the same as 32bit, are they the same file or is one 64bit and one 32bit?

Ive never seen a DLL for opengl32 before. Guess its in the system.

Followup: Egad! The program is missing gdi32+ to make it in runtime. No 64bit available. I can’t find the functions below; they must be buried in the header files:


C:\Users\Technologist\Marble\64bit\3D_FPS_cam\Debug/../src/main.cpp:125: undefined reference to `debugGL()'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x394): undefined reference to `__imp_CreateDCW'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x3a5): undefined reference to `__imp_GetDeviceCaps'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x3b5): undefined reference to `__imp_GetDeviceCaps'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x3ce): undefined reference to `__imp_DeleteDC'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x533): undefined reference to `__imp_CreateDCW'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x544): undefined reference to `__imp_GetDeviceCaps'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x554): undefined reference to `__imp_GetDeviceCaps'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x56d): undefined reference to `__imp_DeleteDC'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xa69): undefined reference to `__imp_CreateDCW'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xa78): undefined reference to `__imp_GetDeviceGammaRamp'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xa84): undefined reference to `__imp_DeleteDC'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xbe4): undefined reference to `__imp_CreateDCW'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xbf3): undefined reference to `__imp_SetDeviceGammaRamp'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xbfc): undefined reference to `__imp_DeleteDC'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xcf): undefined reference to `__imp_CreateDIBSection'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x109): undefined reference to `__imp_CreateBitmap'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x1b4): undefined reference to `__imp_DeleteObject'
C:\64bit_bil_inc_lib\library/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x239): undefined reference to `__imp_DeleteObject'
C:\64bit_bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x170): undefined reference to `__imp_SwapBuffers'
C:\64bit_bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x43f): undefined reference to `__imp_DescribePixelFormat'
C:\64bit_bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x539): undefined reference to `__imp_DescribePixelFormat'
C:\64bit_bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x687): undefined reference to `__imp_DescribePixelFormat'
C:\64bit_bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x6a1): undefined reference to `__imp_SetPixelFormat'
C:\64bit_bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xfd5): undefined reference to `__imp_ChoosePixelFormat'
C:\64bit_bil_inc_lib\library/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xfe3): undefined reference to `__imp_SetPixelFormat'
collect2.exe: error: ld returned 1 exit status

Headers:

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <freeglut.h>
#include <freeglut_ext.h>
#include <freeglut_std.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#define GLM_ENABLE_EXPERIMENTAL
#include <GLM/glm.hpp>
#include <GLM/gtx/transform.hpp>

Yes.

They are different files. To add to the confusion, the 64-bit one will be in Windows/System32, the 32-bit one in Windows\SysWOW64.

Read the instructions for the libraries which you’re using, and ensure that you have the correct (64-bit) versions of everything, and the correct paths. Failing that, try asking on a GLFW forum.

If the 64bit opengl file is already in Windows/system32, what do I do with it. Thanks on verything else.