Many undefined references with CLion C++ [duplicate] - c++

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
How add OpenGL & GLUT for CLion on Windows?
(1 answer)
Closed 1 year ago.
I want to learn how to use the OpenGL library with C++ but I am struggling getting the external libraries to import. I am using CLion as my IDE and MinGW as my compiler. Here is my CMake code:
cmake_minimum_required(VERSION 3.17)
project(compgeo)
set(CMAKE_CXX_STANDARD 14)
add_executable(compgeo main.cpp)
find_package(GLUT REQUIRED)
find_package(OpenGL REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} )
And here is my code that I am trying to test:
/*
* GL01Hello.cpp: Test OpenGL C/C++ Setup
*/
#include <windows.h> // For MS Windows
#include <GL/glut.h> // GLUT, includes glu.h and gl.h
/* Handler for window-repaint event. Call back when the window first appears and
whenever the window needs to be re-painted. */
void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
// Draw a Red 1x1 Square centered at origin
glBegin(GL_QUADS); // Each set of 4 vertices form a quad
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex2f(-0.5f, -0.5f); // x, y
glVertex2f( 0.5f, -0.5f);
glVertex2f( 0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd();
glFlush(); // Render now
}
/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
glutInitWindowSize(320, 320); // Set the window's initial width & height
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
glutDisplayFunc(display); // Register display callback handler for window re-paint
glutMainLoop(); // Enter the infinitely event-processing loop
return 0;
}
These are the errors I am getting. The issue comes around once it links the CXX executable:
[ 50%] Linking CXX executable compgeo.exe
CMakeFiles\compgeo.dir/objects.a(main.cpp.obj): In function `glutInit_ATEXIT_HACK':
c:/mingw/include/gl/glut.h:486: undefined reference to `__glutInitWithExit#12'
CMakeFiles\compgeo.dir/objects.a(main.cpp.obj): In function `glutCreateWindow_ATEXIT_HACK':
c:/mingw/include/gl/glut.h:503: undefined reference to `__glutCreateWindowWithExit#8'
CMakeFiles\compgeo.dir/objects.a(main.cpp.obj): In function `glutCreateMenu_ATEXIT_HACK':
c:/mingw/include/gl/glut.h:549: undefined reference to `__glutCreateMenuWithExit#8'
CMakeFiles\compgeo.dir/objects.a(main.cpp.obj): In function `Z7displayv':
A:/CppProjects/compgeo/main.cpp:10: undefined reference to `glClearColor#16'
A:/CppProjects/compgeo/main.cpp:11: undefined reference to `glClear#4'
A:/CppProjects/compgeo/main.cpp:14: undefined reference to `glBegin#4'
A:/CppProjects/compgeo/main.cpp:15: undefined reference to `glColor3f#12'
A:/CppProjects/compgeo/main.cpp:16: undefined reference to `glVertex2f#8'
A:/CppProjects/compgeo/main.cpp:17: undefined reference to `glVertex2f#8'
A:/CppProjects/compgeo/main.cpp:18: undefined reference to `glVertex2f#8'
A:/CppProjects/compgeo/main.cpp:19: undefined reference to `glVertex2f#8'
A:/CppProjects/compgeo/main.cpp:20: undefined reference to `glEnd#0'
A:/CppProjects/compgeo/main.cpp:22: undefined reference to `glFlush#0'
CMakeFiles\compgeo.dir/objects.a(main.cpp.obj): In function `main':
A:/CppProjects/compgeo/main.cpp:29: undefined reference to `glutInitWindowSize#8'
A:/CppProjects/compgeo/main.cpp:30: undefined reference to `glutInitWindowPosition#8'
A:/CppProjects/compgeo/main.cpp:31: undefined reference to `glutDisplayFunc#4'
A:/CppProjects/compgeo/main.cpp:32: undefined reference to `glutMainLoop#0'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [compgeo.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/compgeo.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/compgeo.dir/rule] Error 2
mingw32-make.exe: *** [compgeo] Error 2
CMakeFiles\compgeo.dir\build.make:104: recipe for target 'compgeo.exe' failed
CMakeFiles\Makefile2:94: recipe for target 'CMakeFiles/compgeo.dir/all' failed
CMakeFiles\Makefile2:101: recipe for target 'CMakeFiles/compgeo.dir/rule' failed
Makefile:137: recipe for target 'compgeo' failed

You must add the library as a link dependency.
target_link_libraries(compgeo ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} )

Related

Multiple undefined reference errors when linking freeglut and codelite (minGW32 c++)

While trying to install (if that's the right word) opengl onto my codelite IDE to create c++ opengl programs, I have run into multiple undefined reference errors in the freeglut_std.h file as well as well known functions like glutMainLoop() are also "undefined".
So I have actually found the function definitions in the freeglut_std.h file and I have tried messing with the header file to make sure that there is no false conditions causing my definitions not to be created. (like making #if true ..... #endif (so that the code will for sure run)). I have experience in C but have never linked files like this before. Going through several webpages like: https://www.ntu.edu.sg/home/ehchua/programming/opengl/HowTo_OpenGL_C.html , https://www.transmissionzero.co.uk/computing/using-glut-with-mingw/ I linked my files. (Also note, that this question has been asked before however most posts had different solutions that didn't work for me)
So here is how codelite is compling my files (with not erroneous code) :
C:/mingw-w64/i686-7.3.0-posix-dwarf-rt_v5-rev0/mingw32/bin/g++.exe -c "C:/Users/admin/Documents/codelite/workspaces/c_plus_plus/cpp_openGL/main.cpp" -g -O0 -Wall -I"C:\mingw-w64\i686-7.3.0-posix-dwarf-rt_v5-rev0\mingw32\include" -o ./Debug/main.cpp.o -I. -I.
C:/mingw-w64/i686-7.3.0-posix-dwarf-rt_v5-rev0/mingw32/bin/g++.exe -o ./Debug/cpp_openGL #"cpp_openGL.txt" -L. -m32 -static-libgcc -static-libstdc++ -static -lpthread -L"C:\mingw-w64\i686-7.3.0-posix-dwarf-rt_v5-rev0\mingw32\lib" -Wl,--subsystem,windows -lfreeglut -lopengl32 -lglu32
mingw32-make.exe[1]: Leaving directory 'C:/Users/admin/Documents/codelite/workspaces/c_plus_plus/cpp_openGL'
====0 errors, 0 warnings====
However for something like this (actual test code):
/*
* GL01Hello.cpp: Test OpenGL C/C++ Setup
*/
#include <windows.h> // For MS Windows
#include <GL/glut.h> // GLUT, includes glu.h and gl.h
/* Handler for window-repaint event. Call back when the window first appears and
whenever the window needs to be re-painted. */
void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
// Draw a Red 1x1 Square centered at origin
glBegin(GL_QUADS); // Each set of 4 vertices form a quad
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex2f(-0.5f, -0.5f); // x, y
glVertex2f( 0.5f, -0.5f);
glVertex2f( 0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd();
glFlush(); // Render now
}
/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
glutInitWindowSize(320, 320); // Set the window's initial width & height
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
glutDisplayFunc(display); // Register display callback handler for window re-paint
glutMainLoop(); // Enter the infinitely event-processing loop
return 0;
}
I get the following errors:
./Debug/main.cpp.o: In function `glutInit_ATEXIT_HACK':
C:/mingw-w64/i686-7.3.0-posix-dwarf-rt_v5-rev0/mingw32/include/GL/freeglut_std.h:623: undefined reference to `_imp____glutInitWithExit#12'
./Debug/main.cpp.o: In function `glutCreateWindow_ATEXIT_HACK':
C:/mingw-w64/i686-7.3.0-posix-dwarf-rt_v5-rev0/mingw32/include/GL/freeglut_std.h:625: undefined reference to `_imp____glutCreateWindowWithExit#8'
./Debug/main.cpp.o: In function `glutCreateMenu_ATEXIT_HACK':
C:/mingw-w64/i686-7.3.0-posix-dwarf-rt_v5-rev0/mingw32/include/GL/freeglut_std.h:627: undefined reference to `_imp____glutCreateMenuWithExit#8'
./Debug/main.cpp.o: In function `main':
C:/Users/admin/Documents/codelite/workspaces/c_plus_plus/cpp_openGL/main.cpp:32: undefined reference to `_imp__glutInitWindowSize#8'
C:/Users/admin/Documents/codelite/workspaces/c_plus_plus/cpp_openGL/main.cpp:33: undefined reference to `_imp__glutInitWindowPosition#8'
C:/Users/admin/Documents/codelite/workspaces/c_plus_plus/cpp_openGL/main.cpp:34: undefined reference to `_imp__glutDisplayFunc#4'
C:/Users/admin/Documents/codelite/workspaces/c_plus_plus/cpp_openGL/main.cpp:35: undefined reference to `_imp__glutMainLoop#0'
collect2.exe: error: ld returned 1 exit status
====7 errors, 0 warnings====
The file that it is complain about is freeglut_std.h, the following is copied from the file:
#if defined(_WIN32) && !defined(GLUT_DISABLE_ATEXIT_HACK) && !defined(__WATCOMC__)
FGAPI void FGAPIENTRY __glutInitWithExit(int *argcp, char **argv, void (__cdecl *exitfunc)(int));
FGAPI int FGAPIENTRY __glutCreateWindowWithExit(const char *title, void (__cdecl *exitfunc)(int));
FGAPI int FGAPIENTRY __glutCreateMenuWithExit(void (* func)(int), void (__cdecl *exitfunc)(int));
#ifndef FREEGLUT_BUILDING_LIB
#if defined(__GNUC__)
#define FGUNUSED __attribute__((unused))
#else
#define FGUNUSED
#endif
static void FGAPIENTRY FGUNUSED glutInit_ATEXIT_HACK(int *argcp, char **argv) { __glutInitWithExit(argcp, argv, exit); }//<--has problem with
#define glutInit glutInit_ATEXIT_HACK
static int FGAPIENTRY FGUNUSED glutCreateWindow_ATEXIT_HACK(const char *title) { return __glutCreateWindowWithExit(title, exit); }//<--has problem with
#define glutCreateWindow glutCreateWindow_ATEXIT_HACK
static int FGAPIENTRY FGUNUSED glutCreateMenu_ATEXIT_HACK(void (* func)(int)) { return __glutCreateMenuWithExit(func, exit); } //<--has problem with
#define glutCreateMenu glutCreateMenu_ATEXIT_HACK
#endif
#endif
#ifdef __cplusplus
}
#endif
Note that I could get rid the 3-undefined references with:
#define GLUT_DISABLE_ATEXIT_HACK
However the remaining errors still exist.
A final note in freeglut_std.h the following lines exist (are these not definitions)
FGAPI void FGAPIENTRY glutInit( int* pargc, char** argv );
FGAPI void FGAPIENTRY glutInitWindowPosition( int x, int y );
FGAPI void FGAPIENTRY glutInitWindowSize( int width, int height );
FGAPI void FGAPIENTRY glutInitDisplayMode( unsigned int displayMode );
FGAPI void FGAPIENTRY glutInitDisplayString( const char* displayMode );
And something must be working since it doesn't complain about
glutinit(param...)
glutCreateWindow(param...)
UPDATE
I should let you guys know that I have a freeglut.dll file saved in the same location as my application. However that shouldn't matter because I also tried a static build white I used -DFREEGLUT_STATIC in the complier command, and linked -lfreeglut_static This had the same result, except the _imp_ part of the error was gone.
So in short I am bamboozled here, Any help is always greatly appreciated.
(p.s. please spare me mods).

OpenGL program failing to link?

I'm attempting to use the GA Sandbox source code found here on Linux (specifically Ubuntu 16.04). Yet when it comes to compiling the first example I'm left with this error.
g++ -g -O2 -o chap1ex1 chap1ex1.o -lGL -lGLU -lglut ../../libgasandbox/libgasandbox.a
../../libgasandbox/libgasandbox.a(libgasandbox_a-gl_util.o): In function
`pickLoadMatrix()':
/mnt/c/GASandbox/ga_sandbox-1.0.7/libgasandbox/gl_util.cpp:231: undefined
reference to `gluPickMatrix'
collect2: error: ld returned 1 exit status
Makefile:216: recipe for target 'chap1ex1' failed
I should mention that the configure script which provided the Makefile mentioned above does not initially link either -lGL or -lGLU. This gave me an error pertaining to a missing DSO, which was corrected by linking -lGL. I then wound up with this error. I looked around for any similar errors online and found this post, where the OP solved it by linking -lGLU. I was not so fortunate.
Here is the snippet of code in question, from gl_util.cpp.
#include <string>
#include "gl_util.h"
#if defined (__APPLE__) || defined (OSX)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
// code inbetween
namespace GLpick {
bool g_pickActive = false;
int g_OpenGL_pick[4] = {0, 0, 0, 0};
double g_frustumNear = 1.0;
double g_frustumFar = 100.0;
double g_frustumWidth = -1.0;
double g_frustumHeight = -1.0;
int g_pickWinSize = 4;
}
void pickLoadMatrix() {
if (!GLpick::g_pickActive) return;
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
gluPickMatrix(
GLpick::g_OpenGL_pick[0], GLpick::g_OpenGL_pick[1],
GLpick::g_OpenGL_pick[2] * 2 + 1, GLpick::g_OpenGL_pick[3] * 2 + 1,
viewport);
}
In glu.h, gluPickMatrix()'s signature is GLAPI void GLAPIENTRY gluPickMatrix (GLdouble x, GLdouble y, GLdouble delX, GLdouble delY, GLint *viewport);. So, I attempted to change int g_OpenGL_pick[] = {0, 0, 0, 0}; to GLdouble g_OpenGL_pick[] = {0.0, 0.0, 0.0, 0.0};. Neither that nor casting the individual values to GLdouble worked.
What might I be overlooking? Or are there any concepts that could help narrow down my search?
Try moving the libgasandbox.a before all the -l options on the command line. So your command would look like this:
g++ -g -O2 -o chap1ex1 chap1ex1.o ../../libgasandbox/libgasandbox.a -lGL -lGLU -lglut
Order of arguments does matter for static linking, as described in this answer: things that depend on a library must come before that library. libgasandbox evidently depends on GLU, so putting it earlier should solve that error.
You might also need to move -lGL to the very end, if GLU or glut depend on it (I'm not sure whether they do).

Symbol(s) not found for architecture x86_64 (OpenGL with xcode)

I am very new to using OpenGL. The program I am trying to run is provided by my professor so I have not actually written any of it, I am having problems getting the program to run. The program is suppose to just make a white square on a black screen. I am using mac Sierra 10.12.2. Also I have already changed the deployment target to 10.8 because of the errors from compiling in anything later than that. Now when I try to build and run in xcode I get 2 errors.
These are the errors im getting,
Undefined symbols for architecture x86_64:
"exit(int)", referenced from:
myKeyboard(unsigned char, int, int) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Now here is the code exactly as I am trying to compile it.
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
const int screenHeight = 480; // window height is 480
const int screenWidth = 640 ; //window width is 640
// <<<<<<<<<<<<<<<<<<<<< Prototypes >>>>>>>>>>>>>>>>>>
void exit(int) ;
// <<<<<<<<<<<<<<<<<<<<<<< myInit >>>>>>>>>>>>>>>>>>>
void myInit(void)
{
glClearColor(1.0,1.0,1.0,0.0); // set white background color
glColor3f(0.0f, 0.0f, 0.0f); // set the drawing color
glPointSize(4.0); // a ?dot? is 4 by 4 pixels
glLineWidth(4.0); // a ?dot? is 4 by 4 pixels
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
// <<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT); // clear the screen
glBegin(GL_POINTS);
// glBegin(GL_LINE_STRIP) ;
// glBegin(GL_LINE_LOOP) ;
// glBegin(GL_POLYGON);
glVertex2i(289, 190); // Dubhe
glVertex2i(320, 128) ; // Merak
glVertex2i(239, 67) ; // Phecda
glVertex2i(194, 101) ; // Megrez
glVertex2i(129, 83) ; // Alioth
glVertex2i(75, 73) ; // Mizar
glVertex2i(74, 74) ; // Alcor
glEnd();
glFlush(); // send all output to display
}
// <<<<<<<<<<<<<<<<<<<<<<<< myKeyboard >>>>>>>>>>>>>>
void myKeyboard(unsigned char theKey, int mouseX, int mouseY)
{
switch(theKey)
{
case 'Q':
case 'q':
exit(-1); //terminate the program
default:
break; // do nothing
}
}
// <<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
int main(int argc, char** argv)
{
glutInit(&argc, argv); // initialize the toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode
glutInitWindowSize(640, 480); // set window size
glutInitWindowPosition(100, 150); // set window position on screen
glutCreateWindow("Big Deep - Type Q or q to quit") ; // open the screen window
glutDisplayFunc(myDisplay); // register redraw function
glutKeyboardFunc(myKeyboard); // register the keyboard action function
myInit();
glutMainLoop(); // go into a perpetual loop
}
Any help would be greatly appreciated!
You need to add the following near the top of your source file:
#include <stdlib.h>
and remove this line:
void exit(int) ;
First, you should always use the proper system headers to get the declarations of system library functions. This is especially true on macOS where the declaration can have important attributes which affect how the function is linked.
However, the lack of such attributes is not really what tripped you up in this case. The issue here is that you're building a C++ program. In C++, a function's argument types are part of its symbol name. You can see this in the error message you've quoted. But the exit() function is part of the C standard library. It's not natively a C++ interface. Its symbol name is _exit, with no indication of its argument count or types.
Your code has incorporated references to a symbol that translates to exit(int) while the actual symbol in the system library is just _exit. They don't match, so you get a symbol-not-found linker error.
The stdlib.h header takes special care to wrap its function declarations in extern "C" { ... } when it's included for a C++ translation unit. So, including that header to get the declaration tells the C++ compiler not to use a C++-style symbol name but to instead just use the C-style symbol name.
You could also "solve" the issue by putting extern "C" on the declaration of exit() in your own code, but that's the wrong approach. Just include the proper header.

GLFW: Compilation errors C++ [duplicate]

I am having some difficulties with codeblocks 10.05 recognizing the GLFW libraries on my machine. When I create an empty project, and copy paste this code found from this GLFW tutorial >> http://content.gpwiki.org/index.php/GLFW:Tutorials:Basics
#include <stdlib.h>
#include <GL/glfw.h>
void Init(void);
void Shut_Down(int return_code);
void Main_Loop(void);
void Draw_Square(float red, float green, float blue);
void Draw(void);
float rotate_y = 0,
rotate_z = 0;
const float rotations_per_tick = .2;
int main(void)
{
Init();
Main_Loop();
Shut_Down(0);
}
void Init(void)
{
const int window_width = 800,
window_height = 600;
if (glfwInit() != GL_TRUE)
Shut_Down(1);
// 800 x 600, 16 bit color, no depth, alpha or stencil buffers, windowed
if (glfwOpenWindow(window_width, window_height, 5, 6, 5,
0, 0, 0, GLFW_WINDOW) != GL_TRUE)
Shut_Down(1);
glfwSetWindowTitle("The GLFW Window");
// set the projection matrix to a normal frustum with a max depth of 50
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float aspect_ratio = ((float)window_height) / window_width;
glFrustum(.5, -.5, -.5 * aspect_ratio, .5 * aspect_ratio, 1, 50);
glMatrixMode(GL_MODELVIEW);
}
void Shut_Down(int return_code)
{
glfwTerminate();
exit(return_code);
}
void Main_Loop(void)
{
// the time of the previous frame
double old_time = glfwGetTime();
// this just loops as long as the program runs
while(1)
{
// calculate time elapsed, and the amount by which stuff rotates
double current_time = glfwGetTime(),
delta_rotate = (current_time - old_time) * rotations_per_tick * 360;
old_time = current_time;
// escape to quit, arrow keys to rotate view
if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS)
break;
if (glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS)
rotate_y += delta_rotate;
if (glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS)
rotate_y -= delta_rotate;
// z axis always rotates
rotate_z += delta_rotate;
// clear the buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw the figure
Draw();
// swap back and front buffers
glfwSwapBuffers();
}
}
void Draw_Square(float red, float green, float blue)
{
// Draws a square with a gradient color at coordinates 0, 10
glBegin(GL_QUADS);
{
glColor3f(red, green, blue);
glVertex2i(1, 11);
glColor3f(red * .8, green * .8, blue * .8);
glVertex2i(-1, 11);
glColor3f(red * .5, green * .5, blue * .5);
glVertex2i(-1, 9);
glColor3f(red * .8, green * .8, blue * .8);
glVertex2i(1, 9);
}
glEnd();
}
void Draw(void)
{
// reset view matrix
glLoadIdentity();
// move view back a bit
glTranslatef(0, 0, -30);
// apply the current rotation
glRotatef(rotate_y, 0, 1, 0);
glRotatef(rotate_z, 0, 0, 1);
// by repeatedly rotating the view matrix during drawing, the
// squares end up in a circle
int i = 0, squares = 15;
float red = 0, blue = 1;
for (; i < squares; ++i){
glRotatef(360.0/squares, 0, 0, 1);
// colors change for each square
red += 1.0/12;
blue -= 1.0/12;
Draw_Square(red, .6, blue);
}
}
and compile it using codeblocks it returns me this error:
/home/user/Graphics/Project_2/test.c|27|undefined reference to `glfwInit'|
/home/user/Graphics/Project_2/test.c|30|undefined reference to `glfwOpenWindow'|
......
.....
....
...
but when I create a simple *.c file and compile it with :
gcc myprog.c -o myprog -lglfw -lGL -lpthread
it works.. How can I make codeblocks work with GLFW??
thanks
Follow the following procedure.
First download the GLFW from here.
unzip the zip file
copy the glfw.h file from the include folder and paste to the folder "C:\Program Files\CodeBlocks\MinGW\include\GL"
copy all file (libglfw.a and libglfwdll.a ) from the lib_mingw folder
and paste to the folder "C:\Program Files\CodeBlocks\MinGW\lib"
glfw.dll file from the lib_mingw folder of unzip file and paste it
inside "C:\Windows\System32" floder. If you don't like to keep it in system32 then you can keep it with your project exe file.
Now while creating the GLFW project in code::blocks give the path C:\Program Files\CodeBlocks\MinGW" for glfw location
IF you are again confuse then go here for step by step procedure with image of every step.
Make sure that you have the correct type of glfw libs. ie x86 or x64 for your mingw compiler. 8 Hours of time searching for undefined reference errors ie linker problems to glfw.
Follow these instrucions:
http://codeincodeblock.blogspot.com/2011/02/setup-glfw-project-in-codeblock.html
I was having similar problems earlier with importing GLFW into codeblocks, and I recently found something that works for me.
I can see that you have already done the header installation correctly, but I will include that in this response so that you can double-check that everything is in tip-top condition.
I also recommend that you use the sample code within the 'Documentation' tab of glfw.org. It works really well for me, so I think it might for you as well.
Since you are using GLFW, I will assume that you want to use OpenGL in your application, so I will include the installation of OpenGL in the tutorial
A. Creating relevant folders
The first thing you will need to do is set up a location for library files and header files on your system. You can either creates these folders within a specified location on your drive, or you can create these folders within your code::blocks project.
In my case, I created a 'lib' and 'head' folder in my code::blocks project folder.
B. Downloading & Installing necessary media
GLFW:
Head over to GLFW.org, and hit 'Downloads'.
Click '32-bit Windows binaries', and open the 'glfw-version.bin.WIN32' within zip file that was downloaded.
Open the 'include' folder and copy the enclosed GLFW folder to the 'head' folder you created in part A.
Open up 'glfw-version.bin.WIN32' again, and pick the 'lib' folder that corresponds to your compiler. Because I am using the MinGW GCC compiler, I picked 'lib-mingw'. To find your compiler, go to code::blocks, click settings, and then click 'compiler...'. Your compiler is found in the 'selected compiler' section of the window that appears.
Once you've found the 'lib' folder that you will use, open it, and copy all of the files within into the 'lib' folder that you created during part A.
GLEW (OpenGL):
Go to this link
Open the folder that is within the downloaded zip.
Go to 'lib', then release, then Win32, and copy all of the files located there into the 'lib' folder you created in step A.
Go back to the folder within the downloaded zip.
Enter the 'include' directory, and copy the 'GL' folder into the 'head' folder created in part a.
At this point, your 'head' folder should contain 'GLFW' and 'GL' folders, and your 'lib' folder should contain 'glew32', 'glew32s', and all of the library files from GLFW for your compiler.
C. Configuring your code::blocks project
Once you've opened your project, right click on the name of your project in your workspace, and hit 'build options...
On the left of the window that has appeared, make sure 'Debug' is selected.
Next click the 'linker settings' tab, and add the following libraries: 'glfw.3', 'gdi32', and 'opengl32'.
Next, in the 'Search Directories' tab, select the 'Compiler' tab.
Add the path to your 'head' folder. If the head folder was created within your project folder, you can just type 'head'
Also in the 'Search Directories' tab, select the 'Linker' tab.
Add the path to your 'lib' folder. Again, if the lib folder was created withing your project folder, you can just type 'lib'.
Hit 'OK' at the bottom of the window.
D. Build and Run your code :)! Hope this helps!

Unhandled Exception using glGenBuffer on Release mode only - QT

I'm having some trouble while compiling my project on Windows 7 using Qt 4.8 on Release mode. Everything works fine on Debug, but on Release I get an Unhandled Exception: 0xC0000005: Access violation.
I narrowed it down to the line where this happens, which is when I generate my Pixel Buffers.
My first guess would be wrong DLLs loading, but I checked the executable with Dependency Walker and every DLL loaded is correct.
Here goes some of my code:
class CameraView : public QGLWidget, protected QGLFunctions;
void CameraView::initializeGL()
{
initializeGLFunctions(this->context());
glGenBuffers(1, &pbo_); //<<<<< This is where I get the unhandled exception on Release mode
glBindBuffer(QGLBuffer::PixelUnpackBuffer, pbo_);
glBufferData(QGLBuffer::PixelUnpackBuffer, 3 * sizeof(BYTE) * image_width_ * image_height_, NULL, GL_STREAM_DRAW);
...
}
Again, this works great on debug. Why would this only happen on Release?
I got it.
Seems like this issue is related to this one:
https://forum.qt.io/topic/12492/qt-4-8-qglfunctions-functions-crash-in-release-build
and there's a bug report that may be related also:
https://bugreports.qt.io/browse/QTBUG-5729
Perhaps the initializeGLFunctions() method is not getting all function pointers for the GL extension functions, I don't really know why but this seems to be it.
The solution for me was to stop using Qt's GL extensions and start using glew.
So, here's what worked for me:
#include <QtGui/QtGui>
#include <gl/glew.h>
#include <QtOpenGL/QGLWidget>
class CameraView : public QGLWidget;
void CameraView::initializeGL()
{
//initializeGLFunctions(this->context());
GLenum init = glewInit();
// Create buffers
glGenBuffers(1, &pbo_);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_);
glBufferData(GL_PIXEL_UNPACK_BUFFER, 3 * sizeof(BYTE) * image_width_ * image_height_, NULL, GL_STREAM_DRAW);
// Set matrixes
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glOrtho(0, this->width(), 0, this->height(), 0, 1);
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
}
Be sure that glew.h is included before any QTOpenGL headers or else you'll get a compilation error.