OpenGL Linking error? Unresolved external glCreateShader() - c++

I'm working on an OpenGL program to test out shaders and trying to compile them. However, the call to glCreateShader() (and other shader calls like glDeleteShader) give the following error:
(this error is from glCreateShader())
Error 3 error LNK2001: unresolved external symbol _pglCreateShader
I'm using Visual Studio 2012 and on windows 7. Got one of the latest nvidia cards including the latest drivers so can't be my OpenGL version.
I'm using the glTools header files for all the helper functions for the OpenGL Superbible 4th edition. Not sure if there is an error in using these files?
I'll post my includes in case this could be of any help as well.
#pragma once
#include <Windows.h>
// Basic C++ includes
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
using namespace std;
// OpenGL specific and GUI includes
#include "shared/gltools.h"
#include "shared/math3d.h"
#include <SOIL.h>
And linker options:
soil.lib;opengl32.lib;gltools.lib;
Oké, the problem has been solved thanks to the answers:
I edited my glTools.h to include 'gl/glew.h' instead of "glee.h", added a ;glew32.lib option to my linker and added glewInit() before entering the main loop. I've also added the GLEW libs,dlls and includes into the appropriate folder and all the functions work like they should! :)

Grab a copy of GLEW to handle extension loading.
Doing it by hand is...annoying.

On Windows, you use WGL, and when using WGL you can't just link against the GL functions directly. All the functions you get are these; you're supposed to dynamically grab the pointer to the GL entry point you want with wglGetProcAddress (as in here) before you can use them.
Basically, OpenGL on Windows is a PITA if you do the GL entrypoint function pointer loading manually. It's much easier to use a utility library to grab the pointers for you, such as GLEW.

Related

Hundreds of Errors When Including "D3DX11Effect.h"

Whenever I include D3DX11Effect.h in my project, I get hundreds of errors from multiple different DirectX header files that do not give me errors when I do not include D3DX11Effect.h. These are my includes:
#include <string>
#include <dwmapi.h>
#include <iostream>
#include <Windows.h>
#include <vector>
#include <thread>
#include <chrono>
#include <string>
#include <sstream>
#include <TlHelp32.h>
#include <exception>
#include <memory>
#include <vector>
#include <D3D11.h>
#include <d3dx11.h>
#include <DXErr.h>
#include <D3DX11async.h>
#include <D3DX11Effect.h>
#include <D3Dcompiler.h>
#include <D3D11Shader.h>
#include <FW1FontWrapper.h>
#include "../Drawing/ImGUI/imgui.h"
#include "../Drawing/DirectX.h"
#include "../Drawing/imgui_dx11.h"
#include "../Drawing/ShaderFX.h"
#include "../Drawing/Renderer.h"
#include "Global.h"
I'm using Direct X 11 andWindows SDK version 10.0.16299.0. I've tried reinstalling DirectX with no luck. Here is an image of some of the errors I'm getting:
Any help is appreciated.
TL;DR: Read MSDN.
The DirectX SDK is deprecated, and the Windows 8.0 SDK, Windows 8.1 SDK, and Windows 10 SDK headers are newer than the headers that shipped in the legacy DirectX SDK. You are getting a mix of old headers and hew headers, which is why you are getting those errors.
The first thing to consider is if you need to use the legacy DirectX SDK at all. Ideally you just don't use it. This means avoiding the D3DX11 utility library which itself is also deprecated. You can find a number of open source replacements for that functionality listed in the article Living without D3DX, including the latest version of Effects for Dirct3D 11.
You can continue to use the legacy DirectX SDK mixed with modern versions of the Windows SDK, but you need to do it with some care as explained at the bottom of the MSDN page Where is the DirectX SDK?:
VC++ Directory include/lib paths must be in reverse traditional order so you get the newer headers where they conflict
You need to explicitly include d3d11.h and dxgi.h before you include d3dx11.h or you end up with the wrong version--which is exactly what happened above; you are using getting an outdated version of dxgi and/or d3dcommon.
For dxerr.h, build your own version as explained here because (a) it doesn't ship in the Windows SDK, and (b) the version that ships in the legacy DirectX SDK is not fully compatible with modern versions of Visual C++.
Note that the error buried in your image: C2440 static_cast cannot convert from const char[6] to char * in renderer.h has nothing to do with the issue above. This is due to the fact that modern C++11 rules on string literals disallow using them as non-const. You should fix the code, but you can also turn off strictstrings if you don't care about portability/conformance. In any case, take some time to read up on const correctness.
See The Zombie DirectX SDK for a complete dissection of what headers conflict, which ones are unique to the DirectX SDK, and which ones have any value for DirectX 11 games on modern versions of Windows.
You should review the various posts I've made in the past 8 years on this subject as well.

C++ Boost and ImageMagick++ API issue

While developing Raspberry Pi library compiled by g++4.9.2 I have met compability issue between boost (1.6.2) and ImageMagick++ API (7.0). When compiling this code:
#include <Magick++.h>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
I got these boost errors:
__assert_fail was not declared in this scope (path_trails.hpp)
...
__assert_fail was not declared in this scope (path.hpp)
...
__assert_fail was not declared in this scope (shared_ptr.hpp)
When deleting #include <Magick++.h> line everything runs fine. Unfortunately I need boost and ImageMagick as well in this source file. How to solve this issue?
A simple workaround is to include Magick++.h after boost.
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <Magick++.h>
I don't have a proper explanation for this problem but it seems to come from a clash when using different headers including assert.h (I had the same problem using the assimp library and ImageMagick) but I don't get why the order matters.
Reproducing your case, assert.h is included in:
cassert for boost
MagickCore/pixel-accessor.h for Magick++.h
If someone has an explanation for this problem feel free to edit.

C++ project build, but IDE shows error

Error: cannot open source file "GL/glew.h"
I have the following code :
//Include GLEW
#include <GL/glew.h>
//Include GLFW
#include <GLFW/glfw3.h>
//Include the standard C++ headers
#include <stdio.h>
#include <stdlib.h>
//Define an error callback
static void error_callback(int error, const char* description)
{
...
I took from there: http://www.41post.com/5178/programming/opengl-configuring-glfw-and-glew-in-visual-cplusplus-express#part4
In order to have a somewhat portable solution, before I even started Visual Studio 2013 I created two System Environment Variable in windows.
GLEW=C:\Install\Development\C++\Framework\glew-1.10.0-win32\glew-1.10.0
GLFW=C:\Install\Development\C++\Framework\glfw-3.0.4.bin.WIN32\glfw-3.0.4.bin.WIN32
So in my project I could for instance write a additional include folder as: %GLEW%\include
As I said, it builds fine and runs fine as well.
Yet, not having intellisense behave properly is really annoying.
How to fix it?
My syntax was actually wrong, you cant use global environment variable in VS using %<name>% but you have to use $(%<name>).
Wherever I wrote %GLEW%\include I should have $(GLEW)\include.
It's working fine now.
Though I'm completely clueless why it built.
This post: https://stackoverflow.com/a/11543754/910813 got me to remind that.

OpenGL SOIL Undefined reference to glBindTexture, glTexImage2d, etc

I'm using C++ and Opengl, and I'm trying to use SOIL, but when I compile, I get undefined reference to glBindTexture, glTexImage2D, etc. However, this is only coming from SOIL.c, not my own source code. This is what the error produces:
http://pastebin.com/sKrQaBhz
My graphics card is NVIDIA GeForce GTX 680 and my drivers are fully updated. I have everything linked and I'm using premake to manage my project. I'm developing on a linux machine, however, I'm trying to cross compile it onto my windows machine, which gives this error. If I compile it on linux, it's completely fine. This is my premake4.lua file:
http://pastebin.com/T4hsbdz0
My include files is this:
#include "opengl/gl_core_3_3.hpp"
#include <GLFW/glfw3.h>
#include <SOIL/SOIL.h>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include "loadshader.hpp"
I'm using mingw32 to compile my code. Before I was using SOIL, everything was fine. I downloaded SOIL from their webpage at lonesock.net, which I then copied over the libSOIL.a and their include files, but it just doesn't work.
Links order matters for g++.
Try this order:
links { "SOIL", "glfw3", "opengl32", "gdi32", "glu32" }
(edit: fixed the OP answer according to the duplicated question in Premake forum: http://industriousone.com/topic/how-use-premake-compile-static-library)
Looking at SOIL homepage, they said that it must be linked staticly. So, instead of using dynamic linking ('-l' in gcc compiler), try to specify the full path of the library.
This post illustrate what I want to say: https://stackoverflow.com/a/4156190/2293156
gcc -lsome_dynamic_lib some_static_lib.a code.c

Using glut with code blocks in Windows 7

i'm a total novice with OpenGL, and I have to compile a file (my first file using opengl), the headers of the file are :
#include <GL/glut.h>
#include <GL/gl.h>
#include <iostream>
I downloaded glut, put the glut.h in the right folder, and put the glut32lib in the right folder too (in Code Blocks).
I also linked glut32.lib in the linker settings.
But i can not compile, i have errors like this :
....\Desktop\OpenGL\OpenGL\prog3.o:prog3.cxx|| undefined reference to `__glutInitWithExit'|
Please can you help me ?
EDIT : Solution foud here : GLUT compile errors with Code::Blocks
All that was needed was #include before including GL/glut.h
I don't know why...
This was my problem. I found solution for this problem in 2 step.
Step 1: follow instructions in this link: Using OpenGL & GLUT in Code::Blocks
Step 2: add #include <GL/glu.h> before #include <GL/glut.h>
Attention: you must create new project, not blank source file. Just follow how to do it in that link.