Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Cross-build not finding libraries #119

Closed
GrantEdwards opened this issue Feb 5, 2017 · 3 comments
Closed

Cross-build not finding libraries #119

GrantEdwards opened this issue Feb 5, 2017 · 3 comments
Assignees
Labels

Comments

@GrantEdwards
Copy link

The handling of cross development appears to be fundamentally broken.

In my cmake toolchain file, I specify where the libraries are. When
building c-utility, it finds libssl, but not libcurl (which is in the
same directory).

Here's the content of deps/c-utility/build/error.txt:

/home/nextgen/toolchain/bin/../lib/gcc/arm-unknown-linux-uclibcgnueabi/4.6.3/../../../../arm-unknown-linux-uclibcgnueabi/bin/ld: cannot find -lcurl
collect2: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/aziotsharedutil.dir/build.make:1138: libaziotsharedutil.so] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/aziotsharedutil.dir/all] Error 2
gmake: *** [Makefile:139: all] Error 2

And here's deps/c-utility/build/CMakeFiles/aziotsharedutil.dir/link.txt:

/home/nextgen/toolchain/bin/arm-linux-gcc -fPIC
-D_POSIX_C_SOURCE=200112L -fPIC -Werror -g -shared
-Wl,-soname,libaziotsharedutil.so -o libaziotsharedutil.so
CMakeFiles/aziotsharedutil.dir/src/base64.c.o
[...]
CMakeFiles/aziotsharedutil.dir/src/x509_openssl.c.o -lcurl
/home/nextgen/buildroot-new/output/host/usr/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib64/libssl.so
/home/nextgen/buildroot-new/output/host/usr/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib64/libcrypto.so
-lpthread -lm -luuid
-Wl,-rpath,/home/nextgen/buildroot-new/output/host/usr/arm-buildroot-linux-uclibcgnueabi/sysroot/usr/lib64:

As you can see cmake found the ssl library files and specifed the full
path. But for the curl library (which is in the same location as ssl
library files), it just uses "-lcurl". That's broken.

I've tried setting CMAKE_EXE_LINKER_FLAGS, CMAKE_SHARED_LINKER_FLAGS,
CMAKE_C_FLAGS with "-L" options to specify the library directory, but
those settings are apparently ignored and never show up in
aziotsharedutil.dir/link.txt

How are you supposed to configure the location of library files when
doing cross development?

@damonbarry damonbarry self-assigned this Feb 7, 2017
@damonbarry damonbarry added the bug label Feb 7, 2017
@damonbarry
Copy link
Member

I agree this should be fixed. In our azure-c-shared-utility dependency, the root CMakeLists.txt file simply references curl, without doing a proper CMake find_package() first.

@damonbarry
Copy link
Member

I submitted a pull request in the azure-c-shared-utility repo for this.

@GrantEdwards
Copy link
Author

I've tried setting CMAKE_EXE_LINKER_FLAGS, CMAKE_SHARED_LINKER_FLAGS,
CMAKE_C_FLAGS with "-L" options to specify the library directory, but
those settings are apparently ignored and never show up in
aziotsharedutil.dir/link.txt

For future reference, you can specify compiler and linker flags in
your cmake toolchain to point to library locations, but there's a
trick to it:

SET(CMAKE_EXE_LINKER_FLAGS "-L<whatever>" CACHE STRING "" FORCE)
SET(CMAKE_SHARED_LINKER_FLAGS "-L<whatever>" CACHE STRING "" FORCE)
SET(CMAKE_C_FLAGS "-L<whatever>" CACHE STRING "" FORCE)

WARNING: This is pure cargo-cult cut-and-paste. I don't really understand what
those extra bits at the end are doing. But it works.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants