OpenGL Getting OpenGL functioins

This topic is 1055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hey, guys.

I've got very annoying error when trying to build my app using VisualStudio.

Here is complete error stack

Error       linker command failed with exit code 1 (use -v to see invocation)   PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\clang.exe  1
Error       undefined reference to 'glGetAttribLocation'    PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   70
Error       undefined reference to 'glCreateProgram'    PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   87
Error       undefined reference to 'glAttachShader' PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   91
Error       undefined reference to 'glAttachShader' PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   92
Error       undefined reference to 'glLinkProgram'  PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   93
Error       undefined reference to 'glGetProgramiv' PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   96
Error       undefined reference to 'glDeleteProgram'    PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   100
Error       undefined reference to 'glCreateShader' PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   111
Error       undefined reference to 'glShaderSource' PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   115
Error       undefined reference to 'glCompileShader'    PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   116
Error       undefined reference to 'glGetShaderiv'  PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   119
Error       undefined reference to 'glGetShaderiv'  PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   124
Error       undefined reference to 'glDeleteShader' PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   128
Error       undefined reference to 'glUseProgram'   PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   172
Error       undefined reference to 'glVertexAttribPointer'  PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   174
Error       undefined reference to 'glEnableVertexAttribArray'  PewPew.NativeActivity   c:\workspace\PewPew\PewPew\PewPew.NativeActivity\Renderer.cpp   175


Well, it seems to be related to OpenGL calls, but I can't understand how exactly.

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <EGL/egl.h>
#include <GLES/gl.h>


but still no luck.

Any suggestions about what am I doing wrong?

Share on other sites

Probably easiest thing to do is use one of the libraries that takes care of managing openGL extensions for you.

I personally don't use them much because the rendering engines I make are not exactly conventional so I can't really recommend a specific solution. However I do know many people use and have success with GLEW, SDL, GLFW, and not sure what else but there are a few solutions if you google for it.

Failing that you can just import them yourself if you only need a few openGL functions and don't want to use a library for some reason, but I don't really recommend it.

For example:

const PFNGLCREATEPROGRAMPROC glCreateProgram = ((PFNGLCREATEPROGRAMPROC)wglGetProcAddress("glCreateProgram"));

Edited by JeffRS

Share on other sites

These are linker errors.  Building a C/C++ executable (and I'm simplifying a lot here) involves two primary steps: compiling your C/C++ source code to object code, then linking your object code together with object code from external libraries to make the final executable.

Header files are only relevant for the compiling step and they're sufficient to tell the compiler what function signatures, data types, etc to expect.

For linking you also need library files: .lib or .o or whatever, depending on your OS and toolchain.  Header files on their own are not enough, so hence the errors.

You mentioned Visual Studio so that brings us to the next piece of information: there are no native library files available for OpenGL versions beyond 1.1 in Windows.  The way to access higher functionality is to use the extension loading mechanism (this is not the same thing as using extensions; a misunderstanding I've seen before elsewhere) to get the entry points.

That gets messy which is why the general recommendation you'll see a lot is to use an extension loading library instead of doing it yourself manually.  GLEW is the one that is typically recommended and you're probably going to have the easiest time finding documentation and help on it: http://glew.sourceforge.net/

Share on other sites

Try adding GLESv2 to properties->linker->input->additional dependencies. If it is an option then why not try using v3.1? I didn't have any issues with getting functions (didn't need to) nor linking. Just:

#include <EGL/egl.h>
#include <GLES3/gl31.h>

GLESv3
EGL
to library dependancies.

Of course if you are limited by the platform you are targeting that won't be an option.

Share on other sites
mhagain

I'm sorry, I forgot to mention, that I'm developing an Android application (using NativeActivity), so I'm not sure about an opportunity to use GLEW...

Edited by Fennec

Share on other sites

you need to link es2 lib in android.mk file

LOCAL_LDLIBS := -llog -landroid -lGLESv2

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>

should work

//edit comment to that below: uh oh : )

Edited by WiredCat

Share on other sites

WiredCat,

Visual Studio doesn't contain make files in NativeActivity applications...

Nanoha

Sorry, I'm very new in all that stuff. Could you please tell me a little bit more detailed about how do I add additional dependencies? I mean, I've found this menu, but if I just put "GLESv2" string here, and try to build my project, it says

Error no such file or directory: 'GLESv2'

Share on other sites

Nanoha

Sorry, I'm very new in all that stuff. Could you please tell me a little bit more detailed about how do I add additional dependencies? I mean, I've found this menu, but if I just put "GLESv2" string here, and try to build my project, it says

Error no such file or directory: 'GLESv2'

I'll start by saying I've just made an Android app using Visual Studio's NativeActivity Application project. It starts out using GLES 1 which at first I tried to change but I had difficulty and just went 'old school' and made do but eventually I needed shaders so I put the effort in to getting my project compiling and linking with GLES 3.1 (I had to change a lot..).

I messed a round a lot to get it working but I believe all you need to do is:

#include <EGL/egl.h>
#include <GLES3/gl31.h>

Next right click on your project (PewPew.NativeActivity) and select properties. Expand the linker group and select input. Then in the right pane you should see an option "Library Dependancies". Make sure EGL is there and GLESv3. They should be separated by semicolons. Mine looks like:
%(LibraryDependencies);GLESv3;EGL;m
The 'm' is just the maths lib so you only need that if you are going to be using it.

Other than changing my old GLES1 code to the more modern way of doing things I don't recall having to change much to get it building and linking. I didn't need to get any function addresses or install anything to do that for me (such as GLEW).
Edited by Nanoha

Share on other sites

Nanoha

Thanks, it worked!

Share on other sites

Nanoha

Thanks, it worked!

Good to hear it. I was worried I may have missed a step.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 11
• 13
• 87
• 11
• 10
• Forum Statistics

• Total Topics
632973
• Total Posts
3009617
• Who's Online (See full list)

There are no registered users currently online

×