Problems with GLEW using MinGW: Undefined reference to '_imp__glewExperimental.' - c

I'm using GLEW version 1.10.0 with MinGW (Through the CodeBlocks IDE), running on Windows 8. I downloaded the Windows binaries from the GLEW website, and have been linking to the libraries included with that build.
I have a linking problem that I just can't seem to find an answer to. I have followed the installation on the GLEW home page. I have referenced the linker to the glew32.lib, as well as the other required libs such as opengl32 and glu32.
Unfortunately, compiling this code (I'm also using GLFW for context/window management):
#include <stdio.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#define TRUE 1
#define FALSE 0
int main()
{
GLFWwindow *window;
if (!glfwInit())
return -1;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3.0);
window = glfwCreateWindow(640, 480, "Hello World!", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
// Initialize GLEW
glewExperimental=TRUE;
GLenum err = glewInit();
if (err!=GLEW_OK)
fprintf(stderr, "Could not initialize GLEW!");
printf("%s\n", glGetString(GL_VERSION));
while (!glfwWindowShouldClose(window))
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
I get the error:
*undefined reference to imp_glewExperimental*
Even though I'm new to C, as far as I understand, this means that I'm referring to something which has no definition, which generally means the library is missing. In this case though, I have included the library, and I got no errors whatsoever about the other GLEW references I make, such as glewInit, which I feel it should also complain about should it be a problem of missing libraries.
I've tried to search the web but I simply haven't found anything on this problem.
Anyone got any ideas? :)
Thank you all very much for your time. It is much appriciated.

It seems I have solved the problem. For anyone who'd like to know, it appears the problem was the pre-build Windows binaries from the GLEW website, because they originate from Visual Studio (they are .lib files). I was using MinGW to do compilation. As soon as I tried to compile GLEW myself using MinGW to create a .a archive, it worked.
There's already a great answer here on stackoverflow on how to compile GLEW for MinGW, and can be found right here.

try to put #define GLEW_STATIC on the first line:
#define GLEW_STATIC
#include <stdio.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
and put -lglew32s first in the link libraries table.
codeblocks:
project > build options... > linker settings > add glew32s
then click the up arrow until it get first

Related

glfw code not running and skipping after compiling without errors

I am trying to learn the glfw library in C. I have installed the glfw pre-compiled binaries from their official website. I have moved the 32-bit libs from the pre-compiled binaries zip file to my mingw-gcc's lib folder and the include files from the zip file to the mingw-gcc's include folder. I am trying to make the a window using the library and c. I am using vscode as my editor. This is my code:
#include <stdio.h>
#include <windows.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
int main() {
printf("Hello World!\n"); //test line
GLFWwindow * window;
if (!glfwInit) {
printf("glfw3 initialization failed");
return -1;
} else {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window) {
printf("Could not create window.");
glfwTerminate();
return -1;
} else {
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window)) {
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
}
}
I am using the following command to compile my code:
gcc main.c -lglfw3dll -lopengl32
The program compiles without any errors but when I run the compiled .exe, nothing happens. I even tried to print hello world before the code runs, but even that doesn't print. What is happening and how do I fix it?
Edit: I fixed the problem by adding the glfw libraries to my system path. now it is working fine
You are doing:
if (!glfwInit)
This just checks to see if the address of glfwInit is non-zero.
It does not call/invoke it.
To invoke it, you want:
if (! glfwInit())
UPDATE:
the code still is doing nothing. it is still not printing the test hello world –
The Parallax
The "Hello World" in your glfwCreateWindow call just sets the window title.
The first question is: Does a window come up on the screen? That is, what, exactly, do you mean by the code is doing nothing ...?
I don't see any drawing calls in your code.
Your code is similar to the example code from: https://www.glfw.org/documentation.html#example-code with some small exceptions but not exactly the same.
In the link, it has:
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
at the top of the loop.
AFAICT, this will clear the buffer to the background color.
You may need/want to add some drawing calls to put up a rectangle (e.g.) after the glClear call.
Otherwise, you may get the window to come up, but it won't have anything in it.
Here is the step by step tutorial: https://www.glfw.org/docs/3.3/quick.html
It has a more complete/extensive example code. I'd use the code in the two links as a model.
I fixed the problem by adding the glfw libraries to my system path. now it is working fine

Correct command line parameters for gcc compilation of SDL

I recently started SDL2.0 programming.
I did a lot of researches and i tried all but i still get those "undefined reference" errors for all the SDL functions:
undefined reference to `SDL_Init'|
undefined reference to `SDL_GetError'|
undefined reference to `SDL_Quit'|
||=== Build finished: 3 errors, 0 warnings ===|
on that simple test program:
#include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) {
fprintf(stderr, "\nUnable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);
return 0;
}
If i have to guess the problem occurs due to the wrong command line syntax.
In this case what should be the correct one?
You aren't linking to the SDL libraries correctly.
Add the following lines int Other Linker Option
-lSDL -lSDLmain
mingw32
SDLmain
SDL
Also You need to check setup for how to compile SDL in codeblock
http://wiki.codeblocks.org/index.php?title=Using_SDL_with_Code::Blocks
http://lazyfoo.net/SDL_tutorials/lesson01/windows/codeblocks/
If it's not too late then try from the beginging to how to set up SDL in codeblock and successfully run it? Below link provide you exact steps for it.
http://www.dreamincode.net/forums/topic/57275-setting-up-codeblocks-to-work-with-sdl/
You might have not linked SDL2 correctly to your CodeBlocks project and not referred to SDL2 correctly in your code.
1:
Go to "Linker options" in "Build Options" menu and make sure you have added these library's to your project like this:
Library's to include in linker options
Importent!: save project before running it after adding/changeing library's.
2:
Change:
#include "SDL.h"
to this:
#include <SDL2/SDL.h>
if you still encounter problems compiling and running it, it's most likely either, your SDL2 files not placed correctly in the compiler's folders, or your using an version of gcc with some missing tools.
These Youtube video's explain everything in great detail:
1: https://www.youtube.com/watch?v=x0LUf7Ibpi0
2: https://www.youtube.com/watch?v=EtUw_7CvRRo

cannot link with glew32 for "glewInit()"

#include <gl/glew.h>
int main()
{
glewInit();
glActiveTexture(GL_TEXTURE0);
return true;
}
I've already set up header search path, library search path, glew32.lib & opengl32.lib. However Visual Studio 2012 cannot link with
error LNK2019: _imp_glewInit
The strangest thing is that I can link glActiveTexturet ( or *__glewActiveTexture* ), but I cannot link glewInit
OK finally I got it...I use glew from cuda, which absolutely has some problems... I overwrite glew.h & glew32.lib from sourceforge, which works now...

Unable to link libpng or zlib in Eclipse with MinGW C linker

I'm new to external static libraries in C, and i'm having trouble adding pnglib (or any library) to Eclipse. Im using Eclipse v3.3.2 with mingw on windows 7 64bit.
I first followed these instructions to install libpng and zlib: http://wiki.openttd.org/Compiling_on_MinGW
Then in Eclipse under C/C++ Build -> Settings ->Tool Settings -> MinGW C Linker -> Libraries
I added: "png" then "z" in Libraries (-l)
and: "C:\MinGW\libpng-1.5.12" then "C:\MinGW\zlib-1.2.7" in the Library search path (-L)
If I execute the simplest code:
#include <stdio.h>
#include <zlib.h>
#include <png.h>
int main(void) {
printf("foo\n");
unsigned char header[8];
//png_sig_cmp(header, 0, 0);
return 0;
}
It works fine, however as soon as i uncomment the function, the code compiles (without error/warning), but does absolutely nothing, (not even the print statement). This happens when I use ANY function from an external library.
I assume it can read the headers but there's funny business with finding function definitions.
I have no idea where i went wrong.
I'm sure I have missed something trivial!

Using GCC (MinGW) to compile OpenGL on Windows

I've searched on google and haven't been able to come up with a solution.
I would like to compile some OpenGL programming using GCC. In the GL folder in GCC I have the following headers:
gl.h
glext.h
glu.h
Then in my system32 file I have the following .dll
opengl32.dll
glu32.dll
glut32.dll
If I wanted to write a simple OpenGL "Hello World" and link and compile with GCC, what is the correct process?
I'm attempting to use this code:
#include <GL/gl.h>
#include <GL/glut.h>
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitWindowSize(512,512);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("The glut hello world program");
glutDisplayFunc(display);
glClearColor(0.0, 0.0, 0.0, 1.0);
glutMainLoop(); // Infinite event loop
return 0;
}
I am using WindowsXP and GCC version 3.4.5. Thank you in advance for the help.
You probably want to run gcc like this:
gcc -g -Wall hello_gl.c -lopengl32 -lglu32 -lfreeglut
Unfortunately GLUT does not come preinstalled on Windows.
GLUT is a library that takes care of the (platform specific) job of creating a window and graphic context for you. Many OpenGL samples use it.
The official GLUT port to Win32 is available here but it's a bit dated.
I suggest you use the compatible freeglut library instead. You can use this tutorial for setting up freeglut with Mingw32

Resources