0

I'm running OSX 10.9.2

I've successfully compiled and run the example program for wiiuse. However, this meant making a makefile with CMake, then running make. I am stuck, though, as to how I can compile my own program using this library. As a first step, I'm trying to recompile the example program on my own. I've made a directory which contains example.c and wiiuse.h. When I run

clang example.c -lwiiuse -o example

I get

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

What gives? Why can't include the library?

  • Use `make -n` to generate the exact commands that the `Makefile` is running. Then copy the library arguments, and in particular `LD_LIBRARY_PATH`. – merlin2011 Jun 29 '14 at 03:55
  • I'm a bit confused with what make is doing. https://gist.github.com/anonymous/54c47db1948aa820d1e4 Could you explain how to use LD_LIBRARY_PATH? – user1637451 Jun 29 '14 at 04:07
  • It appears to be calling other `make` scripts. You should run those commands in sequence to see what they do. You can also manually inspect the scripts that are invoked. – merlin2011 Jun 29 '14 at 04:09
  • And those make scripts call other make scripts, which call other scripts, which call other scripts. It's a bit ridiculous. I'm really not sure how to continue. – user1637451 Jun 29 '14 at 04:22
  • Another approach: Use the `find` utility to figure out where the file `libwiiuse.so` lives. Then make sure that is in your linker's path when you compile. – merlin2011 Jun 29 '14 at 04:23
  • I only see libwiiuse.dylib in the directory src, which is compiled when I run make wiiuseexample. – user1637451 Jun 29 '14 at 04:27
  • Ugh, I think the solution you seek might be OS X specific, in that case. I'm sorry I cannot help you further, since I'm on a normal Unix. – merlin2011 Jun 29 '14 at 04:29
  • Regardless, could you explain how to use LD_LIBRARY_PATH? Or how on normal Unix to make sure libwiiuse.so is in the linker's path? – user1637451 Jun 29 '14 at 04:31
  • On a regular Unix, I would be using `gcc` with the option `-Lpath/to/location/of/so_file`. I assume there is an equivalent option for `clang`. When running the compiled binary, I would then set `LD_LIBRARY_PATH` to include the same path. – merlin2011 Jun 29 '14 at 04:34
  • 1
    Hooray! It worked! Thanks so much for helping! gcc example.c -lwiiuse -o example -L/Users/alex/Desktop/WiiUse/build/src/ – user1637451 Jun 29 '14 at 04:38
  • I guess I will write that as an Answer so that future folks can use it... – merlin2011 Jun 29 '14 at 04:39

1 Answers1

0

Since the comment happened to work for the OP, I am writing it into an answer.

On a regular Unix, one would run gcc with the option -Lpath/to/location/of/so_file.

When running the compiled binary, one would then set LD_LIBRARY_PATH to include the same path.

Apparently this approach also works for OS X.

To set LD_LIBRARY_PATH when running, simply prefix the assignment command before the actual program:

LD_LIBRARY_PATH=/path/to/folder/containing/my/lib ./example
merlin2011
  • 71,677
  • 44
  • 195
  • 329
  • Sorry, could you explain how to set LD_LIBRARY_PATH when running? This way, I can move the libwiiuse.dylib, right? – user1637451 Jun 29 '14 at 04:49