I am trying to compile simple program to standalone executable so i can send it to my friend. But i am facing a problem with GLUT dependencies. Command i tried is:
g++ triangle.cpp -static -lglut -lGLU -lGL -lm
And i got this error:
/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
When i try to use Mingw64 i get this:
i686-w64-mingw32-g++ triangle.cpp -static -lglut -lGLU -lGL -lm -o test.exe
triangle.cpp:9:21: fatal error: GL/glut.h: No such file or directory
#include <GL/glut.h>
^
compilation terminated.
My includes
#include <vector>
#include <cstdio>
#include <GL/glut.h>
#include <math.h>
#include <string>
#include <sstream>
/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
It seems that you do not have the GLUT libraries installed.
For GNU linux with aptitude, try
apt-get update
apt-cache search freeglut
to get a list of all libraries containing freeglut.
I think (not totally sure) that you need freeglut3-dev installed.
Related
I use Linux, more specifically, Arch Linux. I wanted to work with OpenGL, so I did the following steps:
First, I downloaded the glfw-x11 with the pacman package manager.
I also used cmake to add glfw to /usr/local/include, everything works fine.
I wrote a Makefile to run my program with the command:
gcc -o demo main.c -lglfw3 -lm -lXrandr -lXi -lXxf86vm -lpthread
Also note that I removed -lGl because gcc, the compiler, screamed at me.
Here is my project directory: glad main.c Makefile. Note that glad is a directory. And it works fine.
I am running on Linux so I can't install Visual Studio and I am really don't think I need CodeBlocks to create an OpenGL project.
The error the compiler gives me when I run this code (in main.c):
#include <stdio.h>
#include "glad/glad.h"
#include <GLFW/glfw3.h>
int main() {
glfwInit();
printf("Hello, OpenGL!");
// Code goes here..
glfwTerminate();
return 0;
}
The compiler gave me:
/usr/bin/ld: /usr/local/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XPending'
/usr/bin/ld: /usr/lib/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Edit
lGL just worked, but still I get the same error.
Another Edit
Adding -ldl, lXinerama and lXcursor worked for me.
Final Edit
I fixed it, first, you create a main.cpp (or whatever you wanna call it). Make sure you have libgl, glu and glfw-x11 installed. Then create a Makefile with the flags -lGL -lGLU -lglfw3 -lm -lXrandr -lXi -lX11 -lXxf86vm -lpthread -ldl -lXinerama -lXcursor. Then download glad. Extract glad.zip (Make sure glad is in the project folder). Move src/glad.c into the project directory. Include glad with "include/glad/glad.h" or whatever directory you choose. Also make sure GLFW is in /usr/local/bin.
I am trying to compile this piece of code using GCC:
#include <glad/glad.h>
#include <GLFW/glfw3.h>
int main(){
return 0;
}
I am following this guide. As the guide said I went to https://glad.dav1d.de/ and generated glad. I placed the glad and KHR include folders in my /usr/include folder and placed glad.c in the folder where I have this piece of code.
This is the command I am trying to use to compile the code:
gcc test.cpp -o test -lglad -lglfw
I get this compile error
/usr/bin/ld: cannot find -lglad
collect2: error: ld returned 1 exit status
Turns out, you can just compile using
gcc test.cpp glad.c -o test -lglfw
I've written a simple code which create folder. The problem is that I can't compile it. The code is below:
#include <iostream>
#include <boost/filesystem.hpp>
int main()
{
boost::filesystem::create_directories("/tmp");
return 0;
}
Compilation:
g++ createFolder.cpp -std=c++0x -lboost_system -o createFolder
I have got errors:
collect2: ld returned 1 exit status
How to correct the compilation process to run this program.
Try adding boost-filesystem to you linker:
g++ createFolder.cpp -std=c++0x -lboost_system -lboost_filesystem -o createFolder
when I had tried to compile the example code for glfw3 on http://www.glfw.org/documentation.html (copy/pasted to test compilation), I got the following errors:
/tmp/ccCdEKoi.o: In function main':
example.cpp:(.text+0x38): undefined reference toglfwCreateWindow'
example.cpp:(.text+0x5b): undefined reference to glfwMakeContextCurrent'
example.cpp:(.text+0x7a): undefined reference toglfwWindowShouldClose'
collect2: error: ld returned 1 exit status
I am compiling with g++ example.cpp -o example -lGL -lglfw and when I installed the latest glfw 3.0.2, it installed without problems.
GLFW3 builds as libglfw3 by default, not libglfw as GLFW2 did. So you're probably still linking against your GLFW2 installation.
Solution:
g++ example.cpp -o example -lGL -lglfw3
I am trying to setup OpenGL developing environment on Ubuntu.I installed all the libs including GLFW as I don't want to use GLUT.GLEW lib has been installed too.I am trying to set it all in NetBeans.I have never used it before and currently I am getting :
undefined reference to `glfwInit' error while running this simple code:
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <GL/glew.h>
#include <GL/glfw.h>
#include "glm.hpp"
using namespace std;
using namespace glm;
int main(int argc, char** argv) {
/* init GLFW */
if(!glfwInit()){
fprintf(stderr,"failed to init GLFW");
}
return 0;
}
I am sure it is linker related problem.So I have added libglfw.a to Linker->Libraries and then got even more errors like these:
make[2]: Entering directory /home/sasmaster/NetBeansProjects/OpenGLDemo'
mkdir -p dist/Debug/GNU-Linux-x86 g++ -o dist/Debug/GNU-Linux-x86/opengldemo build/Debug/GNU-Linux-x86/main.o /usr/lib/libglfw.a
/usr/lib/libglfw.a(window.o): In functionglfwOpenWindow':
/usr/lib/libglfw.a(x11_init.o): In function _glfwPlatformInit':
/usr/lib/libglfw.a(x11_init.o): In function_glfwPlatformInit':
/usr/lib/libglfw.a(x11_init.o): In function _glfwPlatformInit':
/usr/lib/libglfw.a(x11_init.o): In function_glfwPlatformInit':
/usr/lib/libglfw.a(x11_init.o): In function _glfwPlatformTerminate':
/usr/lib/libglfw.a(x11_init.o): In function_glfwPlatformTerminate':
/usr/lib/libglfw.a(x11_window.o): In function translateKey':
/usr/lib/libglfw.a(x11_window.o): In functiontranslateKey':
/usr/lib/libglfw.a(x11_window.o): In function translateKey':
/usr/lib/libglfw.a(x11_window.o): In functiontranslateChar':
...........
........................
What else should I link or install?
Update:
Here it is said one should add LIBRARIES='-pthread -lglfw -lGL -lX11 -lGLU -lXxf86vm'
But where should I add those in NetBeans properties? I tried put into the MakeFile and "linker options" too and nothing helped.
Update1
Compiling the main.cpp manually using this command:
**g++ main.cpp -o Game -lglfw -lGL -lGLU -lX11 -lpthread -lXxf86vm -lm**
Compiles fine.How do I link all these libs via NetBeans???
I figured out the solution.For those interested:
Openg Project properties.Then "Linker" ->"Libraries".
In the Libraries dialog:
Click "Add Option" -> "Other Option".
In the textfield insert these params:
-lGLEW -lglfw -lGL -lGLU -lX11 -lpthread -lXxf86vm -lm
I guess lGLU is needed only if you use the old OpenGL version.