Unofficial OpenGL SDK Linking issue - undefined reference - c++

I'm trying to get the Unofficial OpenGL SDK Libraries to work and started using the glutil library for the matrixStack functionality. I compiled the source using Visual studio 2010 and moved the libraries to the minGW folder located at my Code::Blocks folder. I moved the header files to the include folder over there as well.
Everything should be in place now and should be compiled for my OS so the following code should work just fine.
// Get rotation matrix
//float rotValue = (glutGet(GLUT_ELAPSED_TIME)) / 10;
glm::mat3 rotMatrix = RotateAxis(0.0f, 0.0f, 1.0f, 0.0f);
// Build final matrix from rotMatrix
glm::mat4 finalMatrix(rotMatrix);
finalMatrix[3].x = camX;
finalMatrix[3].y = camY;
finalMatrix[3].z = camZ - 1.0f;
finalMatrix[3].w = 1.0f;
glutil::MatrixStack stack(finalMatrix);
glutil::PushStack push(stack);
// Object 1
glBindVertexArray(vaoObject); // Advantage of using vao's is that you only have to do all the vertex attribute enabling and buffer stuff once.
glUniformMatrix4fv(modelToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(stack.Top()));
glDrawElements(GL_TRIANGLES, ARRAY_COUNT(indexData), GL_UNSIGNED_SHORT, 0);
// Object 2
stack.Translate(glm::vec3(0.0f, 0.5f, 0.0f)); // THIS IS WHERE THINGS GO WRONG
finalMatrix[3].z = camZ - 2.00f;
glUniformMatrix4fv(modelToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(stack.Top()));
glDrawElementsBaseVertex(GL_TRIANGLES, ARRAY_COUNT(indexData), GL_UNSIGNED_SHORT, 0, 36/2);
The call to stack.Translate generates the following error: undefined reference to 'glutil::MatrixStack::Translate(glm::detail::tvec3 const&)' which is quite odd since without the translate call the constructors for the MatrixStack and PushStacks work just fine which is odd.
I tried adding -glutil to the linker but didn't solve my problem.
Header includes (related to openGL):
// Open GL and GLUT
#include <gl/glew.h>
#include <gl/glut.h>
// Open GL Libraries
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glutil/glutil.h>
I'm still not sure how to find out the correct names to link the libraries to since the OpenGL SDK didn't show this information on their website so I'm not sure if -glutil is correct. I'm guessing the problem has something to do with the linking stage.

Are you using C++ code compiled by VC++ under MinGW? You know that ABI's of those compilers are different? Even the name mangling scheme is different, so that could explain why it cannot be linked. Chack if unmangled version of function name from mingw linker (should be somewhere in error report) maches the one exported from glutil - using eg. DLL Export Viewer - or is glutil statically linked? If it doesn't match, you probably need to use the same compiler for both library and your code.

Related

Linker gives errors about a function that i have not used in my application at all

The linker keeps showing a bunch of errors about functions that i have not used in my application. The only thing that I did was change the headers from DirectX SDK to the Windows SDK, and I also downloaded the package for DirectXTK so i can use WICTextureLoader.h and DDSTextureLoader.h
Here are some of the linker errors.
error LNK2001: unresolved external symbol "union __m128 __vectorcall DirectX::XMVectorMultiply(union __m128,union __m128)
error LNK2001: unresolved external symbol "void __vectorcall DirectX::XMVectorSinCos(union __m128 *,union __m128 *,union __m128)
error LNK2001: unresolved external symbol "union __m128 __vectorcall DirectX::XMVectorSet(float,float,float,float)
I'm not sure what's going on here. I didn't call XMVectorMultiply() or XMVectorSinCos() at all in my application. I already linked the appropriate libraries and headers in my project, but this still won't fix the problem. What could be causing these linker errors?
(If you need more relevant information, just ask)
Below is just part of my code (I didn't include all of it because i have about 2000 lines of code):
#pragma comment (lib, "dinput8.lib")
#pragma comment (lib, "dxguid.lib")
#pragma comment (lib, "D3D11.lib")
#pragma comment (lib, "d3dcompiler.lib")
#include <windows.h>
#include <D3D11.h>
#include <dinput.h>
#include <D3Dcompiler.h>
#include <sstream>
#include <SimpleMath.h>
#include <DirectXMath.h>
#include <DDSTextureLoader.h>
#include <WICTextureLoader.h>
#include <SpriteBatch.h>
#include <SpriteFont.h>
void Create_Camera_View_Space()
{
camPosition = DirectX::XMVectorSet(0.0f, 2.0f, -12.5f, 0.0f);
camDirection = DirectX::XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f);
camUp = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
CameraView = DirectX::XMMatrixLookAtLH(
camPosition,
camDirection,
camUp
);
}
void Create_Camera_Projection_Space()
{
CameraProjection = DirectX::XMMatrixPerspectiveFovLH(
0.4f * 3.14f,
(float)400 / 400,
1.0f,
10000.0f
);
}
void Create_World_Space_for_Ground()
{
DirectX::XMMATRIX Translation;
DirectX::XMMATRIX Rotation;
DirectX::XMMATRIX Scale;
DirectX::XMMATRIX Input_Rotation_X;
DirectX::XMMATRIX Input_Rotation_Z;
GroundWorld = DirectX::XMMatrixIdentity();
Scale = DirectX::XMMatrixScaling(500.0f, 10.0f, 500.0f);
Translation = DirectX::XMMatrixTranslation(0.0f, 10.0f, 0.0f);
GroundWorld = Scale * Translation;
}
This is the few times i am using the functions in the DirectXMath.h, but the linker shows errors that come from that specific header..
The most likely issue here is that you are building the various libraries in question with different settings, compilers, or paths.
__vectorcall is a calling convention supported by VS 2013 or later and is used by DirectXMath in the Windows 8.1 SDK and the Windows 10 SDK if it is supported by your compiler. As DirectXMath is all inline, you have to be consistent about making sure all your use of DirectXMath in the same EXE or DLL is using the same version of the headers and the same version of the compiler.
This is one of the reasons why DirectX Tool Kit provides compiler specific vcxproj files to ensure this is kept in sync.
As your project previously used the legacy DirectX SDK, you probably have some lingering Preprocessor macros and VC++ Directories settings that need cleaned up. You might try doing a diff of your vcxproj file with DirectXTK_Desktop_2015.vcxproj.
You can also have problems if you are building your x86 config with /arch:IA32 or /arch:SSE rather than /arch:SSE2 which is what is used for the DirectX Tool Kit library builds.
A similar mismatch can happen if you try to use _XM_NO_INTRINISCS_ in your project which does not match how DirectX Tool Kit is built.

Linking a script to glew and GLFW c++

I been following a tutorial to create a simple program which displays a window with an unshaded triangle drawn in it. To do this I am using the glew library and the GLFW library however after adding in the following code:
do{
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glVertexAttribPointer(0, 3,GL_FLOAT, GL_FALSE, 0, (VOID*)0);
glDrawArrays(GL_TRIANGLES,0,3);
glDisableVertexAttribArray(0);
glfwSwapBuffers(window);
glfwPollEvents();
} while (glfwWindowShouldClose(window) == false);
I got this error (full message not shown):
undefined reference to `glDrawArrays'
I think this could be because of a problem with how my project is linked however other functions from glew are being called without errors which is what confuses me. I'm using NetBeans for my IDE and MinGW64 as my compiler on a 64 bit windows 10 installation. The project includes the following places:
../../../../../Program Files/mingw-w64/x86_64-5.2.0-win32-seh-rt_v4-rev0/mingw64/include/GLFW
../../../../../Program Files/mingw-w64/x86_64-5.2.0-win32-seh-rt_v4-rev0/mingw64/include
../../../../../Program Files/mingw-w64/x86_64-5.2.0-win32-seh-rt_v4-rev0/mingw64/include/GL
And the library files I use are located at these locations:
../../../../../Program Files/mingw-w64/x86_64-5.2.0-win32-seh-rt_v4-rev0/mingw64/bin/glew32.dll
../../../../../Program Files/mingw-w64/x86_64-5.2.0-win32-seh-rt_v4-rev0/mingw64/lib/glfw3.dll

Superbible 6th edition undefined platform error

I just started off with learning openGL from the superbible(6th edition) with code::blocks.
But when i try to run the first sample code i get an undefined platform error from the sb6.h file.
sample code:
#include "sb6.h"
// Derive my_application from sb6::application
class my_application : public sb6::application
{
public:
// Our rendering function
void render(double currentTime)
{
// Simply clear the window with red
static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 0, red);
}
};
// Our one and only instance of DECLARE_MAIN
DECLARE_MAIN(my_application);
Does anyone know how to fix this?
This is because that header file expects one of _WIN32, _LINUX or __APPLE__ to be defined. Usually these are defined by the compiler or one of the platform's headers. You could also pass them to your compiler, e.g. -D_LINUX or define it in your source file before you include their header, e.g.:
#ifndef _LINUX
#define _LINUX
#endif
gcc actually defines __linux, but this is not what the header file is checking for.
It appears you are not using the CMake provided along with the projects. The CMake build process automatically adds -D_LINUX, on Linux systems when detected. Refer to the file CMakeLists.txt (https://github.com/prabindh/sb6code/blob/master/CMakeLists.txt) around line 135. If you are not using CMake, you will need to do a similar addition to the build flags.
The end of sb6.h has a set of preprocessor defines for various operating systems, and the '#elif defined _LINUX || defined APPLE' is not reached for some reason. I commented out from '#if defined _WIN32' to 'APPLE' and from '#else' to second last '#endif'. Between those commented out sections is the #define DECLARE_MAIN(a)' that is needed.
Good luck getting the rest of the programs to compile.

OpenGL functions are undefined in VS2012 express

I'm attempting to use some OpenGL functions in Visual Studio 2012 express, my code looks like this:
#include <Windows.h>
#include <iostream>
#include <gl/GL.h>
#include <fstream>
void saveScreen()
{
//code to define some variables, nWidth, nHeight and Buffer.
glreadbuffer ( GL_BACK ); //which buffer we are reading from.
glreadpixels ( 0, 0, nWidth, nHeight, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *Buffer);
//do something with buffer data
return;
}
According to internet research, my code is correct, apart from glreadpixels apparently expects more expressions and )'s, but i think i can work that out myself.
When i try to compile and run i get errors saying both glreadbuffer and glreadpixels are undefined. I cant find anything that tells me what to do apart from #including windows.h and gl/gl.h and OpenGL should work.
Thanks in advance for any help :)
Edit:
Thanks for replying, I added these lines to the Additional dependancys of the linker:
opengl32.lib
glu32.lib
and properly capitalised the function calls
That seems to have solved the problem.
The functions glreadbuffer() and glreadpixels do not exist in OpenGL. The API uses CamelCase function name style, so these function names are spelled glReadBuffer() and glReadPixels().
This is how you correctly link in visual studio 12:
The first thing you create is a folder somewhere called "dev" (or really any name). In that folder you extract "freeglut"(only if you want a windowing toolkit) and "glew" (the openGL extension wrangler, this loads the gl functions).
After that you open a new project in VS12 and rightclick on the project->properties
Under VC++ properties click on "Include directories" and add the path to your dev/glew/include folder and your dev/freeglut/include. Make sure your path is 100% correct!
Then click on "Library directories" and add these 2 paths: dev/glew/lib and dev/freeglut/lib.
Then go to C/C++ and click on additional include directories and add these 2 paths:dev/glew/include and dev/freeglut/include.
Then go to linker and add the lib folders in "additional library directories" this is a tricky one because you need to link to the correct version: \dev\glew\lib\Release\Win32
Then try your code again, if that doesn't work, try source code from the internet.
Also if you copied the folders without changing there name you should include "GL/glew.h"
These steps are required for each project that uses openGL.

what SDL and OpenGL version and implementation I'm using

I downloaded SDL 1.2.14
on Windows 7
and I have Mobility Radeon X1800 driver installed.
I'm using Microsoft Visual C++ 2010 Express.
I added the SDL include and library directories in the "VC++ Directories"
I added the following Additional Dependencies:
opengl32.lib;
glu32.lib;
SDL.lib;
SDLmain.lib;
I added the SDL.dll to my program folder
I didn't add any opengl directories!
#include "SDL.h"
#include "SDL_opengl.h"
bool running = true;
int main(int argc, char* args[]) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface* screen = SDL_SetVideoMode(640,480,32,SDL_OPENGL);
glViewport(0,0,640,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 640/480, 1.0, 200.0);
while(running) {
glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); // Swich to the drawing perspective
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5f, 0.5f, 0.0f);
glVertex3f(-1.0f, 1.5f, 0.0f);
glVertex3f(-1.5f, 0.5f, 0.0f);
glEnd();
SDL_GL_SwapBuffers();
}
SDL_Quit();
return 0;
}
This program draws a simple triangle.
I include 2 header files above and my Opengl code just works!
I don't know if my triangle is done on a the GPU or CPU. And what openGL version I'm using?
I mean i heard that Microsoft don't update there opengl files any longer and that they use CPU implementation of OpenGL 1.1 or something.
How do I know what version of OpenGL I'm using? And can I check at run time?
How do I know if I'm using a CPU or GPU implementation? And can I check at run time?
Thanks for look at my problem.
call glGetString
Here is Microsoft's documentation for glGetString. It just repeats the SGI doc and tells you the function is found in gl.h and opengl32.lib.
Actually when you install your video card driver it "replaces" the opengl existing in your machine, so you will be using that version.
Multiple versions of OpenGL are present at the same time, and which one is used depends on the HDC used to initialize OpenGL. For example, applications running in the local login session can get hardware-accelerated GL while those running in a remote desktop session get the CPU-based implementation ( Ben Voigt )
The currently header and lib that comes with Visual Studio only has OpenGL 1.1 in it, so to access more modern stuff you need to call the wglGetProcAddress to get pointers to the new functions.
Here you can find more information: http://www.opengl.org/wiki/Getting_started