Menu

#152 Compilation error on tests with glibc >=2.31

Feature Request
closed-accepted
5
2023-03-12
2020-02-19
No

As per the glibc documentation:
Starting with glibc 2.31, this function is no longer available to
newly linked applications and is no longer declared in <time.h>.</time.h>

This causes a compilation error in the tests:

 testDailyRollingFileAppender.cpp:43:35: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
   43 | const char* const nesteddirname = "nesteddir"PATHDELIMITER;
      |                                   ^
testDailyRollingFileAppender.cpp: In functionint OnlyManualTesting::jumpToFuture(int)’:
testDailyRollingFileAppender.cpp:235:7: error: ‘stimewas not declared in this scope; did you mean ‘ctime’?
  235 |   if (stime(&now) == -1) {
      |       ^~~~~
      |       ctime

System information:

$ uname -a
Linux ncerndobedev6196 4.12.14-95.45-default #1 SMP Wed Dec 11 13:09:13 UTC 2019 (12c8180) x86_64 x86_64 x86_64 GNU/Linux
$ libc.so.6 --version
GNU C Library (GNU libc) stable release version 2.31.
Copyright (C) 2020 Free Software Foundation, Inc.
$ /gcc --version
gcc (GCC) 10.0.1 20200211 (experimental)
Copyright (C) 2020 Free Software Foundation, Inc.

I propose this patch:

--- tests/testDailyRollingFileAppender.cpp.old  2020-02-19 08:59:32.990751857 +0000
+++ tests/testDailyRollingFileAppender.cpp      2020-02-19 09:00:55.467558182 +0000
@@ -232,7 +232,9 @@

                now += seconds;

-               if (stime(&now) == -1) {
+        timespec ts = {};
+        ts.tv_sec = now;
+        if (clock_settime(CLOCK_REALTIME, &ts) != 0) {
                        std::cerr << "Can not set date. Need admin privileges?" << std::endl;
                        return -1;
                }

Regards,
Stac

Discussion

  • Alexander Perepelkin

    • status: open --> closed-accepted
    • assigned_to: Alexander Perepelkin
     
  • Alexander Perepelkin

    Thanks for the patch!
    Merged into the repository at c383936fcb74f587ef529f618270b651a741859f (tag REL_1.1.4rc3_Mar_12_2023,), with the fallback to stime function where applicable.
    Available too as log4cpp-1.1.4rc3.tar.gz

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.