Unable to build FreeFileSync 14.9 on Ubuntu 26.04

Get help for specific problems
User avatar
Posts: 23
Joined: 13 Mar 2021

xtradeb

Hi @Zenju!

I'm unable to build Freefilesync 14.9 on Ubuntu 26.04 (resolute) due to this error:
In file included from ../../zen/globals.h:12,
                 from ../../zen/i18n.h:10,
                 from <command-line>:
afs/ftp.cpp: In lambda function:
/usr/include/glib-2.0/glib/gmem.h:172:3: error: expected id-expression before ‘(’ token
  172 |   (__builtin_object_size ((mem), 0) != ((size_t) - 1)) ?                       \
      |   ^
../../zen/scope_guard.h:90:145: note: in definition of macro ‘ZEN_ON_SCOPE_EXIT’
   90 | #define ZEN_ON_SCOPE_EXIT(X)    [[maybe_unused]] auto ZEN_CONCAT(scopeGuard, __LINE__) = zen::makeGuard<zen::ScopeGuardRunMode::onExit   >([&]{ X; });
      |                                                                                                                                                 ^
afs/ftp.cpp:124:25: note: in expansion of macro ‘g_free’
  124 |     ZEN_ON_SCOPE_EXIT(::g_free(utfStr));
      |                         ^~~~~~
compilation terminated due to -Wfatal-errors.
make[2]: *** [Makefile:144: /tmp/FreeFileSync_Make/ffs/src/afs/ftp.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from ../../zen/error_log.h:12,
                 from ../../zen/extra_log.h:10,
                 from ../../zen/sys_error.h:13,
                 from base/icon_loader.cpp:12:
../../zen/time.h:262:26: warning: macro ‘__DATE__’ might prevent reproducible builds [-Wdate-time]
  262 |     char compileTime[] = __DATE__ " " __TIME__; //e.g. "Aug  1 2017 01:32:26"
      |                          ^~~~~~~~
../../zen/time.h:262:39: warning: macro ‘__TIME__’ might prevent reproducible builds [-Wdate-time]
  262 |     char compileTime[] = __DATE__ " " __TIME__; //e.g. "Aug  1 2017 01:32:26"
      |                                       ^~~~~~~~
In file included from ../../zen/globals.h:12,
                 from ../../zen/i18n.h:10,
                 from <command-line>:
base/icon_loader.cpp: In lambda function:
/usr/include/glib-2.0/glib/gmem.h:172:3: error: expected id-expression before ‘(’ token
  172 |   (__builtin_object_size ((mem), 0) != ((size_t) - 1)) ?                       \
      |   ^
../../zen/scope_guard.h:90:145: note: in definition of macro ‘ZEN_ON_SCOPE_EXIT’
   90 | #define ZEN_ON_SCOPE_EXIT(X)    [[maybe_unused]] auto ZEN_CONCAT(scopeGuard, __LINE__) = zen::makeGuard<zen::ScopeGuardRunMode::onExit   >([&]{ X; });
      |                                                                                                                                                 ^
This is the full build log:
freefilesync14.9_build_on_Ubuntu26.04.txt
(232.18 KiB) Downloaded 8 times
.

Can you help?

Thank you!
Jhonny Oliveira
https://xtradeb.net
Posts: 58
Joined: 14 Aug 2022

daviank

Strangely this doesn't happen on debian testing (glib2.0 2.88.0-1, like resolute), neither on debian sid (2.88.1-2)

You have to change the "ZEN_ON_SCOPE_EXIT(::g_free" to "ZEN_ON_SCOPE_EXIT(g_free" (remove the two colon before g_free) in all files where there is this. I have found 4 occurrences.

It could be related to the version of gcc and the preprocessor. But I'm rather usure.
gcc doesn's seem to like the output of the preprocessorw when using ZEN_ON_SCOPE_EXIT macro & ::g_free macro.

The kind of fix is similar to https://sources.debian.org/src/freefilesync/13.7-3/debian/patches/ffs_icon_loader.patch but I haven't investigated the real reason. However in this case, it doesn't seem related to the glib2.0 version since on Debian testing, which has the same glib2.0 version as Ubuntu resolute, it builds fine.

To investigate, you'll probably have to look at the preprocessor output (using "g++ -E") and find out what happens.
Posts: 58
Joined: 14 Aug 2022

daviank

In the build of glib-2.0 2.88.0-1, we have
- Checking for function "free_sized" : NO [on Debian] https://buildd.debian.org/status/fetch.php?pkg=glib2.0&arch=amd64&ver=2.88.0-1&stamp=1773702037&raw=0
- Checking for function "free_sized" : YES [on Ubuntu Resolute] https://launchpadlibrarian.net/852312891/buildlog_ubuntu-resolute-amd64.glib2.0_2.88.0-1_BUILDING.txt.gz

This directly impacts glib "/usr/include/glib-2.0/glib/gmem.h" at this point. Glib apparently "overrides" it's g_free function by this macro.
#if G_GNUC_CHECK_VERSION (4, 1) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_78 && defined(G_HAVE_FREE_SIZED)

#define g_free(mem)                                                            \
  (__builtin_object_size ((mem), 0) != ((size_t) - 1)) ?                       \
    g_free_sized (mem, __builtin_object_size ((mem), 0)) : (g_free) (mem)

#endif /* G_GNUC_CHECK_VERSION (4, 1) && && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_78 && defined(G_HAVE_FREE_SIZED) */
From what I understand, g_free is defined as a macro when Glib2 version >= 2.78 & free_sized is available. This is the case in Ubuntu but not on Debian.

So on Ubuntu resolute the preprocessor will produce this incorrect syntax.
    [[maybe_unused]] auto scopeGuard167 = zen::makeGuard<zen::ScopeGuardRunMode::onExit >([&]{ ::(__builtin_object_size ((contentType), 0) != ((size_t) - 1)) ? g_free_sized (contentType, __builtin_object_size ((contentType), 0)) : (g_free) (contentType); });;
I think the scope resolution operator "::" doesn't make sense in that case and is the cause of the error.
It is correct to use it though when g_free isn't defined as a macro in glib.

Zenju, would you please merge this patch to your code? It would fix the error in a way that it works in both cases.
Attachments
glib2-2.78-free_size-Fix-build-when-g_free-macro-is-defined.patch
(4.54 KiB) Downloaded 11 times
User avatar
Posts: 23
Joined: 13 Mar 2021

xtradeb

I confirm daviank’s patch works.
Many thanks to you both!