nigels-com / glew

The OpenGL Extension Wrangler Library
Other
2.62k stars 617 forks source link

Building on FreeBSD cannot find <X11/Xlib.h> for glew and glew_s target #210

Closed Tloe closed 5 years ago

Tloe commented 5 years ago

I'm trying to build glew-2.1.0 on FreeBSD.

➜  glew-2.1.0 cd build 
➜  build cmake ./cmake 
-- The C compiler identification is Clang 6.0.1
-- The CXX compiler identification is Clang 6.0.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenGL: /usr/local/lib/libGL.so   
-- Looking for XOpenDisplay in /usr/local/lib/libX11.so;/usr/local/lib/libXext.so
-- Looking for XOpenDisplay in /usr/local/lib/libX11.so;/usr/local/lib/libXext.so - found
-- Looking for gethostbyname
-- Looking for gethostbyname - found
-- Looking for connect
-- Looking for connect - found
-- Looking for remove
-- Looking for remove - found
-- Looking for shmat
-- Looking for shmat - found
-- Looking for IceConnectionNumber in ICE
-- Looking for IceConnectionNumber in ICE - found
-- Found X11: /usr/local/lib/libX11.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/T/coding/glew-2.1.0/build
➜  build make
Scanning dependencies of target glew
[ 12%] Building C object CMakeFiles/glew.dir/home/T/coding/glew-2.1.0/src/glew.c.o
In file included from /home/T/coding/glew-2.1.0/src/glew.c:55:
/home/T/coding/glew-2.1.0/build/cmake/../../include/GL/glxew.h:98:10: fatal error: 'X11/Xlib.h' file not
      found
#include <X11/Xlib.h>
         ^~~~~~~~~~~~
1 error generated.
*** Error code 1

Stop.
make[2]: stopped in /usr/home/T/coding/glew-2.1.0/build
*** Error code 1

Stop.
make[1]: stopped in /usr/home/T/coding/glew-2.1.0/build
*** Error code 1

Stop.
make: stopped in /usr/home/T/coding/glew-2.1.0/build
➜  build

I can fix this by changing line 142 in CMakeLists.txt to: target_include_directories(${t} PUBLIC $ ${X11_INCLUDE_DIR}) And add a find_package(X11) just before that.

But as I am using conan.io for my dependencies I would love to see a more permanent fix for this. And I am not sure if this is the correct fix? It seems like the glew and glew_s target isn't supposed to include the X11 files?

nigels-com commented 5 years ago

At first glance I agree that fixing cmake to use ${X11_INCLUDE_DIR} is the way to go.

The logic for find_package(X11) probably ought to ignore BUILD_UTILS too.

On Linux it appears that -lX11 linking is transitive via OpenGL:

cc -DGLEW_NO_GLU -DGLEW_BUILD -O2 -Wall -W -Iinclude -fPIC -Wcast-qual -ansi -pedantic -fno-stack-protector  -o tmp/linux/default/shared/glew.o -c src/glew.c
cc -shared -Wl,-soname=libGLEW.so.2.2 -o lib/libGLEW.so.2.2.0 tmp/linux/default/shared/glew.o -L/usr/X11R6/lib64 -L/usr/lib64 -lGL -lX11
nigels-com commented 5 years ago

Oh, I stand corrected.

The Linux cmake build is linking -lX11 (and others) for the tools, but not the shared library target:

[ 50%] Linking C shared library lib/libGLEW.so
/usr/bin/cmake -E cmake_link_script CMakeFiles/glew.dir/link.txt --verbose=1
/usr/bin/cc -fPIC -O3 -DNDEBUG  -shared -Wl,-soname,libGLEW.so.2.2 -o lib/libGLEW.so.2.2.0 CMakeFiles/glew.dir/home/nigels/dev/glew/src/glew.c.o -lGL -lGLU
...
[ 75%] Linking C executable bin/glewinfo
/usr/bin/cmake -E cmake_link_script CMakeFiles/glewinfo.dir/link.txt --verbose=1
/usr/bin/cc -O3 -DNDEBUG  -rdynamic CMakeFiles/glewinfo.dir/home/nigels/dev/glew/src/glewinfo.c.o  -o bin/glewinfo -Wl,-rpath,/home/nigels/dev/glew/build/cmake/lib: lib/libGLEW.so.2.2.0 -lSM -lICE -lX11 -lXext -lGL -lGLU

Generally speaking I accept cmake patches, but I tend not to use or test cmake since it is in addition to the traditional Makefile build that is more maintainer-oriented.

Tloe commented 5 years ago

Hmm.. I tried using the Makefile directly too and get the include error there as well, but it seems to be another issue.

➜  glew-2.1.0 gmake
cc -DGLEW_NO_GLU -DGLEW_BUILD -O2 -Wall -W -Iinclude -I/usr/X11R6/include -fPIC  -o tmp/freebsd/default/shared/glew.o -c src/glew.c
In file included from src/glew.c:55:
include/GL/glxew.h:98:10: fatal error: 'X11/Xlib.h' file not found
#include <X11/Xlib.h>
         ^~~~~~~~~~~~
1 error generated.
gmake: *** [Makefile:137: tmp/freebsd/default/shared/glew.o] Error 1
➜  glew-2.1.0 

The /usr/X11r6/include folder doesn't exist on FreeBSD.. The X11 files are in /usr/local/include/X11 so this line works:

cc -DGLEW_NO_GLU -DGLEW_BUILD -O2 -Wall -W -Iinclude -I/usr/local/include -fPIC -o tmp/freebsd/default/shared/glew.o -c src/glew.c

nigels-com commented 5 years ago

I pushed a git branch that seems to be building fine for FreeBSD12 (in a virtual box) https://github.com/nigels-com/glew/tree/freebsd

Tloe commented 5 years ago

Hum.. do I need to run some script to get the files in src and include/ when checking out the github repo? What am I missing.. can't find any info on that in the README.md

nigels-com commented 5 years ago

gmake -C auto ought to do it.

Tloe commented 5 years ago

Getting an error.. From google search it seems like it would be better to have #!/bin/sh instead of bash.

Freebsd has bash, but not in /bin/bash

rm -rf extensions/gl
cp -r glfixes/gl/specs/ANGLE OpenGL-Registry/extensions
cp -r glfixes/gl/specs/REGAL OpenGL-Registry/extensions
bin/update_ext.sh extensions/gl OpenGL-Registry/extensions blacklist
bash: bin/update_ext.sh: /bin/bash: bad interpreter: No such file or directory
gmake: *** [Makefile:108: extensions/gl/.dummy] Error 126
gmake: Leaving directory '/usr/home/T/coding/glew/auto'
nigels-com commented 5 years ago

This ought to be fixed in the FreeBSD branch I pushed: freebsd (not yet merged) PR: https://github.com/nigels-com/glew/pull/212

nigels-com commented 5 years ago

There is a Travis build available here also, that ought to work for FreeBSD https://glew.s3.amazonaws.com/nigels-com/glew/293/293.1/glew-2.2.0.tgz

Tloe commented 5 years ago

Been traveling to the other side of the planet so been offline for a bit :)

Thought I had checked out the freebsd branch.. my git/github is a bit rusty.. Checked out the freebsd branch now and it builds with no errors. Also tried the Travis build and it works as well

Perfect :)

nigels-com commented 5 years ago

Great, thanks for the confirmation.

Tloe commented 5 years ago

Thanks for fixing it :)