OpenGL SOIL Undefined reference to glBindTexture, glTexImage2d, etc - c++

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

Related

OpenCV3.10 core.hpp must be compiled in C++

i have installed OpenCV 3.10 and the linked the opencv_world310.lib to release and opencv_world310d.lib to debug.
Moreover I put the compiler options in search directory to ...opencv\build\include. I got a undefined reference error when i left out #include <opencv2/highgui.hpp. Now that i have included it my code looks like this:
#include <stdio.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <opencv2/highgui.hpp>
int main(void){
printf("HALLO!");
return 0;
}
When i try to build it core.hpp opens and the error: core.hpp must be compiled in C++ occurs.
I am using the GNU GCC Compiler in Codeblocks.
What should i do to solve the problem?
Check you compiler options. Open CV 3.10 C++ API requires code to be compiled as C++, but not C. You can use answer to "CodeBlocks: change project language c and c++" question to change the options.
Also use the new Open CV 3.10 API
#include <opencv2/opencv.hpp>`
instead of all the other Open CV header files. This header includes core functionality. To enable highgui module you need to define HAVE_OPENCV_HIGHGUI in your project settings.

c++: How to remove libstdc++.so.6 dependencies

I have 2 program I wrote on my windows computer using Visual Studio 2013. They run fine and work perfectly on my computer, but when I brought them over to my school account that is on a Linux machine, a problem arose. They compile and 1 ran, but the other did not. The one that did not run gave me an error:
.../lib/compat/libstdc++.so.6: version CXXABI_1.3.2 required by...
I have been doing research and I can't seem to find out what in my program would be using libstdc++.so.6, I'm not even really sure what it is or does. Since I am on a student account I can't go installing it using sudo, and it is a homework so I can't submit it using my own libraries.
Any Idea on what my program might be using that would require libstdc++.so.6?
I have 3 files: main.cpp, LinkedList.cpp and LinkedList.h.
I think it might be in main.cpp because I think it stems from a library I am including and main.cpp is the only one that uses outside libraries. Here is the list of libraries it uses:
#include <iomanip>
#include <stdio.h>
#include <fstream>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <bitset>
#include <algorithm>
#include "LinkedList.h"
Thanks in advance!
You are trying to run a program linked against one version of the libraries under another set. That should work fine as long as the library versions aren't too far apart. In your case, the difference between libraries is just too large.
GCC (C++ in particular) has changed quite a bit lately, some programs that used to compile and run fine now blow up or don't compile at all (due to language changes, compiler bugs accepting broken code, ...), and the library ABI has also changed. Your best bet is to carry source code around, and make sure you got compatible language versions on both ends. If that is inconvenient, a solution is to make sure you have the same compiler (and other environment) at both places. The easiest way to get this is to install the same distribution and version.
First you can't remove the dependencies of libstdc++.so.6, because it's a standard C++ library.
To solve your problem you have to check whether your libstdc++.so have the right version
strings /usr/lib64/libstdc++.so.6|grep GXXABI_1.3.1
if there have no matching version, you will have 2 methods like these:
update your gcc on your school's linux OS
yum intsall gcc
download a matching libstdc++.so from this website:
download gcc || download matching libstdc++
then replace the libstdc++.so to /usr/lib64/libstdc++.so.6.*
SOLUTION
I went through a few steps to find my solution. Originally I could compile my program but could not run it.
1) My first step to solve the issue was to change my method of compiling. Originally I compiled my program with the following: g++ main.cpp LinkedList.cpp -o output. I changed it to: g++ -static main.cpp LinkedList.cpp -o output which allowed me to compile and run. This worked but static is a method to dynamically link libraries. This prevents linking with the shared libraries. This is not a good solution because it takes a lot longer and increases the file size of the executable, so I wanted to improve.
2) The second thing I did was remove using namespace std. Yes, I cheated and used it. So I went through my program and added std:: to the appropriate places.
3) The last thing I did was clean up my code. I was using a lot of libraries because my program was a large and complicated program. I was using all of the libraries I had listed in my original post. I went through my code and anywhere I was using a function from a library I would try and write my own code that would do the same thing which would result in my program not depending on those libraries. I was able to replicate a decent amount of these dependent foreign functions with my own which added lot of code, but it allowing me to remove some of these includes. My list of includes is now:
#include <fstream>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include "LinkedList.h"
#include <math.h>
I am not sure exactly which step resolved my issue, but now I can compile with my preferred method, g++ main.cpp LinkedList.cpp -o output, and my program runs fine.
I hope this helps someone.

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.

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.

OpenGL Linking error? Unresolved external glCreateShader()

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.