Cannot find required libs m, dl, and/or pthread

135 views
Skip to first unread message

heid...@googlemail.com

unread,
Jun 8, 2023, 11:50:32 AM6/8/23
to DynamoRIO Users
Trying to cross-compile Dynamorio current master for Aarch64 with an external toolchain fails in Cmake with:

CMake Error at CMakeLists.txt:1804 (message):
  cannot find required libs m, dl, and/or pthread

I tried adding something like this in the CMakeLists.txt :

  find_library(libpthread pthread PATHS /path/to/toolchain/aarch64-linux-gnu/1/workspace/gcc-9.3.0-2.31-edfe925f87-aarch64-linux-gnu/sysroot/lib64 )

but the test still fails.

Adding the path manually in the cmake cache is the only resort at the moment.

Any ideas?

Regards

heid...@googlemail.com

unread,
Jun 8, 2023, 12:47:28 PM6/8/23
to DynamoRIO Users
Note: Just throwing pthread into target_link_libaries will also link. And libpthread.so.* is in this directory and it is Aarch64. I don't understand why it doesn't find it.

Derek Bruening

unread,
Jun 8, 2023, 2:04:36 PM6/8/23
to heid...@googlemail.com, DynamoRIO Users
Please provide the exact command line used for configuring, and the platform and cross packages installed: is it Ubuntu with standard packages or sthg else.  Are you using the provided toolchain file as in the build documentation?  As you might expect that is what our regression tests all use on GA Ubuntu runners and they of course have no errors.

--
You received this message because you are subscribed to the Google Groups "DynamoRIO Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dynamorio-users/18c9fd2d-e3b4-448f-a79c-c4ec9ebdcf42n%40googlegroups.com.

heid...@googlemail.com

unread,
Jun 8, 2023, 2:37:15 PM6/8/23
to DynamoRIO Users
I have to be careful what I provide due to proprietary info. The toolchain sets up an environment, for the build itself its pretty much one cmake call that triggers everything:

cmake -C /path/to/toolchain/aarch64-linux-gnu/1/workspace/gcc-9.3.0-2.31-edfe925f87-aarch64-linux-gnu/bin/../../defaults.cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain/aarch64-linux-gnu/1/workspace/gcc-9.3.0-2.31-edfe925f87-aarch64-linux-gnu/bin/../../aarch64-linux-gnu.toolchain -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_LIBRARY_PATH=/usr/lib -DCMAKE_INSTALL_LIBDIR:PATH=lib -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON /path/to/src/system/ext-dynamorio/1/workspace/ext.dynamorio -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=/path/to/src/system/ext-dynamorio/1/workspace/ext.dynamorio/make/toolchain-aarch64.cmake -DCMAKE_FIND_ROOT_PATH=/path/to/toolchain/aarch64-linux-gnu/1/workspace/gcc-9.3.0-2.31-edfe925f87-aarch64-linux-gnu

I try to use the toolchain-aarch64.cmake from Dynamorio as you can see. I don't know if there is any parameter that causes problems for find_library

heid...@googlemail.com

unread,
Jun 8, 2023, 3:02:18 PM6/8/23
to DynamoRIO Users
Host for Cross Compiling is an Ubuntu 18.04 system and Cmake is cmake-3.16.8Linux-x86_64. Target system is an Aarch64 Yocto Linux 5.10.41-yocto-standardYou need any more info?

Derek Bruening

unread,
Jun 8, 2023, 6:44:46 PM6/8/23
to heid...@googlemail.com, DynamoRIO Users
Presumably this is specific to your particular setup: if your sysroot is in that unusual path and that other toolchain file points there you probably want only that and not the DR-provided one which was written for standard Ubuntu packages which have:

libpthread:FILEPATH=/usr/aarch64-linux-gnu/lib/libpthread.so


heid...@googlemail.com

unread,
Jun 9, 2023, 4:05:20 AM6/9/23
to DynamoRIO Users
Ok, using CMAKE_SYSTEM_PROCESSOR aarch64 will proceed to the build process. But there it fails with:

/path/to/toolchain/aarch64-linux-gnu/1/workspace/gcc-9.3.0-2.31-edfe925f87-aarch64-linux-gnu/bin/aarch64-linux-gnu-as: unrecognized option '--sysroot=/path/to/toolchain/aarch64-linux-gnu/1/workspace/gcc-9.3.0-2.31-edfe925f87-aarch64-linux-gnu/sysroot'

heid...@googlemail.com

unread,
Jun 9, 2023, 5:18:28 AM6/9/23
to DynamoRIO Users
It seems to me that the compiler flags are passed to the assembler too in cross compile mode I don't know how to prevent that.

heid...@googlemail.com

unread,
Jun 9, 2023, 8:28:32 AM6/9/23
to DynamoRIO Users
Ok, I finally found a setup that works:

- set(CMAKE_SYSTEM_PROCESSOR aarch64) needs to be added to our toolchain file
- set(CMAKE_SYSROOT has to be removed from our toolchain file.  Otherwise it is passed to the assembler for whatever reason.
- Instead, a call to set(CMAKE_FIND_ROOT_PATH with the sysroot is added so find_library looks in the right directories.
- Finally, in the find_library calls NAMES parameter has to be used with NAMES pthread libpthread.so . Otherwise, it will look for a file named pthread and not find it. Probably the same with m and dl. I don't know if there is a Cmake parameter that will make it create the full library name.

heid...@googlemail.com

unread,
Jun 9, 2023, 10:11:03 AM6/9/23
to DynamoRIO Users
Ok, the missing lib and .so during library search can be amended with SET (CMAKE_FIND_LIBRARY_SUFFIXES ".so" ) and SET (CMAKE_FIND_LIBRARY_PREFIXES "lib" )
Reply all
Reply to author
Forward
0 new messages