compiling problem

i compile a glfw3 and glew2 program with g++ i done the linking correctly this is the command line:

C:\Users\nidal\Desktop\united revolution>g++ main.cpp -L"lib" -lglfw3dll -lglew32dll

but only the function glDrawArrays still undefined

C:\Users\nidal\AppData\Local\Temp\ccdc4xgb.o:main.cpp:(.text+0x2c6): undefined reference to `glDrawArrays@12'

other such glDisableVertexAttribArray glBindBuffer... are defined and when i delete it the program compiled and the window appear

i use cmake to generate a codeblock project from glew2.0.0 and i buid the nessecary libraries
then i use a text editor and the compiler without IDE(I hate all IDEs) sorry
Last edited on
Are you sure you have provided a function definition for glDrawArrays ? That is normally a reason why one gets linker errors. Did you qualify the function definition with the class name as in :

1
2
3
MyClass::glDrawArrays() {

}


Can you show the code, for where this function is called, and the function declaration and definition?




This has probably nothing to do with with your particular problem, but one should always compile with a high level of warnings, at least:

g++ -std=c++14 -Wall -Wextra -pedantic-errors -o executablefilename

If you don't have a compiler that supports c++14, try to get the latest version, or use -std=c++11

Despite these seemingly comprehensive options, there are even more warning options that come in handy:

http://www.cplusplus.com/forum/general/183731/#msg899203

Warnings are your friend, they help show potential problems with your code. Code may compile without errors, but the warnings point to problems which cause the program to fail at runtime.

If one wants to be super pedantic, then use the option -Werror , this makes all warnings into errors.

When I am coding, I am not finished until my code is free of all warnings and errors.

It's worth reading the compiler manual if you have time - there are a zillion options:

https://gcc.gnu.org/onlinedocs/

Good luck !!


[I linked my program] correctly
Since you're getting linker errors, it seems likely you're mistaken.

glDrawArrays is defined in libGL; you need to link with that too.
g++ main.cpp -Wall -Wextra -pedantic -L"lib" -lGL -lglfw3dll -lglew32dll

Last edited on
i cant find libGl in the default mingw library folder. so i think that i have to build opengl from source code ? i work under windows
Last edited on
you should have the files in their own folder on windows if you downloaded / installed / etc the tools.

You shouldn't have to try to compile opengl. You can, but you don't have to.

so should i copy the libgl library to my lib folder?or what. because i get file not found error when i compile and link to libgl note that i dont have visual studio
Last edited on
you can do that, but the right way is to use the path to the library in the link command. Just put "c:\yourfolder\etc\gl\gl.lib" (example ... its up to you to figure out the exact path and file)

you need quotes if the path has a space. If not they are optional

you can also add the folder to your window's path. You probably have to do this for the dlls so the executable can see them. For the libs, I don't know if your tool searches the win path or not.

Last edited on
thanks i know but where can i find libgl i cant find it in my mingw default lib folder, in windows directory any where. maybe it's named something else. should i download the library? build it from source code ? what i sould do with it? i just cant find it? i search the hole pc
Last edited on
Thanks for your effort,but under windows the library is named opengl32.lib

g++ main.cpp -Wall -Wextra -pedantic -L"lib" -lopengl32 -lglfw3dll -lglew32dll
Topic archived. No new replies allowed.