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

difficulties on macos, arm64 #1

Closed
anentropic opened this issue Dec 11, 2022 · 4 comments
Closed

difficulties on macos, arm64 #1

anentropic opened this issue Dec 11, 2022 · 4 comments

Comments

@anentropic
Copy link

I had already brew install glfw

first attempt to opam instal glfw-ocaml failed with:

# File "glfw-ocaml/dune", line 9, characters 15-25:
# 9 |   (names       GLFW_stubs)
#                    ^^^^^^^^^^
# (cd _build/default/glfw-ocaml && /usr/bin/cc -O2 -fno-strict-aliasing -fwrapv -pthread -D_FILE_OFFSET_BITS=64 -O2 -fno-strict-aliasing -fwrapv -pthread -g -I /Users/paul/.opam/oktree/lib/ocaml -o GLFW_stubs.o -c GLFW_stubs.c)
# GLFW_stubs.c:1:10: fatal error: 'GLFW/glfw3.h' file not found
# #include <GLFW/glfw3.h>
#          ^~~~~~~~~~~~~~
# 1 error generated.

from this answer https://stackoverflow.com/a/67378304/202168 I fixed that by export CPATH=/opt/homebrew/include

installed successfully

then I copied the code from example window.ml and tried to compile it:

ocamlfind ocamlopt -package glfw-ocaml -thread -linkpkg -o glfw.native glfw.ml
File "glfw.ml", line 8, characters 15-32:
8 |   let window = GLFW.createWindow 640 480 "Hello World" () in
                   ^^^^^^^^^^^^^^^^^
Warning 6 [labels-omitted]: labels width, height, title were omitted in the application of this function.
File "glfw.ml", line 10, characters 2-25:
10 |   GLFW.makeContextCurrent (Some window);
       ^^^^^^^^^^^^^^^^^^^^^^^
Warning 6 [labels-omitted]: label window was omitted in the application of this function.
File "glfw.ml", line 12, characters 13-35:
12 |   while not (GLFW.windowShouldClose window) do
                  ^^^^^^^^^^^^^^^^^^^^^^
Warning 6 [labels-omitted]: label window was omitted in the application of this function.
File "glfw.ml", line 16, characters 4-20:
16 |     GLFW.swapBuffers window;
         ^^^^^^^^^^^^^^^^
Warning 6 [labels-omitted]: label window was omitted in the application of this function.
Undefined symbols for architecture arm64:
  "_caml_glClearColorBufferBit", referenced from:
      _camlGlfw__entry in glfw.o
      _camlGlfw__1 in glfw.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
File "caml_startup", line 1:
Error: Error during linking (exit code 1)

I found a couple of answers:

the solution there seems to revolve around having a CMakeLists.txt file with target_link_libraries(<project> glfw)

but I have no idea how to relate that back to glfw-ocaml ...do you have any tips? thank you!

@SylvainBoilard
Copy link
Owner

Hi,

The error you are getting is actually about a missing stub for the external function glClearColorBufferBit which is implemented in the window_stubs.c file. You should copy that file too and append window_stubs.c -cclib -lGL to your ocamlfind command line.

Alternatively the dune file present in that example folder shows how to create a window_stubs library from the C file and link it with an executable.

@anentropic
Copy link
Author

Ah, thank you.

to understand the role of window_stubs.c in the example ... is that just to avoid depending on some ocaml opengl library?

so if e.g. I used lablgl I would not need an extra .c file?

@anentropic
Copy link
Author

...and indeed, if I comment out the glClearColorBufferBit parts then I can compile the window.ml as I was trying before

and a window opens and works perfectly 👍

thanks again!

@SylvainBoilard
Copy link
Owner

to understand the role of window_stubs.c in the example ... is that just to avoid depending on some ocaml opengl library?

so if e.g. I used lablgl I would not need an extra .c file?

Exactly.

You're welcome. ;)

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

No branches or pull requests

2 participants