[CMake] find_library fails when cross compiling

Oliver Dain oliver at revl.com
Wed Mar 28 15:12:07 EDT 2018


In case anyone else hits this, I figured it out. The issue was that our
toolchain file specified "CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY" which
meant it was ignoring our PATH list. Changing it to
"CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH" solved the issue.

On Mon, Mar 26, 2018 at 6:06 PM Oliver Dain <oliver at revl.com> wrote:

> Hi,
>
> I have some find_library lines like the following:
>
> find_library(protobuf_protobuf protobuf PATHS
> /Users/oliverdain/Documents/code/revl/.install/${ARCH}/${VARIANT}/protobuf/3.4.1.r1/lib
> NO_DEFAULT_PATH )
> target_link_libraries(ml_editing PUBLIC ${protobuf_protobuf})
>
> These work find when $ARCH and $VARIANT are set to OSX and either Debug or
> Release (my target system). However, If I run
>
> cmake -H.
> -B/Users/oliverdain/Documents/code/revl/cpp/build/build/IPHONE/Release
> -DCMAKE_TOOLCHAIN_FILE=ios.toolchain.cmake -DIOS_PLATFORM=OS
> -DCMAKE_BUILD_TYPE=Release -DARCH=IPHONE -DVARIANT=Release
>
> the libraries are reported not found (the standard "CMake Error: The
> following variables are used in this project, but they are set to
> NOTFOUND." error) even though the libraries are in the specified location.
> For example, it says it can't find the protobuf libs but an ls yields:
>
> $ ls
> /Users/oliverdain/Documents/code/revl/.install/IPHONE/Release/protobuf/3.4.1.r1/lib
> cmake libprotobuf-lite.a libprotobuf.a pkgconfig
>
> Note that if I change the NO_DEFAULT_PATH specification in the
> find_library line to NO_CMAKE_FIND_ROOT_PATH everything works as expected
> and the libs are found and linked (and I know its the right libs because
> things also run).
>
> Is this a bug or is there something I don't understand about
> NO_DEFAULT_PATH?
>
> Thanks,
> Oliver
>
> PS: I know the hard coded full path names are odd - the CMakeLists.txt
> files are actually generated -- it's a long story.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180328/0310b594/attachment.html>


More information about the CMake mailing list