-1

I'm trying to compile and link my c++ GLFW3 program with g++, this is a simple test program i wrote:

#include <GLFW/glfw3.h>
#include <iostream>

int main()
{
    if (!glfwInit())
        std::cout << "glfwInit(); // ERROR" << std::endl;
    return 0;
}

I'm using this command on ubuntu 14.04: g++ src/main.cpp -lglfw3, and it gives me the following extremely long list of errors: http://pastebin.com/p58k3x41

DutChen18
  • 1,133
  • 1
  • 7
  • 24
  • Didn't you forget a few libraries? http://stackoverflow.com/q/17559280/560648 – Lightness Races in Orbit Apr 02 '16 at 01:04
  • I don't know, i'm new to g++ on linux, i'm used to visual studio on windows and there i can just add glfw3.dll to the include and link paths. I'm assuming adding `-lglfw3` to g++ is doing the same thing. I tried compiling with the command suggested in your link, `g++ src/main.cpp -lglfw3 -lm -lGL -lGLU`, but it still gives me a huge amount of errors. – DutChen18 Apr 02 '16 at 01:26
  • Did you try reading the documentation? Because programming by guessing doesn't work. – Lightness Races in Orbit Apr 02 '16 at 01:42
  • I did have a quick look through the documentation but found nothing of use. I've noticed that adding `-lm -lGL -lGLU` did decrease the amount of errors, so after a bit of fiddling i found this command `g++ src/main.cpp -lglfw3 -pthread -lXrandr -lXxf86vm -lXi -lXinerama -lX11 -ldl -lXcursor` wich compiles without errors, i don't fully understand why it needs all the extra libraries, but it works so hurray! – DutChen18 Apr 02 '16 at 01:49
  • Have more than a "quick look". Follow its instructions to find out how to build your software. Study it carefully and in depth. Using _our_ time is not a substitute for performing basic research!! – Lightness Races in Orbit Apr 02 '16 at 01:53

2 Answers2

0

Compiling with g++ src/main.cpp -lglfw3 -pthread -lXrandr -lXxf86vm -lXi -lXinerama -lX11 -ldl -lXcursor works for me without any errors, i don't fully understand why it needs all these extra libraries, but it works so hurray!

DutChen18
  • 1,133
  • 1
  • 7
  • 24
  • You need to link all those libraries because you need to link not only the libraries that your code calls but also all the libraries that are called by any libraries that you link. When a library needs a whole lot of others, [`pkg-config`](https://www.freedesktop.org/wiki/Software/pkg-config/) can find them for you. GLFW supports `pkg-config`. Read **With pkg-config on OS X or other Unix** in [Building programs that use GLFW](http://www.glfw.org/docs/3.0/build.html) – Mike Kinghan Apr 02 '16 at 16:33
0

I recently faced the same errors, on my machine the working command line was:

gcc -o myprog myprog.c -lglfw3 -lGL -lX11 -lXxf86vm -lpthread -lXrandr -lXi -lXinerama -lXcursor -lm
                               ^^^^   

Consider also that depends on how you compiled glfw3 library (shared or static see in the docs) you will obtain a glfw3.so free binary!

Zulan
  • 21,896
  • 6
  • 49
  • 109