glPrimitiveRestartIndex could not be resolved - c++

I am learning OpenGL with the Redbooks v8 at the moment. But I'm stuck at the glPrimitiveRestartIndex() function, because it cannot be resolved.
My setup:
OS: ubuntu 14.04,
Compiler: g++ v4.8.4,
Linked GL and glut.
the exact error message is:
error: ‘glPrimitiveRestartIndex’ was not declared in this scope
I included the following libs:
#include <GL/freeglut.h>
#include <GL/glew.h>
enter code here
Any idea why this function could not be resolved?
What additional information is needed to fix this issue?

Minimal test compiles fine:
#include <GL/glew.h>
#include <GL/freeglut.h>
int main(void) {
glPrimitiveRestartIndex(0);
return 0;
}
Compilation line is gcc test.c -lGLEW -Wall.
If you have problems with that minimal example - then something is fundamentally wrong with your setup, but I bet it isn't the case. If it is, please let me know.
If it compiles but your code doesn't - then it is a mistake in your code, either include order or defines (both direct #define and -D compiler flags).

Related

CBLAS_LAYOUT not declared in gcc version of mkl.h

I'm trying to compile a large code with gcc(version 5.3) compiler, that was compiled with icpc before.
I have troubles with mkl header files that are not the same in gcc as in intel version.
This is the error I'm getting.
error: 'CBLAS_LAYOUT' was not declared in this scope
I looked in the include directory of mkl library and its not in any header. This is the piece of code that's throwing the error.
#include "simgms_math.h"
#include "mkl_lapacke.h"
#include "mkl.h"
#include <iostream>
.
.
CBLAS_LAYOUT layout = (rowMajor == 1) ? CblasRowMajor : CblasColMajor;
typedef CBLAS_ORDER CBLAS_LAYOUT; /* this for backward compatibility */
Adding the line above fixed the issue, after googling about the issue for a while.

WlanGetNetworkBssList()-like commands do not compile with g++

I'm trying to compile a program that prints all available wifi access points including their BSSID.
The example of WlanGetAvailableNetworkList() function on MSDN website compiled just fine when removing the flag part with WLAN_AVAILABLE_NETWORK_CONNECTED.
To print BSSIDs as well I edited that code. I added the following functions and structs:
WlanGetNetworkBssList()
WlanScan()
PWLAN_BSS_LIST
PWLAN_CONNECTION_ATTRIBUTES
PDOT11_MAC_ADDRESS.
All of them except PDOT11_MAC_ADDRESS are marked as 'not declared in this scope'.
My compile command is:
g++ -o WlanAP2 WlanAP2.cpp -lwlanapi -lole32
(The same one worked for the MSDN example.)
My include order is as follows:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <wlanapi.h>
#include <objbase.h>
What am I missing?
Is there another library to be included?
Why do especially these commands not compile?
Thanks in advance!

sdl, sdl2 error: SDL_window (among others) not declared

I have played around with C++ for a while and just recently started to get into SDL and SDL2.
I was able to get the dot demo program to work.
But other programs, such as Lazy Foo' Productions's copied and pasted don't seem to work.
I have both SDL and SDL2 installed (and uninstalled and reinstalled.) I am on Ubuntu 15.04 and I have the IDE CodeBlocks linked (-ISDL2)
The errors are SDL_Window - SDL_WINDOWPOS_UNDEFINED - SDL_WINDOW_SHOWN - SDL_CreateWindow - SDL_GetWindowSurface - SDL_UpdateWindowSurface and finally, SDL_DestroyWindow -- was not declared in this scope.
Also, I include:
#include </usr/include/SDL/SDL.h>
#include </usr/include/SDL2/SDL.h>
#include <stdio.h>
I'm pretty sure that I don't need all of that location, but it didn't work without it either. One other note, when I type the #includes, CodeBlocks will suggest SDL2/SDL.h but not SDL/SDL.h.
What am I missing?
I don't think I can put Lazy Foo' code here - I didn't get permission...
The code you listed;
#include </usr/include/SDL/SDL.h>
#include </usr/include/SDL2/SDL.h>
#include <stdio.h>
Why don't you change it to
#include <SDL2/SDL.h>
#include <stdio.h>
as the first header is where SDL_CreateWindow and other SDL2 functions are declared?
Also you don't need to include both SDL and SDL2 headers. Indeed that could very well be the source of your problem as you would only need to include the version you're using.
If you're following the tutorials from lazyfoo's site, you can check if the ones you're following are using SDL1.2 or SDL2 from their table of contents, as the site actually have the tutorials for both versions.
UPDATE:
I didn't notice that your platform is a Linux platform. Then it is so much easier to solve your problem. The demo that you followed previously was done using SDL-1.2, whereas the gcc error hinted that you're using SDL-2.0, hence SDL_CreateWindow and other undefined errors. You should install SDL-2.0 library and SDL-2.0 development files (which will provide you with the necessary SDL-2.0 headers). You may refer this to SDL-2.0 packages provided by your platform distribution.
As for the compilation, it'll be the same as the tutorial you've followed with a minor change, instead of gcc sdltest.o -lSDL -o sdltest, you'll issue gcc sdltest.o -lSDL2 -o sdltest to indicate that you're linking your code against SDL2 library.
EDIT
A simple SDL program to test your environment. You can use any of the simpler text editor such as nano or gedit or others to edit this, and run the compilation command above to test your setup.
The simplest way to do this is by copy the code, then from your terminal, issue cat > sdltest.cpp and paste the code, then hit [ENTER] and [CTRL-C] to end it. Then you can issue the compilation command as mentioned previously,g++ sdltest.cpp -lSDL2 -o sdltest.
Code;
#include <SDL2/SDL.h>
#include <stdio.h>
int main()
{
SDL_Window *p;
SDL_Renderer *w;
p = SDL_CreateWindow("Game",SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,800,640,SDL_WINDOW_SHOWN);
w = SDL_CreateRenderer(p, -1, 0);
SDL_RenderClear(w);
SDL_SetRenderDrawColor(w,255,0,0,255);
SDL_Rect Rect = {220,140,200,200};
SDL_RenderFillRect(w,&Rect);
SDL_RenderPresent(w);
SDL_Delay(3000);
SDL_DestroyRenderer(w);
SDL_DestroyWindow(p);
SDL_Quit();
return 0;
}
Hope that helps.

Function 'glWindowPos2i' could not be resolved?

While trying to compile a simple example openGL example to display text, I ran into the problem with 'glWindowPos2i' could not be resolved. glWindowPos2i seemed to compile fine as a C program under GCC, but for a could not be resolved error under eclipse as a c++ program with g++. (solution below)
The environment is eclipse (juno) under ubuntu 13.04 with openGL 3.3.0 (NVIDIA 310.44) GLEW version 1.8.0
The issue was that glWindowPos2i is an extension and in order compile with c++, glWindowPos2i needed to be defined by its address. At the top of the program, just after the includes glWindowPos2i needs to be defined as a global.
PFNGLWINDOWPOS2IPROC glWindowPos2i;
Then in the body of the program, after the glutInit, a value needs to be assigned to the global variable.
glWindowPos2i = (PFNGLWINDOWPOS2IPROC) glutGetProcAddress("glWindowPos2i");
The glutGetProcAddress is defined by an include for and the definition for PFNGLWINDOWPOS2IPROC comes from
The full list of the includes I'm using are
#include <GL/glew.h>
#include <GL/glext.h>
#include <GL/freeglut.h>
#include <GL/freeglut_ext.h>
The linker includes I'm using are
-lGL -lm -lglut -lGLEW -lGLU

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