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
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 installed casacore from source using the GitHub repository on my Ubuntu 18.04. The installation completes without any errors and the respective files are written to the expected directories (the .h files to /usr/local/include & libraries to /usr/local/lib). On trying to compile a basic C++ file using these I'm given the following error:
tmp/ccBxZcf3.o: In function 'main': /home/zealouspriest/C_C++_Projects/bb++/ms.cpp:15: undefined reference to 'casacore::MeasurementSet::MeasurementSet()'
/home/zealouspriest/C_C++_Projects/bb++/ms.cpp:15: undefined reference to 'casacore::MeasurementSet::~MeasurementSet()'
collect2: error: ld returned 1 exit status
The compiler command that I use is as follows:
g++ -g -Wall -I/usr/local/include -L/usr/local/lib -lcasa_casa -lcasa_tables -lcasa_ms ms.cpp -o ms
The ms.cpp file being compiled is extremely simple and just creates an empty measurement set to test for successful linking and is as follows:
//ms.cpp
#include <iostream>
#include </usr/local/include/casacore/ms/MeasurementSets/MeasurementSet.h>
int main(){
casacore::MeasurementSet ms = casacore::MeasurementSet();
return 0;
}
Here is all that I have tried:
a) Building from source using GitHub instructions,
b) Installing from Ubuntu repository.
Thanks in advance for your time!
When compiling manually with g++ you need to first specify your sources, and then the dependencies (libraries):
g++ -o ms ms.cpp -I/usr/local/include -L/usr/local/lib -lcasa_casa -lcasa_tables -lcasa_ms -g -Wall
Better just use CMake if you plan to have something more that just one cpp.
Related topics:
linking files in g++
gcc-g++-parameter-order
Alternatively, you can use the -Wl,--no-as-needed options:
g++ -g -Wall -I/usr/local/include -L/usr/local/lib -Wl,--no-as-needed -lcasa_ms ms.cpp -o ms
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.
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