Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0.0 linux compilation error due to: "undefined reference to `clock_gettime'" #2453

Closed
KristofferC opened this issue Dec 11, 2021 · 6 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@KristofferC
Copy link
Contributor

I am getting the following error when attempting to compile v3.0.0 on a linux machine (GCC 7.1.0):

[21:13:06] CMakeFiles/notcurses-demo.dir/src/demo/demo.c.o: In function `main':
[21:13:06] demo.c:(.text.startup+0x3e3): undefined reference to `clock_gettime'
[21:13:06] demo.c:(.text.startup+0x5a6): undefined reference to `clock_gettime'
[21:13:06] demo.c:(.text.startup+0x704): undefined reference to `clock_gettime'
[21:13:06] CMakeFiles/notcurses-demo.dir/src/demo/animate.c.o: In function `animate_demo':
[21:13:06] animate.c:(.text+0xbbe): undefined reference to `clock_gettime'
[21:13:06] CMakeFiles/notcurses-demo.dir/src/demo/highcon.c.o: In function `highcon_demo':
[21:13:06] highcon.c:(.text+0x3b8): undefined reference to `clock_gettime'
[21:13:06] CMakeFiles/notcurses-demo.dir/src/demo/highcon.c.o:highcon.c:(.text+0x57d): more undefined references to `clock_gettime' follow
[21:13:06] collect2: error: ld returned 1 exit status

Doing something like:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d9b9f0f79..7bb9ad13b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -144,6 +144,7 @@ if(WIN32)
 elseif(NOT APPLE)
   find_library(LIBM m REQUIRED)
   find_library(LIBRT rt REQUIRED)
+  set(LIBRT_LIBRARIES rt)
 endif()
 if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
   include_directories(/usr/local/include)
@@ -679,6 +680,7 @@ target_include_directories(ncneofetch
 target_link_libraries(ncneofetch
   PRIVATE
     notcurses
+    "${LIBRT_LIBRARIES}"
 )
 
 # documentation source, processed by pandoc into XHTML and man pages. declare

seems to fix it, but I am not experienced enough to know if that makes sense.

@KristofferC KristofferC added the bug Something isn't working label Dec 11, 2021
@dankamongmen dankamongmen self-assigned this Dec 11, 2021
@dankamongmen dankamongmen added this to the 4.0.0 milestone Dec 11, 2021
@dankamongmen
Copy link
Owner

good find, good fix. that's a fairly old GCC, but we ought work with it. what distro is this, just for my edification?

your fix looks pretty much right. would you like to make a PR out of it, so you get the commit credit? if not, i'll commit it myself.

@dankamongmen
Copy link
Owner

sure enough, " Link with -lrt (only for glibc versions before 2.17)."

@dankamongmen
Copy link
Owner

we actually needed it a few more places, and the desired syntax was a bit different. i believe i've fixed this in b5ccc9d; please verify and let me know! thanks!

@KristofferC
Copy link
Contributor Author

Thanks for the quick reply and speedy fix. With b5ccc9d things mostly work but I also needed:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c5ed5c171..af94f8fb4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -599,6 +599,7 @@ target_include_directories(notcurses-info
 target_link_libraries(notcurses-info
   PRIVATE
     notcurses
+    "${LIBRT}"
 )
 
 ############################################################################
@@ -616,6 +617,8 @@ target_include_directories(notcurses-input
 target_link_libraries(notcurses-input
   PRIVATE
     notcurses++
+    "${LIBRT}"
+
 )
 
 ############################################################################
@@ -633,6 +636,7 @@ target_include_directories(nctetris
 target_link_libraries(nctetris
   PRIVATE
     notcurses++
+    "${LIBRT}"
 )
 endif()
 
@@ -678,6 +682,7 @@ target_include_directories(ncneofetch
 target_link_libraries(ncneofetch
   PRIVATE
     notcurses
+    "${LIBRT}"
 )
 
 # documentation source, processed by pandoc into XHTML and man pages. declare

that's a fairly old GCC, but we ought work with it. what distro is this, just for my edification?

For context, this came up on a synthetic Alpine linux system which only purpose is to cross-compile libraries to a large number of architectures for use by the Julia Language package manager to deliver binaries to users. It is using an old glibc is to try get maximum compatibility with a large variety of users system, since a binary compiled on an older glibc will work on a system with a newer one but not vice versa. If you are at all interested the system is described shortly in https://youtu.be/S__x3K31qnE?t=264 and you can see the WIP for building notcurses with it in JuliaPackaging/Yggdrasil#4059 where it is built for:

aarch64-apple-darwin
aarch64-linux-gnu
aarch64-linux-musl
armv6l-linux-gnueabihf
armv6l-linux-musleabihf
armv7l-linux-gnueabihf
armv7l-linux-musleabihf
i686-linux-gnu
i686-linux-musl
i686-w64-mingw32
powerpc64le-linux-gnu
x86_64-apple-darwin
x86_64-linux-gnu
x86_64-linux-musl
x86_64-unknown-freebsd
x86_64-w64-mingw32

Looking at the builders in JuliaPackaging/Yggdrasil#4059, the current status seems to be that it builds on most platforms with the exception of:

Apple M1 (aarch64-apple-darwin):

[09:24:03] Undefined symbols for architecture arm64:
[09:24:03]   "___divdc3", referenced from:
[09:24:03]       _normal_demo in normal.c.o
[09:24:03] ld: symbol(s) not found for architecture arm64
[09:24:03] clang-12: error: linker command failed with exit code 1 (use -v to see invocation)

Windows (this one is funny, libdeflate is found by CMake but then immidiately set to NOTFOUND).

[09:23:57] -- The following REQUIRED packages have been found:
[09:23:57] 
[09:23:57]  * PkgConfig
[09:23:57]  * terminfo
[09:23:57]  * Threads
[09:23:57]  * libunistring
[09:23:57]  * libdeflate
[09:23:57] 
[09:23:57] -- Configuring done
[09:23:57] CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
[09:23:57] Please set them or make sure they are set and tested correctly in the CMake files:
[09:23:57] libdeflate
[09:23:57]     linked by target "notcurses-core" in directory /workspace/srcdir/notcurses-3.0.0

FreeBSD - Couldn't find unigbrk.h from GNU libunistrin�g. Not sure what is going on here.

@dankamongmen
Copy link
Owner

outstanding, thanks for all the info.

the libdeflate one is surprising -- i use libdeflate in MSYS2 without issues.

dankamongmen added a commit that referenced this issue Dec 12, 2021
thanks Kristoffer Carlsson <kcarlsson89@gmail.com>!
@dankamongmen
Copy link
Owner

i've applied your patch from above, and hopefully this solves all remaining problems. thanks a ton!

@dankamongmen dankamongmen modified the milestones: 4.0.0, 3.1.0 Dec 12, 2021
KristofferC pushed a commit to KristofferC/notcurses that referenced this issue Dec 13, 2021
KristofferC pushed a commit to KristofferC/notcurses that referenced this issue Dec 13, 2021
thanks Kristoffer Carlsson <kcarlsson89@gmail.com>!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants