bitwalker / picosat_elixir

Elixir + Erlang bindings for the PicoSAT solver
Apache License 2.0
26 stars 5 forks source link

Build fails when picosat is not a dep of another project #1

Closed elbow-jason closed 4 years ago

elbow-jason commented 4 years ago

Building picosat_elixir as a dep of another project with {:picosat_elixir, "~> 0.1.1"} works fine.

However, when cloning master and attempting to run tests I see this error:

picosat_elixir git:(master) ✗ mix test
cc -L/usr/local/opt/llvm@7/lib -Wl,-rpath,/usr/local/opt/llvm@7/lib -shared -L /Users/elbow-jason/.asdf/installs/erlang/22.0.5/usr/lib -lerl_interface -lei /Users/elbow-jason/Workspace/elixirs/picosat_elixir/c_src/picosat_nif.o /Users/elbow-jason/Workspace/elixirs/picosat_elixir/c_src/picosat.o -o /Users/elbow-jason/Workspace/elixirs/picosat_elixir/priv/picosat_nif.so
Undefined symbols for architecture x86_64:
  "_enif_get_int", referenced from:
      _solve_nif in picosat_nif.o
  "_enif_get_list_cell", referenced from:
      _solve_nif in picosat_nif.o
  "_enif_get_list_length", referenced from:
      _solve_nif in picosat_nif.o
  "_enif_make_atom", referenced from:
      _solve_nif in picosat_nif.o
  "_enif_make_badarg", referenced from:
      _solve_nif in picosat_nif.o
  "_enif_make_int", referenced from:
      _solve_nif in picosat_nif.o
  "_enif_make_list_from_array", referenced from:
      _solve_nif in picosat_nif.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/Users/elbow-jason/Workspace/elixirs/picosat_elixir/priv/picosat_nif.so] Error 1
** (Mix) Could not compile with "make" (exit status: 2).
You need to have gcc and make installed. Try running the
commands "gcc --version" and / or "make --version". If these programs
are not installed, you will be prompted to install them.

It's the same error for iex -S mix.

elbow-jason commented 4 years ago

This appears to have been something an issue with asdf.

I switched asdf's erlang to a different version and back again. Now the includes directory is actually there.

darraghenright commented 3 years ago

I was using Ash which uses this library and I came across this error on MacOS Mojave.

When I ran make directly as CC='gcc -m32' make it compiled. Not sure if this is the correct approach.

bitwalker commented 3 years ago

Setting -m32 is going to compile the library as 32-bit, which you almost certainly don't want if you are compiling on a 64-bit machine. I'm honestly a bit surprised it even works when linked against Erlang.

If you are seeing the same error as originally reported here, it is because the symbols this library links against are missing - which essentially means the libraries we expect to link against cannot be found, which can be for a variety of reasons.

In the case of the original error report, the Erlang installation seemed to be missing the libraries entirely, but it is also possible that we are unable to detect the correct path, and so you may need to set LDFLAGS or LD_LIBRARY_PATH to ensure they can be found. If you look at the command string that make outputs when it invokes the compiler, you'll see what paths are being searched.

darraghenright commented 3 years ago

Thanks! Yeah, I figured that can't be right. Anyway, I did some digging and discovered my LDFLAGS was whacked. It's working now!

natterstefan commented 2 years ago

If anyone stumbles upon this again (like I did), this resolved my issue: https://github.com/bitwalker/picosat_elixir/issues/5#issuecomment-967782411 with CPPFLAGSand LDFLAGS.