0

I have an OpenGL program. I have all the include directories, and everything.

Directory Structure:

Main.cpp
Lib/
GL/
GLEW/
glm/

I compile the program by running:

g++ main.cpp -lGL -lm -lX11 -lpthread -lXi -lXrandr -ldl -I. -lglfw -Llib/ -o main -lGLEW

The error is on -lGLEW. The program compiles with no errors, but when I run ./main, it gives me this:

Error while loading shared libraries: libGLEW.so.2.2: No such file or directory.

This is confusing, as in my lib/ directory, libGLEW.so.2.2 is present, so is libGLEW.so and libGLEW.a.

Can someone please help me?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Samuel
  • 11
  • 10
  • 1
    Thank you. `-Llib/` specifies a lib directory relative to the current working directory, which may not be what you expect it to be. Worth confirming. On the other hand, if lib is one of the conventional directory like /usr/lib, it should already be in the path, but also worth checking. – user4581301 Jan 10 '22 at 16:54

1 Answers1

2

When running a dynamic linked executable, the linker must be able to find all the libraries it needs. It always searches

  • a list of fixed default paths like /lib and /usr/lib
  • additional paths defined by the environment variable LD_LIBRARY_PATH
  • any non-standard paths hard-coded in the binary by the -Wl,-rpath g++ option.

These are your options for making this non-standard library known to the runtime linker.

So either use export LD_LIBRARY_PATH=<somepath>/lib when running or use -Wl,-rpath=<somepath>/lib (with comma and without spaces) when building.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
mmomtchev
  • 2,497
  • 1
  • 8
  • 23