anholt / libepoxy

Epoxy is a library for handling OpenGL function pointer management for you
Other
680 stars 161 forks source link

Static build fails on linux #245

Open bog-dan-ro opened 3 years ago

bog-dan-ro commented 3 years ago

I tried to build epoxy as a static library (-Ddefault_library=static) but it fails to link:

$ ninja 
[31/56] Compiling C object test/glx_static.p/glx_static.c.o
../test/glx_static.c: In function ‘main’:
../test/glx_static.c:58:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   58 |     Display *dpy = get_display_or_skip();
      |     ^~~~~~~
[40/56] Linking target test/glx_static
FAILED: test/glx_static 
cc  -o test/glx_static test/glx_static.p/glx_static.c.o -Wl,--as-needed -Wl,--no-undefined -Wl,--start-group test/libglx_common.a src/libepoxy.a -static -ldl /usr/lib/x86_64-linux-gnu/libX11.so -Wl,--end-group
/usr/bin/ld: src/libepoxy.a(dispatch_common.c.o): in function `get_dlopen_handle':
/home/bogdan/work/gtk/gtk/subprojects/libepoxy/b/../src/dispatch_common.c:312: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libX11.so'
collect2: error: ld returned 1 exit status
[56/56] Linking target test/glx_beginend
ninja: build stopped: subcommand failed.
rubyFeedback commented 3 years ago

I sometimes have this problem specifically with meson/ninja. Not sure if this is related to the issue here but I remember having had projects with GNU configure that could be built static, but the meson/ninja way failed.

m3t4f1v3 commented 2 years ago

add "static: true" to the dependency lines eg. gl_dep = dependency('gl', required: false, static: true)