3

I am trying to install and run cmocka library for unit testing on Mac OSX Yosemite 10.10.3, but I've got some problems with the RPATH settings.

Update:

Thanks to @baf, I was able to include cmocka.h in my CMakeLists.txt manually like this:

set(CMAKE_C_FLAGS_DEBUG "-I/usr/local/include/cmocka.h")

However, why is it so that I have to do it manually?


I've already tried many different ways of installing it:

What I've done so far:

  1. Download cmocka from here: here. Version 1.0.

  2. tar xvf cmocka-1.0.1.tar.xz

  3. cd cmocka-1.0.1, mkdir build and cd build

  4. sudo cmake ..
    I get a message like this here:

-- Configuring done

CMake Warning (dev):

Policy CMP0042 is not set: MACOSX_RPATH is enabled by default. Run "cmake --help-policy CMP0042" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

MACOSX_RPATH is not specified for the following targets:

cmocka_shared

This warning is for project developers. Use -Wno-dev to suppress it.

Question #1: How can I set the rpath so that there is no warning like the one above?

  1. sudo make

  2. sudo make install

  3. cmocka should be installed now, right?


Running cmake for my program which is using cmocka library.

So now I run cmake for my program and my main CMakeList.txt file has lines like this:

find_library (CMOCKA cmocka)
if (NOT CMOCKA)
    message (WARNING "Cmocka library not found.")
endif (NOT CMOCKA)

But the warning doesn't show up during this phase, so I believe that find_libarary(CMOCKA cmocka) has successfully located cmocka on my computer.

Running make for my program.

While running make I get an error like this:

fatal error:<br>
    'cmocka.h' file not found<br>
#include <cmocka.h>
          ^
1 error generated.

So I guess that cmocka cannot be found...

Question #2: Why cmocka library cannot be found?


Additional notes:

  1. I've tried running

    $ export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    

but it didn't helped. I guess it is a solution for Linux, not Mac.

  1. I've tried to learn something about RAPTH on Mac in cmake from their official documentation here: http://www.cmake.org/Wiki/CMake_RPATH_handling. However I understood very little and I wasn't able to come up with a solution for my problem.

  2. I've tried installing cmocka using brew but I got the same result.

  3. Moreover, I've read many questions at SO about RPATH, linking and cmocka, but I couldn't find a suitable solution as well. Nevertheless, here is the list of related threads:

  4. I've run otool -L cmocka. Here's what I got:

    error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool: can't open file: cmocka (No such file or directory)
    
Community
  • 1
  • 1
Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
  • 1
    Error message is not about missing library, but missing file. Header `cmocka.h` is not in compiler's include path. Try to add `-I/path/to/the/header` to the compiler options. – baf Jun 07 '15 at 18:59
  • @baf. I've found `cmocka.h` in `/usr/local/include/cmocka.h`. I've set such flags for my debug build: `set(CMAKE_C_FLAGS_DEBUG "-std=gnu99 -Wall -pedantic -g -I/usr/local/include/cmocka.h")`. However, when running `make` `cmocka.h` is still not found. What am I doing wrong? – Mateusz Piotrowski Jun 07 '15 at 19:12
  • 2
    Specify location of the header: `-I/usr/local/include` – baf Jun 07 '15 at 19:24
  • It works now. Thank you @bef. Nevertheless, I'm quite curious, why I have to include it using `-I/usr/local/include`... Should it locate cmocka automatically? What is the role of `RPATH` here? – Mateusz Piotrowski Jun 07 '15 at 19:28
  • It seems `/usr/local/include` directory is not in your compiler's include search path. `Rpath` may help to find libraries if installed in non-standard location, but not headers. – baf Jun 07 '15 at 19:57
  • Ok, so RPATH has nothing to do with the "question #2"? *(this would explain why `cmake` was successful)* So it is everything ok with my RPATH settings, right? The problem lies in the difficulty of locating proper headers by my compiler, am I right? If so, what should I search for in order to learn about it and fix it? Thanks! – Mateusz Piotrowski Jun 07 '15 at 20:13

1 Answers1

0

I was able to successfully compile my program (thanks to baf) when I added the -I/usr/local/include flag to my debug flags:

set(CMAKE_C_FLAGS_DEBUG "-std=gnu99 -Wall -pedantic -g -I/usr/local/include/cmocka.h")
Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79