problems with openGl on eclipse - c

I'm working on Windows XP I have portable version of Eclipse Galileo, but I didn't find there glut so I decided to add it using this link I made all steps and and now I'm trying to compile this code
#include "GL/glut.h"
#include "GL/gl.h"
#include "GL/glu.h"
///////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);
// Flush drawing commands
glFlush();
}
///////////////////////////////////////////////////////////
// Setup the rendering state
void SetupRC(void)
{
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}
///////////////////////////////////////////////////////////
// Main program entry point
void main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800,600);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
SetupRC();
glutMainLoop();
}
and I have this errors
Simple.o: In function `RenderScene':
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:16: undefined reference to `_imp__glClear'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:20: undefined reference to `_imp__glFlush'
Simple.o: In function `SetupRC':
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:27: undefined reference to `_imp__glClearColor'
Simple.o: In function `main':
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:34: undefined reference to `glutInit'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:35: undefined reference to `glutInitDisplayMode'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:36: undefined reference to `glutInitWindowSize'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:37: undefined reference to `glutCreateWindow'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:38: undefined reference to `glutDisplayFunc'
C:/Documents and Settings/Administrator/Desktop/workspace/open/Debug/../Simple.c:42: undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status
please can somebody help me, thanks in advance

It looks like you're not linking the OpenGL, GLU or GLUT libraries. You need to tell Eclipse to link them, and you need to tell it the directories where they're stored (at least with most IDEs, the two operations are separate from each other).
If memory serves, openGL itself will be opengl32.lib. If it installed reasonably to start with, the IDE will probably already know the location for this library (i.e., it's a normal part of Windows, and the library will be along with the other normal Windows libraries). The glu functions are in glu32.lib, which should be in the same place.
Glut will normally be in a file named glut32.lib. Assuming you installed Glut in the root directory of your C drive, it would typically be at "C:\glut-3.7\lib\glut".

It seems that you have missed to add the libraries and the linker cannot find them. Make sure that the correct libraries are specified in the Libraries dialog. I don't have a Eclipse installation here but this dialog should be somewhere around `Right click project -> Properties -> Libraries/C++ Linker"

Related

Executing legacy opengl code in codeblocks

I have an old program that uses legacy opengl. I am attempting to run the code, but I have been stumbling into some errors. I installed freeglut and attempted to link it and add the includes, and while it seems to execute, I get an error in the process that states:
undefined reference to `_imp___glutInitWinExit#12
The bit of code in the freeglut_std.h header file that is causing the error is located at:
static void FGAPIENTRY FGUNUSED glutInit_ATEXIT_HACK(int *argcp, char **argv_ { _glutInitWithExit(argcp, argv, exit); }
This is line 637 of the code, so I presume I linked freeglut properly, but for some reason is stopping just short of execution. I am not sure what steps I should take from here, and any help is appreciated. Thank you.
Edit: Build log (a snippet of it) -
C:/Program Files (x86)/CodeBlocks/MinGW/include/GL/freeglut_std.h:637: undefined reference to `_imp____glutInitWithExit#12'
obj\Debug\curve.o: In function `glutCreateWindow_ATEXIT_HACK':
C:/Program Files (x86)/CodeBlocks/MinGW/include/GL/freeglut_std.h:639: undefined reference to `_imp____glutCreateWindowWithExit#8'
obj\Debug\curve.o: In function `glutCreateMenu_ATEXIT_HACK':
C:/Program Files (x86)/CodeBlocks/MinGW/include/GL/freeglut_std.h:641: undefined reference to `_imp____glutCreateMenuWithExit#8'
obj\Debug\curve.o: In function `curve_buildLine':

OpenGL - Undefined references to GLUT [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 years ago.
I'm having a problem getting openGL to work on Windows 7 using MinGW at the moment. I'm following the steps found here: https://www.opengl.org/wiki/MinGW
I have installed MinGW and all of it's basic installation files. I have added the elements required to my PATH variable. I have downloaded and placed the GLUT files in the correct directories as described in the link above. Even so, with the below code I get the subsequent errors.
#include <GL/glut.h>
void display (void)
{
glClear (GL_COLOR_BUFFER_BIT);
glBegin (GL_POLYGON);
glVertex2f (-0.5, -0.5);
glVertex2f (-0.5, 0.5);
glVertex2f (0.5, 0.5);
glVertex2f (0.5, -0.5);
glEnd ();
glFlush ();
return;
}
int main (int argc, char **argv)
{
glutInit (&argc, argv);
glutCreateWindow ("simple");
glutDisplayFunc (display);
glutMainLoop ();
}
The command used to compile this program is:
gcc firstProg.c -o firstProg.exe glut32.lib -lopengl32 -lglu32
The error is as follows (taken from the cmd):
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x1c): undefined
reference to `__glutInitWithExit'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x37): undefined
reference to `__glutCreateWindowWithExit'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x52): undefined
reference to `__glutCreateMenuWithExit'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x66): undefined
reference to `_imp__glClear'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x74): undefined
reference to `_imp__glBegin'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x8c): undefined
reference to `_imp__glVertex2f'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xa4): undefined
reference to `_imp__glVertex2f'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xbc): undefined
reference to `_imp__glVertex2f'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xd4): undefined
reference to `_imp__glVertex2f'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xdb): undefined
reference to `_imp__glEnd'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0xe2): undefined
reference to `_imp__glFlush'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x11f): undefine
d reference to `glutDisplayFunc'
C:\Users\Dylan\AppData\Local\Temp\cciCuMP6.o:firstProg.c:(.text+0x124): undefine
d reference to `glutMainLoop'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\D
ylan\AppData\Local\Temp\cciCuMP6.o: bad reloc address 0x20 in section `.eh_frame
'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link
failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Anyone here have any idea how to solve these errors? I've tried uninstalling and reinstalling MinGW as well as placing the GLUT files within the required directories again but to no avail.
Step 1: Make sure you have a properly built GLUT library that matches your compiler toolchain.
Step 2: Actually add GLUT to the list of libraries to link to.
GLUT is a 3rd party library, that's not part of OpenGL (in any way).

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

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

Including a static library in a C project (Eclipse)

I'm currently developing an application using SDL. In order to utilize it, I have already added the library and header files in the project's settings under C/C++ Build -> Settings -> Tool Settings -> Libraries/Includes. However, when I try to build a test program like
#include <stdio.h>
#include <SDL/SDL.h>
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Quit();
return 0;
}
I get this beautiful error message during the link process:
d:/programme/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a(main.o): In function main':
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference toWinMain#16'
Which is rather weird, given that the directory C:\MinGW doesn't even exist at all.
The command used for linking is this one:
gcc "-LD:\Programme\SDL\lib" -o test.exe test.o -lsdl
After two hours of trying to get a library link to work, I'm pretty confused and have no idea what I'm doing wrong. Help would be appreciated.
It looks like you are building a Windows GUI application, which requires a WinMain, while your code only provides a main function which would be for console applications.
So if this is supposed to be a console application, you must adjust your linker settings accordingly, or you must declare a WinMain.

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