OpenGL program failing to link? - c++

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).

Related

`make` compilation for OpenGL works on VSCode's terminal, but gives `symbol(s) not found for architecture x86_64` on regular terminal (macOS M1)

OS: macOS Ventura version 13.1, on M1.
I'm compiling a simple OpenGL program. I have a makefile as shown below:
CXX = clang++
CXXFLAGS = -I/opt/homebrew/Cellar/glew/2.2.0_1/include -L/opt/homebrew/Cellar/glew/2.2.0_1/lib -w
LIBS = -lGLEW.2.2.0 -framework OpenGL -framework GLUT
SOURCES = t2.cpp
OBJ = $(SOURCES:.cpp=.o)
TARGETS = $(SOURCES:.cpp=)
all: $(TARGETS)
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $# $<
$(TARGETS): %: %.o
$(CXX) $(CXXFLAGS) -o $# $< $(LIBS)
clean:
rm -f $(OBJ) $(TARGETS) *.o
.PHONY: all clean
My simple t2.cpp:
#include <iostream>
#include <GL/glew.h>
#include <GLUT/glut.h>
void resizeCB(int width, int height)
{
/* use the full view port */
glViewport(0, 0, width, height);
/* use 2D orthographic parallel projection */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, width, 0.0, height);
}
typedef struct point2D
{
int x;
int y;
} Point2D;
Point2D roof[3];
Point2D house[4];
void initGeom()
{
// initialize the roof
roof[0].x = 270;
roof[0].y = 340;
roof[1].x = 450;
roof[1].y = 340;
roof[2].x = 360;
roof[2].y = 400;
house[0].x = 285;
house[0].y = 270;
house[1].x = 435;
house[1].y = 270;
house[2].x = 435;
house[2].y = 340;
house[3].x = 285;
house[3].y = 340;
}
// clear the window and fill it with white colour
// set up gl colour to white
void renderCB()
{
// glClearColor(1.0, 1.0, 1.0, 0.0);
// clearing up the canvas with the specific colour
initGeom();
glClear(GL_COLOR_BUFFER_BIT);
// swap the buffers (using double buffers
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_TRIANGLES);
for (int i = 0; i < 3; ++i)
{
glVertex2iv((GLint *)&roof[i]);
}
glEnd();
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_POLYGON);
for (int i = 0; i < 4; ++i)
{
glVertex2iv((GLint *)&house[i]);
}
glEnd();
glFlush();
glutSwapBuffers();
// return;
}
int main(int argc, char **argv)
{
int winId;
// initialize GLUT and pass it the command variables
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(1024, 768);
glutInitWindowPosition(100, 100);
winId = glutCreateWindow("Tutorial 02");
GLenum res = glewInit();
if (res != GLEW_OK)
{
printf("Error - %s \n", glewGetErrorString(res));
return (-1);
}
// print OpenGL information
printf("Renderer: %s \n", glGetString(GL_RENDERER));
printf("OpenGL version: %s \n", glGetString(GL_VERSION));
printf("OpenGL shading language version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
glutReshapeFunc(resizeCB);
glutDisplayFunc(renderCB);
glutMainLoop();
return (0);
}
I've noticed that when I compile via make on VSCode's integrated terminal, it works, output:
clang++ -I/opt/homebrew/Cellar/glew/2.2.0_1/include -L/opt/homebrew/Cellar/glew/2.2.0_1/lib -w -c -o t2.o t2.cpp
clang++ -I/opt/homebrew/Cellar/glew/2.2.0_1/include -L/opt/homebrew/Cellar/glew/2.2.0_1/lib -w -o t2 t2.o -lGLEW.2.2.0 -framework OpenGL -framework GLUT
But, when I compile via make on a regular terminal, I get this:
clang++ -I/opt/homebrew/Cellar/glew/2.2.0_1/include -L/opt/homebrew/Cellar/glew/2.2.0_1/lib -w -c -o t2.o t2.cpp
clang++ -I/opt/homebrew/Cellar/glew/2.2.0_1/include -L/opt/homebrew/Cellar/glew/2.2.0_1/lib -w -o t2 t2.o -lGLEW.2.2.0 -framework OpenGL -framework GLUT
Undefined symbols for architecture x86_64:
"_glewGetErrorString", referenced from:
_main in t2.o
"_glewInit", referenced from:
_main in t2.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [t2] Error 1
I'm honestly stumped as to why. I've restarted my computer, and now everything works as expected. WHAT???
I mean, I was expecting make to be deterministic across both terminals. I can't say I've tried anything meaningful aside from restarting my computer, I'm quite confused as to discrepancies -- this is probably the first I've encountered such a bug. I'm not sure if I'll encounter such a bug again, but I do not want to restart my computer as a fix -- and I want to understand why this is happening.
My best (terrible) guess has something to do with VSCode's terminal makefile invoking the arm64-apple-darwin<version> clang++ binary, but the regular terminal's makefile invoked the x86_64-apple-darwin<version> clang++ binary.
But I can't for the life of me figure out why, as the makefile does not ever specify the architecture, and would assume the default (ARM).
I want to get to the bottom of this, this is one really interesting bug. Any help appreciated. Thanks!

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).

Update multiple locations of one-dimensional array with minimum/one line(s) of code

I have one-dimentional array initialized globally in C++
Gfloat cone1[] = { 0.0f, 2.4f, -11.0f, 30.0f, -1.5, 0.0, 0.0 };
I want to update its all values with different numbers of my choice within my main function writing minimum/one line(s) of code.
Is it possible?
I don't want to do like :-
cone1[0] = 12f , cone1[1] = 56f; ...
If you are willing to switch to using std::vector or std::array you can use uniform initialization and an assignment.
The following example uses std::vector for a variable sized array.
#include <vector>
int main()
{
std::vector<Gfloat> cone1 { 0.0f, 2.4f, -11.0f };
cone1 = { 30.0f, -1.5, 0.0 };
}
The following example uses std::array for a fixed sized array.
#include <array>
int main()
{
std::array<Gfloat, 3> cone1 { 0.0f, 2.4f, -11.0f };
cone1 = { 30.0f, -1.5, 0.0 };
}
If you have the values you want to replace with in another array, you could use std::copy:
std::copy(newCone, newCone + 7, cone1);
If you want to do it on one line, then do it on one line:
cone1[0] = 12f; cone1[1] = 56f; ... // and so on
Making it all appear on one line / aiming for minium code though doesn't make it any more efficient though - readable code across more lines is better than tightly packed code that takes up less space in a file.
I solved my problem as #Captain Obvlious suggested.
Replace -c -fmessage-length=0 with -c -fmessage-length=0 -std=c++11
Make sure you leave a space between -c -fmessage-length=0 and -std=c++11
Otherwise your project will show that it is build but won't create .exe file.

SDL, headers and strange errors..?

I'm learning my way around SDL and everything's been working fine up until now. Whenever I try to compile my code, I get the following error:
Undefined symbols for architecture x86_64:
"Tile::draw(SDL_Surface*)", referenced from:
_SDL_main in ccTWWnIW.o
"Tile::update()", referencedfrom:
_SDL_main in ccTWWnIW.o
"Tile::Tile(int)", referenced from:
_SDL_main in ccTWWnIW.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
What's strange about it is that it only occurs when I include the "level.h" header in my "player.cpp" bit of code.. while including "level.h" in my main program doesn't set off the compiler at all. I make use of the class defined in "level.h" in both the main program - to instantiate the tiles, update them and blit them to the screen - and in "player.cpp" - to check for collisions. I commented out all the parts of "player.cpp" that made use of any components defined in "level.h" and I still got the compiler errors. I've included the same SDL headers as in "player.cpp" and have set the flags accordingly on my compiler so I really don't see why the "ld: symbol(s) not found for architecture x86_64" message is cropping up.
The bits of "level.cpp" that are referenced in the error message:
#include "SDL.h"
#include "SDL_image.h"
#include <iostream>
#include "Variables.h"
#include <cstdlib>
#include "level.h"
class Tile{
public:
int damage;
int velocity;
bool solid;
SDL_Rect position;
SDL_Rect crop;
SDL_Surface* image;
Tile(int type);
~Tile();
bool update();
void draw(SDL_Surface* target);
};
...
Tile::Tile(int type){
if(type == 0){
damage = 0;
velocity = 20;
solid = true;
position.x = 600;
position.y = rand() % 500;
SDL_Surface* temp_image = IMG_Load_RW(SDL_RWFromFile("spritesheet.png", "rb"), 1);
image = SDL_DisplayFormatAlpha(temp_image);
SDL_FreeSurface(temp_image);
crop.x = 0;
crop.y = 0;
crop.w = 50;
crop.h = 50;
}
}
...
bool Tile::update(){
position.x = position.x - velocity;
if(position.x <= 0) {
position.x = 700;
position.y = rand()%500;
}
else return 0;
}
...
void Tile::draw(SDL_Surface* target){
SDL_BlitSurface(image, &crop, target, &position);
}
I know that the coding style is rubbish, this is only me messing about and learning SDL.
I'm not sure what the exact issue is based on this, but there are a few things you should do.
Put header guards around your headers, eg. in level.h, you would want something like:
#ifndef LEVEL_H_
#define LEVEL_H_
at the top, and:
#endif
at the bottom. This is to prevent symbols from being defined multiple times when the file is included by several different source files.
Second, you need to put class definitions into header (.h) files not .cpp files. It would probably be much nicer in your case to move the tile stuff into its own files (tile.h, tile.cpp) but either way the tile class definition needs to be in a header file.

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!