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).
Related
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':
I've compiled the following code with gcc on cygwin:
#include <cairo.h>
int
main (int argc, char *argv[])
{
cairo_surface_t *surface =
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 240, 80);
cairo_t *cr =
cairo_create (surface);
cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size (cr, 32.0);
cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
cairo_move_to (cr, 10.0, 50.0);
cairo_show_text (cr, "Hello, world");
cairo_destroy (cr);
cairo_surface_write_to_png (surface, "hello.png");
cairo_surface_destroy (surface);
return 0;
}
The code is from the official cairo homepage, so I assume it should run.
compiling with this command:
i686-w64-mingw32-gcc kairo.c -o kairo.exe -I /usr/include/cairo/ -L /usr/lib -lcairo
It compiles without a problem, but trying to open the .exe (regularly in the windows file explorer) throws this error:
"The program could not be started, since cygXau-6.dll is missing on your PC. Reinstall the program, to fix the problem."
(roughly translated from german)
But that dll seems to be cygwin-specific and I'd like to not have my .exe depend on cygwin.
I'm new to C (coming from a webdev background) and the whole concept of linking is foreign to me, but I understand that I'll likely need to include the DLLs somewhere near the executable, and maybe link to it with the -I flag.
I don't even know if this is the right approach when building cross-platform C, but my first goal would be to simply get this snippet running under windows.
It does work when compiling with "regular" gcc and running it as kairo.o in cygwin - it produces the desired result, a png with "Hello, World".
The theory that I've compiled some sort of Hybrid seems to confirm itself - I've checked the exe with dependencywalker and got the following output.
Error: At least one required implicit or forwarded dependency was not found.
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.
So I guess I need to find out where I can get the mingw-binaries and header files for cairo and link to those. I just have no idea where to get them.
according to apt-cyg mingw-i686-cairo is installed - I linked to the files in the header file and it compiled as well, but now executing the .exe gives me another error:
the application could not be started (0x000007b).
the following command was used to compile this time:
i686-w64-mingw32-gcc kairo.c -o kairo.exe -I /usr/i686-w64-mingw32/sys-root/mingw/include/cairo/ -L /usr/i686-w64-mingw32/sys-root/mingw/bin/ -lcairo
So I've done some more research and it seems I might still have some mixup between files compiled for 32 and 64 bits. Might have to do with the dlls
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 6 years ago.
i tried to use make on my c source code and created executable file. but the executable file did not work the intended task. even if the make file compiled and produced the executable file when i try to compile the .c file individually it gave many undefined reference problem
The errors are
/tmp/cc4tx0BG.o: In function `main':
cubist.c:(.text+0xdc): undefined reference to `Of'
cubist.c:(.text+0xe7): undefined reference to `Of'
cubist.c:(.text+0xfa): undefined reference to `Of'
cubist.c:(.text+0x10f): undefined reference to `KRInit'
cubist.c:(.text+0x114): undefined reference to `ExecTime'
cubist.c:(.text+0x127): undefined reference to `PrintHeader'
cubist.c:(.text+0x139): undefined reference to `Of'
[...]
cubist.c:(.text+0xb79): undefined reference to `MaxAtt'
cubist.c:(.text+0xb83): undefined reference to `InitialiseEnvData'
cubist.c:(.text+0xb8a): undefined reference to `XVAL'
cubist.c:(.text+0xb93): undefined reference to `CrossVal'
cubist.c:(.text+0xb9a): undefined reference to `SingleCttee'
cubist.c:(.text+0xb9f): undefined reference to `ExecTime'
cubist.c:(.text+0xbab): undefined reference to `Of'
collect2: error: ld returned 1 exit status
please, could any body tells how to use make and building executables in Linux work.
I think (not sure) that you are saying that you successfully produced an executable using Make (at least that's how I interpret "use make on my c source code and created executable file" -- do correct me if I'm wrong!). If that's the case, invoke make like this: make -B --trace, and you'll see the exact commands that were used to build the executable, and then you'll hopefully know which compiler/linker flags or libraries you missed while trying to build stuff manually.
When using Cygwin and GCC under Win 7 and the quad precision library:
gcc -c lquad.c
... this runs OK, but
gcc lquad.o
... produces the following error:
/tmp/ccLM2lOn.o:lquad.c:(.text+0xdb3): undefined reference to `sqrtq'
collect2: error: ld returned 1 exit status
I have #include quadmath.h in a C source, and the __float128 type works, but not the functions (e.g. sqrtq above). This header file has all the relevant externs, e.g.:
extern __float128 sqrtq (__float128) __quadmath_throw;
I found a dll cygquadmath-0.dll which definitely has these functions in it. It is in 3 places in the Cygwin installation. Additionally, I copied it to Windows\System, but that did not help.
There is a related question here, but nothing helped me there and it is not exactly the same error: Quadruple Precision in C++ (GCC)
You are looking for a compiler solution when what you need is a linker solution:
Your code is compiling as it should, so no change in the code would solve your problem:
/tmp/ccLM2lOn.o:lquad.c:(.text+0xdb3): undefined reference to `sqrtq'
collect2: error: ld returned 1 exit status
The undefined reference to errors indicate a function needed by your object is in another library.
As suggested by #Marc Glisse, try adding -lquadmath to your linker line.
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"