simavr
simavr copied to clipboard
add -lGL -lGLU to the Makefile
Build probleme with ubuntu, I've to add that to the linker
On my Ubuntu 20.04,
pkg-config --libs glu
outputs
-lGLU -lGL
If you had to manually add these flags, I would guess that's because your pkg-config
is broken.
I'm using Ubuntu 22.04 I install pkg-config yesterday. Perhaps the package needs reboot. I'll try it again today in the evening. You're right I think also that pkg-config doesn't work. Anyway "-lGLU -lGL" is shorter than "pkg-config --libs glu" doesn't require to install pkg-config.
I just tried on an Ubuntu Jammy (22.04) virtual machine, and I get, I believe, the same build failure as you: while building charlcd.elf, the linker doesn't find the symbol glEnable
, which is provided by libGL.
It seems the relevant difference between Ubuntu Focal (20.04) and Ubuntu Jammy is in the file /usr/lib/x86_64-linux-gnu/pkgconfig/glu.pc. The version on Focal, which does work, has the line:
Requires: gl
This adds -lGL
to the output of pkg-config --libs glu
:
-lGLU -lGL
The version on Jammy doesn't have this “Requires” field, and pkg-config --libs glu
outputs only
-lGLU
Note that the Jammy version of glu.pc has the line
Requires.private: opengl
which one would expect to solve the problem, as OpenGL also defines the missing symbol. Unfortunately, pkg-config
ignores Requires.private unless doing static linking, presumably assuming that the linker will automatically resolve dependencies for dynamic libs. It would seem that GNU ld used to do that, but it doesn't anymore.
I wonder whether this should be considered a bug in pkg-config, or a bug in the Jammy version of glu.pc. In the mean time, the minimal change that fixes the build is:
diff --git a/examples/Makefile.opengl b/examples/Makefile.opengl
index 700b45c..83d0d00 100644
--- a/examples/Makefile.opengl
+++ b/examples/Makefile.opengl
@@ -6,7 +6,7 @@ LDFLAGS += -framework GLUT -framework OpenGL
else
ifeq (${UNAME}, Linux)
CPPFLAGS += ${shell pkg-config --cflags glu}
-LDFLAGS += ${shell pkg-config --libs glu} -lglut
+LDFLAGS += ${shell pkg-config --libs glu gl} -lglut
else
ifeq (${shell uname -o}, Msys)
LDFLAGS += -mwindows -lopengl32 -lfreeglut
Hi, the changes you propose will solve the problem.
The problem is confirmed on Debian/sid, fresh clone and install. The proposed solution is better than my adding manually -lGL to /examples/board_timer_64led/Makefile
to complete compilation.