Cutter: Compiling error: "clock_gettime"

Created on 22 Jul 2020  Â·  21Comments  Â·  Source: rizinorg/cutter

Hi,

The AppImage can't run on ancient Linux environments. So, I'm trying to compile it from scratch inside a Debian 7 x64. I manually compiled/updated/installed cmake, python, git, meson and ninja, so the build system meets the requirements. No problems until I get this error:

shlr/libtree_sitter.a(tree-sitter_lib_src_lib.c.o): In function `clock_now':
/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/../../../../radare2/shlr/tree-sitter/lib/src/././clock.h:73: undefined reference to `clock_gettime'
collect2: error: ld returned 1 exit status
[1126/1507] Generating cc-arm-32.sdb with a meson_exe.py custom command
ninja: build stopped: subcommand failed.
make[2]: *** [Radare2-Bundled-prefix/src/Radare2-Bundled-stamp/Radare2-Bundled-build] Error 1
make[1]: *** [CMakeFiles/Radare2-Bundled.dir/all] Error 2
make: *** [all] Error 2

This problems seems to appear in ancient radare2 compilations: https://github.com/radareorg/radare2/issues/1983
However, I don't know how to fix it. So, please can you help me?

Futhermore, I suggest to use a more legacy environment to compile the AppImage, for example a Debian 7 or CentOS 7 almost. Or privide different AppImages based on the major kernel version.

Regards.

Most helpful comment

@lars18th please have a look at https://github.com/radareorg/radare2/pull/17345 . I think it fixes the problem for good. I could only test it on CentOS 6, because on debian:wheezy container I could not install any package. Let me know!

All 21 comments

Nowadays we check radare2 itself on Debian Jessie, I think it's old enough. https://github.com/radareorg/radare2/runs/891055762?check_suite_focus=true

The problem of doing the same with Cutter is tricker since it requires relatively new Qt. I am not 100% sure if that Qt will even compile on that distribution.

The oldest distro on which Cutter is regullary compiled is Ubuntu 16.04. It can be compiled there mostly with the packages from official repository. It is already somewhat annoying maintaining compatibility with CMake and Qt that old.

As can bee seen in the message error comes from tree sitter library not from the Cutter or radare2 source code. That is a dependency of a dependency of Cutter, asking about it here isn't the best place.
Debian 7 is not only past EOL, it is also past LTS and even extended LTS.

Anyway, I recommend to open a bug of better a pull request in tree-sitter library.

cc @ret2libc

@lars18th could you try this patch on your system? I tried to get a debian:wheezy container to test it but it couldn't even install packages.

diff --git a/libr/core/meson.build b/libr/core/meson.build
index 55dbc152c..937f9e100 100644
--- a/libr/core/meson.build
+++ b/libr/core/meson.build
@@ -102,6 +102,7 @@ r_core_deps = [
   platform_deps,
   gdb_dep,
   java_dep,
+  cc.find_library('rt', required: true),
   shell_parser_dep
 ]

Please let me know how it goes.

@lars18th could you try this patch on your system? I tried to get a debian:wheezy container to test it but it couldn't even install packages.

Please let me know how it goes.

Hi @ret2libc ,

Thank you! This patch fixes the error pointed. However, another one similar appears:

[1420/1507] Linking target binr/r2r/r2r
FAILED: binr/r2r/r2r
cc  -o binr/r2r/r2r binr/r2r/r2r.p/r2r.c.o binr/r2r/r2r.p/load.c.o binr/r2r/r2r.p/run.c.o -Wl,--as-needed -Wl,--no-undefined -Wl,--whole-archive -Wl,--start-group shlr/libr2sdb.a -Wl,--no-whole-archive libr/util/libr_util.so.4.5.0 shlr/libr2spp.a shlr/libr2zlib.a -ldl -lm -pthread -lutil -Wl,--end-group '-Wl,-rpath,$ORIGIN/../../libr/util:$ORIGIN/../../shlr' -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/util -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/shlr
binr/r2r/r2r.p/run.c.o: In function `r2r_subprocess_wait':
/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/../../../../radare2/binr/r2r/run.c:640: undefined reference to `clock_gettime'
/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/../../../../radare2/binr/r2r/run.c:678: undefined reference to `clock_gettime'
collect2: error: ld returned 1 exit status
[1422/1507] Linking target binr/rafind2/rafind2
ninja: build stopped: subcommand failed.
make[2]: *** [Radare2-Bundled-prefix/src/Radare2-Bundled-stamp/Radare2-Bundled-build] Error 1
make[1]: *** [CMakeFiles/Radare2-Bundled.dir/all] Error 2
make: *** [all] Error 2

Perhaps a similar patch will solve it.

Yes, ok that's perfect. I will provide a full patch and after you test it we can include it in r2.

Would be nice to cherry-pick it in 4.5.1 then after.

On Thu, Jul 23, 2020, 16:22 Riccardo Schirone notifications@github.com
wrote:

Yes, ok that's perfect. I will provide a full patch and after you test it
we can include it in r2.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/radareorg/cutter/issues/2316#issuecomment-662880662,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AABRT7PIRVDGX2VZB6KWBJDR47XNDANCNFSM4PE3XR7A
.

@lars18th Please try this:

From 809525685795f110e7c26e284c5a548b35696886 Mon Sep 17 00:00:00 2001
From: Riccardo Schirone <[email protected]>
Date: Thu, 23 Jul 2020 10:31:18 +0200
Subject: [PATCH] Make sure to use -lrt when needed to use clock_gettime
 ##meson

---
 binr/r2r/meson.build  | 5 +++--
 libr/core/meson.build | 1 +
 meson.build           | 6 ++++++
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/binr/r2r/meson.build b/binr/r2r/meson.build
index 5112c06da..d385577e4 100644
--- a/binr/r2r/meson.build
+++ b/binr/r2r/meson.build
@@ -3,10 +3,11 @@ if get_option('enable_r2r')
   executable('r2r', ['r2r.c', 'load.c', 'run.c'],
     include_directories: [platform_inc],
     dependencies: [
-      r_util_dep
+      r_util_dep,
+      lrt,
     ],
     install: true,
     install_rpath: rpath,
     implicit_include_directories: false
   )
-endif
\ No newline at end of file
+endif
diff --git a/libr/core/meson.build b/libr/core/meson.build
index 55dbc152c..9427f0927 100644
--- a/libr/core/meson.build
+++ b/libr/core/meson.build
@@ -102,6 +102,7 @@ r_core_deps = [
   platform_deps,
   gdb_dep,
   java_dep,
+  lrt,
   shell_parser_dep
 ]

diff --git a/meson.build b/meson.build
index 6d0386c79..c4cbd8604 100644
--- a/meson.build
+++ b/meson.build
@@ -352,6 +352,7 @@ foreach item : [
     ['explicit_bzero', '#include <string.h>'],
     ['explicit_memset', '#include <string.h>'],
     ['clock_nanosleep', '#include <time.h>'],
+    ['clock_gettime', '#include <time.h>'],
     ['sigaction', '#include <signal.h>']
   ]
   func = item[0]
@@ -359,6 +360,11 @@ foreach item : [
   userconf.set10('HAVE_@0@'.format(func.to_upper()), ok)
 endforeach

+lrt = ''
+if userconf.get('HAVE_CLOCK_GETTIME', 0) == 1 and cc.has_header_symbol('features.h', '__GLIBC__')
+  lrt = cc.find_library('rt', required: true)
+endif
+
 r_userconf_h = configure_file(
   input: 'libr/include/r_userconf.h.acr',
   output: 'r_userconf.h',
-- 
2.26.2

Hi @ret2libc ,

Testing the new patch, but it generates an error at start of the compilation:

Configuring libr.pc using configuration
Run-time dependency capstone found: NO (tried pkgconfig and cmake)
Message: Use bundled capstone
Run-time dependency tree-sitter found: NO (tried pkgconfig and cmake)
Message: Use bundled tree-sitter
Run-time dependency liblz4 found: NO (tried pkgconfig and cmake)
Message: Use bundled lz4
Run-time dependency zlib found: YES 1.2.7
Message: Use bundled zlib
Run-time dependency libzip found: YES 0.10.1
Message: Use bundled zip
Dependency threads found: YES unknown (cached)
Message: Use bundled magic library

../../../../radare2/libr/core/meson.build:114:0: ERROR: Argument is of an unacceptable type 'str'.
Must be either an external dependency (returned by find_library() or dependency()) or an internal dependency (returned by declare_dependency()).

A full log can be found at /home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/meson-logs/meson-log.txt
make[2]: *** [Radare2-Bundled-prefix/src/Radare2-Bundled-stamp/Radare2-Bundled-configure] Error 1
make[1]: *** [CMakeFiles/Radare2-Bundled.dir/all] Error 2
make: *** [all] Error 2

You know where is the problem?
(Note: Every time I delete the build directory and I start the compilation of Cutter from the start).
Regards.

Hi @ret2libc ,

I moddified your last patch with this simple hack: replace the two instances of the lrt, with the original cc.find_library('rt', required: true), and now the compilation continues. So the problem is some syntax error with the test.

Howerver, a third linking error appears:

[1482/1507] Linking target test/unit/test_r2r
FAILED: test/unit/test_r2r
cc  -o test/unit/test_r2r test/unit/test_r2r.p/test_r2r.c.o -Wl,--as-needed -Wl,--no-undefined -Wl,--whole-archive -Wl,--start-group shlr/libr2sdb.a -Wl,--no-whole-archive libr/util/libr_util.so.4.5.0 shlr/libr2spp.a shlr/libr2zlib.a libr/main/libr_main.so.4.5.0 libr/config/libr_config.so.4.5.0 libr/cons/libr_cons.so.4.5.0 libr/io/libr_io.so.4.5.0 libr/flag/libr_flag.so.4.5.0 libr/asm/libr_asm.so.4.5.0 libr/core/libr_core.so.4.5.0 libr/debug/libr_debug.so.4.5.0 libr/hash/libr_hash.so.4.5.0 libr/bin/libr_bin.so.4.5.0 libr/lang/libr_lang.so.4.5.0 libr/anal/libr_anal.so.4.5.0 libr/parse/libr_parse.so.4.5.0 libr/bp/libr_bp.so.4.5.0 libr/egg/libr_egg.so.4.5.0 libr/reg/libr_reg.so.4.5.0 libr/search/libr_search.so.4.5.0 libr/syscall/libr_syscall.so.4.5.0 libr/socket/libr_socket.so.4.5.0 libr/fs/libr_fs.so.4.5.0 libr/magic/libr_magic.so.4.5.0 libr/crypto/libr_crypto.so.4.5.0 -ldl -lm -pthread -lutil -Wl,--end-group '-Wl,-rpath,$ORIGIN/../../libr/util:$ORIGIN/../../shlr:$ORIGIN/../../libr/main:$ORIGIN/../../libr/config:$ORIGIN/../../libr/cons:$ORIGIN/../../libr/io:$ORIGIN/../../libr/socket:$ORIGIN/../../shlr/gdb:$ORIGIN/../../shlr/ptrace-wrap:$ORIGIN/../../libr/flag:$ORIGIN/../../libr/asm:$ORIGIN/../../libr/syscall:$ORIGIN/../../libr/parse:$ORIGIN/../../libr/reg:$ORIGIN/../../libr/lang:$ORIGIN/../../libr/core:$ORIGIN/../../libr/search:$ORIGIN/../../libr/anal:$ORIGIN/../../libr/crypto:$ORIGIN/../../libr/hash:$ORIGIN/../../libr/fs:$ORIGIN/../../libr/magic:$ORIGIN/../../libr/egg:$ORIGIN/../../libr/debug:$ORIGIN/../../libr/bp:$ORIGIN/../../libr/bin' -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/util -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/shlr -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/main -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/config -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/cons -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/io -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/socket -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/shlr/gdb -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/shlr/ptrace-wrap -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/flag -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/asm -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/syscall -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/parse -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/reg -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/lang -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/core -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/search -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/anal -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/crypto -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/hash -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/fs -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/magic -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/egg -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/debug -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/bp -Wl,-rpath-link,/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/libr/bin
test/unit/test_r2r.p/test_r2r.c.o: In function `r2r_subprocess_wait':
/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/../../../../radare2/test/unit/../../binr/r2r/run.c:640: undefined reference to `clock_gettime'
/home/user/cutter/build/Radare2-Bundled-prefix/src/Radare2-Bundled-build/../../../../radare2/test/unit/../../binr/r2r/run.c:678: undefined reference to `clock_gettime'
collect2: error: ld returned 1 exit status
[1484/1507] Compiling C object test/unit/test_sparse.p/test_sparse.c.o
ninja: build stopped: subcommand failed.
make[2]: *** [Radare2-Bundled-prefix/src/Radare2-Bundled-stamp/Radare2-Bundled-build] Error 1
make[1]: *** [CMakeFiles/Radare2-Bundled.dir/all] Error 2
make: *** [all] Error 2

@lars18th please paste the full meson output.

Hi @ret2libc ,

The compilation of the "radare2" is finished! Thank you for your contribution. Here the info to create a patch:

  • Three different points to include linking with the librt:

    • "binr/r2r/meson.build"

    • "meson.build"

    • "test/unit/meson.build" which requires this change:

77c77,78
<         r_magic_dep
---
>         r_magic_dep,
>         cc.find_library('rt', required: true),

Regarding the syntax error of the test to enable the librt, the full meson output doesn't print anything not included in the previous error paste. Sorry! I suspect the problem is because of the lack of parentheses regarding the operator AND. Please, check it.

Anyway, I need to comment that after the compilation of the "radare2" component the process fails regarding the Qt library. I'll try to update the stock version too.

In any case, please generate a new patch. I'll try to use it, and when it goes then you can merge it.
Thank you for your help! 👍
Regards.

Regarding the syntax error of the test to enable the librt, the full meson output doesn't print anything not included in the previous error paste. Sorry! I suspect the problem is because of the lack of parentheses regarding the operator AND. Please, check it.

Please do paste it anyway. I want to see whether it finds RT, __GLIBC__ and clock_gettime.

Regarding the syntax error of the test to enable the librt, the full meson output doesn't print anything not included in the previous error paste. Sorry! I suspect the problem is because of the lack of parentheses regarding the operator AND. Please, check it.

Please do paste it anyway. I want to see whether it finds RT, GLIBC and clock_gettime.

With your second patch, with the vanilla version or with my moddified patch?

This one #2316 (comment)

Here it is...

meson-log.txt

@lars18th please have a look at https://github.com/radareorg/radare2/pull/17345 . I think it fixes the problem for good. I could only test it on CentOS 6, because on debian:wheezy container I could not install any package. Let me know!

@lars18th please have a look at radareorg/radare2#17345 . I think it fixes the problem for good. I could only test it on CentOS 6, because on debian:wheezy container I could not install any package. Let me know!

Hi @ret2libc ,

This PR is working like a charm! The "radare2" module now is compiling. So please, merge it.

Anyway, here some aestetic warnings that perhaps you want to fix:

Found ninja-1.10.0 at /usr/local/bin/ninja
[295/1507] Compiling C object libr/util/libr_util.so.4.5.0.p/table.c.o
../../../../radare2/libr/util/table.c: In function ‘r_table_visual_list’:
../../../../radare2/libr/util/table.c:975:39: warning: universal character names are only valid in C++ and C99 [enabled by default]
[328/1507] Compiling C object libr/util/libr_util.so.4.5.0.p/print.c.o
../../../../radare2/libr/util/print.c: In function ‘r_print_columns’:
../../../../radare2/libr/util/print.c:76:42: warning: universal character names are only valid in C++ and C99 [enabled by default]
../../../../radare2/libr/util/print.c: In function ‘r_print_progressbar’:
../../../../radare2/libr/util/print.c:1550:42: warning: universal character names are only valid in C++ and C99 [enabled by default]
../../../../radare2/libr/util/print.c: In function ‘r_print_rangebar’:
../../../../radare2/libr/util/print.c:1569:42: warning: universal character names are only valid in C++ and C99 [enabled by default]
../../../../radare2/libr/util/print.c: In function ‘printHistBlock’:
../../../../radare2/libr/util/print.c:1664:42: warning: universal character names are only valid in C++ and C99 [enabled by default]
[1399/1507] Compiling C object test/unit/test_anal_block.p/test_anal_block.c.o
../../../../radare2/test/unit/test_anal_block.c: In function ‘test_r_anal_block_contains’:
../../../../radare2/test/unit/test_anal_block.c:59:2: warning: missing braces around initializer [-Wmissing-braces]
../../../../radare2/test/unit/test_anal_block.c:59:2: warning: (near initialization for ‘dummy._rb’) [-Wmissing-braces]

Regards.

Hi @XVilka ,

The problem of doing the same with Cutter is tricker since it requires relatively new Qt. I am not 100% sure if that Qt will even compile on that distribution.

Now, I'm compiling from scratch Qt5 as the stock version is not supported by Cutter. So I need to know the minimal Qt version required by Cutter. Any idea?

Regards.

Note: This is the log of the error with the stock Qt v5.3.2:

[ 13%] Building CXX object CMakeFiles/Cutter.dir/Main.cpp.o
In file included from /home/user/cutter/src/core/Cutter.h:4:0,
                 from /home/user/cutter/src/core/MainWindow.h:4,
                 from /home/user/cutter/src/CutterApplication.h:9,
                 from /home/user/cutter/src/Main.cpp:2:
/home/user/cutter/src/core/CutterCommon.h:65:56: error: missing binary operator before token "("
/home/user/cutter/src/core/CutterCommon.h: In function ‘QString RAddressString(RVA)’:
/home/user/cutter/src/core/CutterCommon.h:45:12: error: ‘asprintf’ is not a member of ‘QString’
/home/user/cutter/src/core/CutterCommon.h: In function ‘QString RSizeString(RVA)’:
/home/user/cutter/src/core/CutterCommon.h:50:12: error: ‘asprintf’ is not a member of ‘QString’
/home/user/cutter/src/core/CutterCommon.h: In function ‘QString RHexString(RVA)’:
/home/user/cutter/src/core/CutterCommon.h:55:12: error: ‘asprintf’ is not a member of ‘QString’
/home/user/cutter/src/Main.cpp: In function ‘int main(int, char**)’:
/home/user/cutter/src/Main.cpp:78:36: error: ‘AA_ShareOpenGLContexts’ is not a member of ‘Qt’
make[2]: *** [CMakeFiles/Cutter.dir/Main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Cutter.dir/all] Error 2
make: *** [all] Error 2

As I mentioned before Cutter is being tested against Ubuntu 16.04 with all system packages except meson. It has Qt 5.5.

Thank you @XVilka ! 👍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dhucul picture dhucul  Â·  3Comments

ITAYC0HEN picture ITAYC0HEN  Â·  4Comments

karliss picture karliss  Â·  3Comments

Maijin picture Maijin  Â·  5Comments

optizone picture optizone  Â·  3Comments