Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to install on Mac OS 10.14.6 #16

Closed
stevenvar opened this issue Dec 4, 2019 · 33 comments · Fixed by #17 or ocaml/opam-repository#15455
Closed

Unable to install on Mac OS 10.14.6 #16

stevenvar opened this issue Dec 4, 2019 · 33 comments · Fixed by #17 or ocaml/opam-repository#15455

Comments

@stevenvar
Copy link

Hi,

I'm unable to install the package on MacOS 10.14 (Mojave), while it did work when graphics was bundled with ocaml.

Here is the error:

src/unix/libgraph.h:17:10: fatal error: 'X11/Xlib.h' file not found
#include <X11/Xlib.h>

I have xquartz installed.

Doing a

sudo ln -s /opt/X11/include/X11 /usr/local/include/X11

(as mentioned here) just changes the error to:

ld: library not found for -lX11
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any idea?

Thanks

@shenlebantongying
Copy link

shenlebantongying commented Dec 4, 2019

Same thing will occur under macOS Catalina 10.15.1 with XQuartz installed.

Sorry, I do not quite understand OCaml's build system, but I can provide any further information to help.

Screen Shot 2019-12-04 at 4 34 33 PM

@nojb
Copy link
Contributor

nojb commented Dec 4, 2019

Did you try doing

export LIBRARY_PATH=/opt/X11/lib

?

@shenlebantongying
Copy link

shenlebantongying commented Dec 5, 2019

It works!

Thanks!

@nojb
Copy link
Contributor

nojb commented Dec 5, 2019

For info, LIBRARY_PATH is a PATH-like variable that is used to extend the list of directories where the compiler (gcc or similar) looks for static and shared variables at link-time. It is equivalent to adding those directories using an -L flag. As the location of libX11 is nonstandard on OS X the location of the library needs to be passed somehow to the compiler, which one can do using this environment variable, without need to modify the graphics build instructions.

@nojb nojb closed this as completed Dec 5, 2019
@dra27
Copy link
Member

dra27 commented Dec 5, 2019

That said, @nojb - presumably OCaml's configure script figured this out before (on the "just work" principle) - is it just that we're missing some logic in the conversion to Dune?

@stevenvar
Copy link
Author

Just confirming that the

export LIBRARY_PATH=/opt/X11/lib

line works. Thanks!

@shindere
Copy link
Contributor

shindere commented Dec 5, 2019 via email

@dra27
Copy link
Member

dra27 commented Dec 5, 2019

@shindere - it's OK, the report suggests that this did work when the graphics library was in OCaml! I think AC_PATH_X was doing everything needed - the problem now for 4.09+ is that the Dune configuration system is not doing enough, and I wonder if we should fix that.

@dra27
Copy link
Member

dra27 commented Dec 5, 2019

(I think we should fix it, because the graphics library's principal use remains in teaching, where it's very annoying to have extra steps for getting it working...)

@shindere
Copy link
Contributor

shindere commented Dec 5, 2019 via email

@shenlebantongying
Copy link

I think the problem can be traced back to the https://github.com/ocaml/opam-repository/blob/master/packages/conf-libX11/conf-libX11.1/opam, where

[ "sh" "-exc" """PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig" pkg-config --libs x11""" ] {os = "macos"}
After setting the PKG_CONFIG_PATH, the pkg-config still cannot identify --libs x11.

I don't know how to modified it and recompile graphics locally :(

@ghost
Copy link

ghost commented Dec 5, 2019

@ZhengchaoJiang could you look if you have a file x11.pc on your system?

If it's just a missing pkg-config path, I guess we can add it to conf-libX11 and also add a dune-configurator program in graphics to get the flags from pkg-config

@shindere
Copy link
Contributor

shindere commented Dec 5, 2019 via email

@shenlebantongying
Copy link

Ok, I am a noob here anyway:)

i tried to add the line below to my .zshrc

export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig"

then from my terminal

pkg-config --list-all | grep x11                                                                                                   
x11-xcb               X11 XCB - X Library XCB interface
x11                   X11 - X Library

the X11 can be detected.

ghost pushed a commit that referenced this issue Dec 5, 2019
+ add hardcoded pkg-config paths for OSX

Fixes #16

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
@ghost
Copy link

ghost commented Dec 5, 2019

I setup the build to use dune-configurator, @ZhengchaoJiang could you give #17 a try?

@stevenvar
Copy link
Author

stevenvar commented Dec 5, 2019

#17 does not seem to fix it for me. I still get the following linker error

dune build
ocamlmklib src/dllgraphics_stubs.so,src/libgraphics_stubs.a (exit 2)
(cd _build/default && /Users/sv281/.opam/4.08.1/bin/ocamlmklib.opt -g -o src/graphics_stubs src/color.o src/draw.o src/dump_img.o src/events.o src/fill.o src/image.o src/make_img.o src/open.o src/point_col.o src/sound.o src/subwindow.o src/text.o -lX11)
ld: library not found for -lX11
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [default] Error 1

@shenlebantongying
Copy link

I changed to your branch locally, it still not working

dune build                                                                                                  [6:54:04]
  ocamlmklib src/dllgraphics_stubs.so,src/libgraphics_stubs.a (exit 2)
(cd _build/default && /Users/Bash/.opam/4.09.0/bin/ocamlmklib.opt -g -o src/graphics_stubs src/color.o src/draw.o src/dump_img.o src/events.o src/fill.o src/image.o src/make_img.o src/open.o src/point_col.o src/sound.o src/subwindow.o src/text.o -lX11)
ld: library not found for -lX11
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@ghost
Copy link

ghost commented Dec 5, 2019

could you provide the result of the following commands?

$ export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig"
$ pkg-config --cflags x11
$ pkg-config --libs x11

@ghost
Copy link

ghost commented Dec 5, 2019

and also: uname -s (just to be sure)

@stevenvar
Copy link
Author

Here you go :

$ export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig"
$ pkg-config --cflags x11
-I/opt/X11/include
$ pkg-config --libs x11
-L/opt/X11/lib -lX11
$ uname -s
Darwin

@ghost
Copy link

ghost commented Dec 5, 2019

@stevenvar thanks. From the build error you reported in your previous message, it seems that the flags are not being obtained from pkg-config in src/discover/discover.ml. Could you add a couple of printfs in the from_pkg_config function in this file to see what's going on?

@stevenvar
Copy link
Author

Ok what's happening is that the second match returns a None:

let from_pkg_config c =
  Printf.printf "entering";
  let fallback = ([], [ "-lX11" ]) in
  match C.Pkg_config.get c with
  | None -> fallback
  | Some pc -> (
      match C.Pkg_config.query pc ~package:"x11" with
      | None -> Printf.printf "fallback"; fallback
      | Some { cflags; libs } -> (cflags, libs) )

prints "fallback"

@stevenvar
Copy link
Author

The other seemingly wrong thing is that the "match os c" in the entry point of the file returns Other

@ghost
Copy link

ghost commented Dec 5, 2019

Ok, so os c returning Other is probably the issue. Could you provide the output of:

$ dune exec -- src/discover/discover.exe -verbose

?

@stevenvar
Copy link
Author

stevenvar commented Dec 5, 2019

Sure thing. Here you go:

run: /Users/sv281/.opam/default/bin/ocamlc.opt -config
-> process exited with code 0
-> stdout:
 | version: 4.09.0
 | standard_library_default: /Users/sv281/.opam/default/lib/ocaml
 | standard_library: /Users/sv281/.opam/default/lib/ocaml
 | ccomp_type: cc
 | c_compiler: cc
 | ocamlc_cflags: -O2 -fno-strict-aliasing -fwrapv 
 | ocamlc_cppflags: -D_FILE_OFFSET_BITS=64 -D_REENTRANT
 | ocamlopt_cflags: -O2 -fno-strict-aliasing -fwrapv
 | ocamlopt_cppflags: -D_FILE_OFFSET_BITS=64 -D_REENTRANT
 | bytecomp_c_compiler: cc -O2 -fno-strict-aliasing -fwrapv  -D_FILE_OFFSET_BITS=64 -D_REENTRANT
 | native_c_compiler: cc -O2 -fno-strict-aliasing -fwrapv -D_FILE_OFFSET_BITS=64 -D_REENTRANT
 | bytecomp_c_libraries: -lm  -lpthread 
 | native_c_libraries: -lm 
 | native_pack_linker: ld -r -o 
 | ranlib: ranlib
 | architecture: amd64
 | model: default
 | int_size: 63
 | word_size: 64
 | system: macosx
 | asm: clang -arch x86_64 -Wno-trigraphs -c
 | asm_cfi_supported: true
 | with_frame_pointers: false
 | ext_exe: 
 | ext_obj: .o
 | ext_asm: .s
 | ext_lib: .a
 | ext_dll: .so
 | os_type: Unix
 | default_executable_name: a.out
 | systhread_supported: true
 | host: x86_64-apple-darwin18.7.0
 | target: x86_64-apple-darwin18.7.0
 | flambda: false
 | spacetime: false
 | safe_string: false
 | default_safe_string: true
 | flat_float_array: true
 | afl_instrument: false
 | windows_unicode: false
 | supports_shared_libraries: true
 | exec_magic_number: Caml1999X026
 | cmi_magic_number: Caml1999I026
 | cmo_magic_number: Caml1999O026
 | cma_magic_number: Caml1999A026
 | cmx_magic_number: Caml1999Y026
 | cmxa_magic_number: Caml1999Z026
 | ast_impl_magic_number: Caml1999M026
 | ast_intf_magic_number: Caml1999N026
 | cmxs_magic_number: Caml1999D026
 | cmt_magic_number: Caml1999T026
-> stderr:
run: uname -s
-> process exited with code 0
-> stdout:
 | Darwin
-> stderr:
which: pkg-config
-> found: /usr/local/bin/pkg-config
which: brew
-> found: /usr/local/bin/brew
run: /usr/local/bin/brew --prefix
-> process exited with code 0
-> stdout:
 | /usr/local
-> stderr:
run: /usr/local/bin/pkg-config --print-errors x11
-> process exited with code 1
-> stdout:
-> stderr:
 | Package x11 was not found in the pkg-config search path.
 | Perhaps you should add the directory containing `x11.pc'
 | to the PKG_CONFIG_PATH environment variable
 | No package 'x11' found

EDIT: accidentally ran it with ocaml 4.08.1. I corrected it but the same happens with 4.09

@stevenvar
Copy link
Author

stevenvar commented Dec 5, 2019

Ok I think I found the problem.

For some reason running uname -s in the "os" function returns the stdout "Darwin\n" and not "Darwin"

When changing the line

 | { exit_code = 0; stdout = "Darwin"; _ } -> Darwin

to

 | { exit_code = 0; stdout = "Darwin\n"; _ } -> Darwin

Everything seems to work.

ghost pushed a commit that referenced this issue Dec 5, 2019
+ add hardcoded pkg-config paths for OSX

Fixes #16

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
@ghost
Copy link

ghost commented Dec 5, 2019

ah, yes of course I forgot to trim the output 🤦‍♂️

I changed the code in #17 to trim the output. If you could do a final test to confirm it works as expected, I'll merge and prepare a new release. Thanks

@stevenvar
Copy link
Author

Yes that works! thanks

@ghost
Copy link

ghost commented Dec 5, 2019

Cool, merging :)

ghost pushed a commit that referenced this issue Dec 5, 2019
+ add hardcoded pkg-config paths for OSX

Fixes #16

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
@ghost
Copy link

ghost commented Dec 5, 2019

and releasing: ocaml/opam-repository#15455

@garrigue
Copy link

garrigue commented Dec 5, 2019

Completely unrelated: in my mail, your emoticon get displayed as🤦‍ ♂
I.e. "man hitting forehead" = "woman hitting forehead + male"
Mysteries of unicode.

By the way, I had the same problem, and this release fixes it for me too.
(I'm using MacOS 10.15.1, but with macports rather than brew)

@ghost
Copy link

ghost commented Dec 5, 2019

Haha, and I actually typed :man_facepalming:!

Glad it fixes the issue for you too Jacques!

@dra27
Copy link
Member

dra27 commented Dec 5, 2019

@garrigue - that's correct. "man facepalming" is a sequence of characters, it means your MUA isn't processing the zero-width-joiners correctly (see here). The "person facepalming" emoji is permitted to have the appearance of any gender (as you can see on that page). Skin-tone and various other glyphs are selected this way via sequences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants