Mateusz Piotrowski Mateusz Piotrowski - 3 months ago 19
C Question

How to handle problems with RPATH on Mac OS X while installing cmocka?

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)



Answer

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")
Comments