Error while trying to build dune's executable

Dune Build Error on macOS

When trying to build dune’s executable in the source code base’s bin/main using this command:

dune build bin/main.exe

I get this error:

spawn_stubs.c:296:13: warning: unused function 'subprocess' [-Wunused-function]
static void subprocess(int failure_fd, struct spawn_info *info)
            ^
1 warning generated.
File "bin/dune", line 4, characters 7-11: 
4 |  (name main)
           ^^^^
Undefined symbols for architecture x86_64:
  "_CFArrayCreateMutable", referenced from:
      paths_of_list in libfsevents_stubs.a(fsevents_stubs.o)
      dune_fsevents_create in libfsevents_stubs.a(fsevents_stubs.o)
      dune_fsevents_set_exclusion_paths in libfsevents_stubs.a(fsevents_stubs.o)
  "_CFArrayGetValueAtIndex", referenced from:
      dune_fsevents_callback in libfsevents_stubs.a(fsevents_stubs.o)
  "_CFArraySetValueAtIndex", referenced from:
      paths_of_list in libfsevents_stubs.a(fsevents_stubs.o)
      dune_fsevents_create in libfsevents_stubs.a(fsevents_stubs.o)
      dune_fsevents_set_exclusion_paths in libfsevents_stubs.a(fsevents_stubs.o)
  "_CFDictionaryGetValue", referenced from:
      dune_fsevents_callback in libfsevents_stubs.a(fsevents_stubs.o)
  "_CFRelease", referenced from:
      dune_fsevents_create in libfsevents_stubs.a(fsevents_stubs.o)
      dune_fsevents_set_exclusion_paths in libfsevents_stubs.a(fsevents_stubs.o)
  "_CFStringCreateWithCString", referenced from:
      paths_of_list in libfsevents_stubs.a(fsevents_stubs.o)
      dune_fsevents_create in libfsevents_stubs.a(fsevents_stubs.o)
      dune_fsevents_set_exclusion_paths in libfsevents_stubs.a(fsevents_stubs.o)
  "_CFStringGetBytes", referenced from:
      dune_fsevents_callback in libfsevents_stubs.a(fsevents_stubs.o)
  "_CFStringGetLength", referenced from:
      dune_fsevents_callback in libfsevents_stubs.a(fsevents_stubs.o)
  "_FSEventStreamCreate", referenced from:
      dune_fsevents_create in libfsevents_stubs.a(fsevents_stubs.o)
  "_FSEventStreamFlushAsync", referenced from:
      dune_fsevents_flush_async in libfsevents_stubs.a(fsevents_stubs.o)
  "_FSEventStreamFlushSync", referenced from:
      dune_fsevents_flush_sync in libfsevents_stubs.a(fsevents_stubs.o)
  "_FSEventStreamInvalidate", referenced from:
      dune_fsevents_stop in libfsevents_stubs.a(fsevents_stubs.o)
  "_FSEventStreamRelease", referenced from:
      dune_fsevents_stop in libfsevents_stubs.a(fsevents_stubs.o)
  "_FSEventStreamSetDispatchQueue", referenced from:
      dune_fsevents_start in libfsevents_stubs.a(fsevents_stubs.o)
  "_FSEventStreamSetExclusionPaths", referenced from:
      dune_fsevents_set_exclusion_paths in libfsevents_stubs.a(fsevents_stubs.o)
  "_FSEventStreamStart", referenced from:
      dune_fsevents_start in libfsevents_stubs.a(fsevents_stubs.o)
  "_FSEventStreamStop", referenced from:
      dune_fsevents_stop in libfsevents_stubs.a(fsevents_stubs.o)
  "___CFConstantStringClassReference", referenced from:
      CFString in libfsevents_stubs.a(fsevents_stubs.o)
  "_kCFAllocatorDefault", referenced from:
      paths_of_list in libfsevents_stubs.a(fsevents_stubs.o)
      dune_fsevents_create in libfsevents_stubs.a(fsevents_stubs.o)
      dune_fsevents_set_exclusion_paths in libfsevents_stubs.a(fsevents_stubs.o)
  "_kCFTypeArrayCallBacks", referenced from:
      paths_of_list in libfsevents_stubs.a(fsevents_stubs.o)
      dune_fsevents_create in libfsevents_stubs.a(fsevents_stubs.o)
      dune_fsevents_set_exclusion_paths in libfsevents_stubs.a(fsevents_stubs.o)
ld: symbol(s) not found for architecture x86_64
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’m only able to bypass this if I build inside an opam switch by activating one with:

eval $(opam env)

Please does anyone know how I can fix this?

My pc is a macos pro 2017 with intel chip

Could you use dune with -v to see the linker command ?

Hy thanks for the response, do you mean the –verbose command?

I also notice this, if i’m not in an opam switch and i run utop, I get this error

Fatal error: cannot load shared library dlllwt_unix_stubs
Reason: dlopen(dlllwt_unix_stubs.so, 0x000A): tried: 'dlllwt_unix_stubs.so' (no such file), '/System/Volumes/Preboot/Cryptexes/OSdlllwt_unix_stubs.so' (no such file), '/usr/lib/dlllwt_unix_stubs.so' (no such file, not in dyld cache), 'dlllwt_unix_stubs.so' (no such file), '/usr/local/lib/dlllwt_unix_stubs.so' (no such file), '/usr/lib/dlllwt_unix_stubs.so' (no such file, not in dyld cache)
zsh: abort      utop
mac@Kemsguy7 test-project %  

Yes byte code executables need to be able to dynlink C stubs. These are looked up in one of the directories mentioned in CAML_LD_LIBRARY_PATH which is setup by eval $(opam env). See opam env | grep CAML_LD_LIBRARY_PATH and the manual here.