0

When compiling with ninja on Ubuntu 18.04 with gcc11, I get multiple instances of the error: expected ‘;’ before ‘static’
Here is an example of one part of the code which is causing the issue, specifically column 18 of the first line:

 G_GNUC_NO_INLINE static GType
gvo_comparable_get_type_once (void)
{
    static const GTypeInfo g_define_type_info = { sizeof (GVoComparableIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gvo_comparable_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
    GType gvo_comparable_type_id;
    gvo_comparable_type_id = g_type_register_static (G_TYPE_INTERFACE, "GVoComparable", &g_define_type_info, 0);
    g_type_interface_add_prerequisite (gvo_comparable_type_id, G_TYPE_OBJECT);
    return gvo_comparable_type_id;
}

The macro G_GNUC_NO_INLINE expands to: __attribute__ ((__noinline__)) but I do not see why this would cause an issue.

When compiling the exact same code with ninja on Windows 10 with gcc 10.3.0 via msys2, the error doesn't occur.
The error also occurred with gcc 7.5.0 on Ubuntu.

The C code is generated by the valac compiler.
Vala 0.52.4 on Windows.
Vala 0.54.2.30 on Ubuntu.
I previously used 0.52.2 on Ubuntu, but the error still occured.

I do not know if this is because a compiler flag is missing? Otherwise I do not know why this error only occurs on Ubuntu.

Here are the default gcc compiler flags on Ubuntu:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.1.0-1ubuntu1~18.04.1' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --disable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-YRKbe7/gcc-11-11.1.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-YRKbe7/gcc-11-11.1.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.0 (Ubuntu 11.1.0-1ubuntu1~18.04.1)

Here are the default gcc compiler flags on Windows:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-10.3.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --with-arch=x86-64 --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-lto --enable-libgomp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev5, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --with-boot-ldflags='-pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high -Wl,--disable-dynamicbase -static-libstdc++ -static-libgcc' 'LDFLAGS_FOR_TARGET=-pipe -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high' --enable-linker-plugin-flags='LDFLAGS=-static-libstdc++\ -static-libgcc\ -pipe\ -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high\ -Wl,--stack,12582912'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.3.0 (Rev5, Built by MSYS2 project)
DEFAULT
  • 37
  • 1
  • 2
  • 5
  • It seems that attributes go between return type and function in GCC. See https://stackoverflow.com/a/1474050/551045 – RedX Nov 10 '21 at 12:42
  • The macro isn't being expanded. You can test this by adding `#define G_GNUC_NO_INLINE __attribute__ ((__noinline__))` to the top of the file. You're probably missing an include, or some compile-time option. – Tom Karzes Nov 10 '21 at 12:43
  • Possibly. But according to this page https://libsoup.org/glib/glib-Miscellaneous-Macros.html#G-GNUC-NO-INLINE:CAPS putting it before static should be ok. – DEFAULT Nov 10 '21 at 12:45
  • 1
    The order is fine. You're simply missing the macro definition, so it's not being expanded. Do the test that I described and you'll see that I'm right. As it is, it's behaving exactly as it would if you used any random identifier in place of the gnu macro. – Tom Karzes Nov 10 '21 at 12:47
  • It could possibly be a macro expansion issue, but I don't see why there would be a difference between ubuntu and Windows. I will try and define it using -D and see if it makes a difference. – DEFAULT Nov 10 '21 at 12:48
  • It's different because they're two different compiler installs, with different libraries, paths, etc. Just try it. I think the macro you're looking for is defined in `glib.h`, which isn't installed by default on Ubuntu (I'm not certain about this). Try to look it up. At least you know what the problem is now. – Tom Karzes Nov 10 '21 at 12:49
  • Ah ok. I will look into that. Thanks for your help. – DEFAULT Nov 10 '21 at 12:58

1 Answers1

0

The macro G_GNUC_NO_INLINE was not correctly defined on Ubuntu.
Defining it manually using -D fixed the issue.

This also could have been caused by a missing library/package.

klutt
  • 30,332
  • 17
  • 55
  • 95
DEFAULT
  • 37
  • 1
  • 2
  • 5
  • You could also do `#ifdef G_GNUC_NO_INLINE #define NO_INLINE G_GNUC_NO_INLINE #else #define NO_INLINE #endif`... `NO_INLINE static foo (...)` – Lundin Nov 10 '21 at 15:12