Trouble building 3.15.8 using cmake on CentOS 7

417 views
Skip to first unread message

Nathan Cooprider

unread,
Jun 29, 2022, 5:14:08 PM6/29/22
to Protocol Buffers
I can build the protocol buffers (https://github.com/protocolbuffers/protobuf/tree/v3.15.8) using gcc on CentOS 7 or using clang on my Mac, but not using clang on CentOS 7. I feel like I'm missing something obvious.

$ unzip protobuf-3.15.8.zip
$ cd protobuf-3.15.8

# on my Mac (host machine)
$ mkdir build_on_mac
$ cd build_on_mac
$ cmake ../cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -Dprotobuf_BUILD_TESTS=OFF
$ make
$ cd ..

# on my CentOS 7 box (currently a VM, but have an actual box too)
$ mkdir build_on_linux
$ cd build_on_linux
$ cmake ../cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -Dprotobuf_BUILD_TESTS=OFF
$ make

That second one gets me this: 
. . .
[ 31%] Building CXX object CMakeFiles/libprotobuf.dir/vagrant/protobuf-3.15.8/src/google/protobuf/any.cc.o
In file included from /vagrant/protobuf-3.15.8/src/google/protobuf/any.cc:34:
In file included from /vagrant/protobuf-3.15.8/src/google/protobuf/descriptor.h:65:
/vagrant/protobuf-3.15.8/src/google/protobuf/stubs/mutex.h:117:7: warning:
      unknown attribute 'capability' ignored [-Wattributes]
class GOOGLE_PROTOBUF_CAPABILITY("mutex") PROTOBUF_EXPORT WrappedMutex {
      ^
/vagrant/protobuf-3.15.8/src/google/protobuf/stubs/mutex.h:55:54: note:
      expanded from macro 'GOOGLE_PROTOBUF_CAPABILITY'
#define GOOGLE_PROTOBUF_CAPABILITY(x) __attribute__((capability(x)))
                                                     ^
/vagrant/protobuf-3.15.8/src/google/protobuf/stubs/mutex.h:120:15: warning:
      unknown attribute 'acquire_capability' ignored [-Wattributes]
  void Lock() GOOGLE_PROTOBUF_ACQUIRE() { mu_.lock(); }
              ^
/vagrant/protobuf-3.15.8/src/google/protobuf/stubs/mutex.h:52:18: note:
      expanded from macro 'GOOGLE_PROTOBUF_ACQUIRE'
  __attribute__((acquire_capability(__VA_ARGS__)))
                 ^
/vagrant/protobuf-3.15.8/src/google/protobuf/stubs/mutex.h:121:17: warning:
      unknown attribute 'release_capability' ignored [-Wattributes]
  void Unlock() GOOGLE_PROTOBUF_RELEASE() { mu_.unlock(); }
                ^
/vagrant/protobuf-3.15.8/src/google/protobuf/stubs/mutex.h:54:18: note:
      expanded from macro 'GOOGLE_PROTOBUF_RELEASE'
  __attribute__((release_capability(__VA_ARGS__)))
                 ^
In file included from /vagrant/protobuf-3.15.8/src/google/protobuf/any.cc:36:
/vagrant/protobuf-3.15.8/src/google/protobuf/message.h:234:13: error: constexpr
      constructor never produces a constant expression [-Winvalid-constexpr]
  constexpr Message() {}
            ^
/vagrant/protobuf-3.15.8/src/google/protobuf/message.h:234:13: note:
      non-literal type 'google::protobuf::MessageLite' cannot be used in a
      constant expression
3 warnings and 1 error generated.
make[2]: *** [CMakeFiles/libprotobuf.dir/vagrant/protobuf-3.15.8/src/google/protobuf/any.cc.o] Error 1
make[1]: *** [CMakeFiles/libprotobuf.dir/all] Error 2
make: *** [all] Error 2

I'd like to use clang for cross compiling and toolchain consistency reasons. That's the error I get both in my VM and on my actual machine.

Additional info:
$ uname -a ; cmake --version ; clang --version
Linux localhost.localdomain 3.10.0-1160.15.2.el7.x86_64 #1 SMP Wed Feb 3 15:06:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
cmake version 3.23.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).
clang version 3.4.2 (tags/RELEASE_34/dot2-final)
Target: x86_64-redhat-linux-gnu
Thread model: posix

Thanks for any help you can provide. 

Nathan

David Jones

unread,
Jun 29, 2022, 7:17:42 PM6/29/22
to Nathan Cooprider, Protocol Buffers
Hey Nathan,

Capabilities were introduced (IIRC) in Clang 3.5 or so. The version you have (3.4.2) is, I think, too old.

There was a support document recently published which outlines some of what you can expect for building Google libraries:
That doc points to devtoolset-7 as the special requirement for older versions of RHEL. I would agree with its advice to use Clang/LLVM 6 or newer... there are some non-trivial C++ Language Defect Reports (i.e., bugs in the C++ standard) that were addressed in the [3.4, 6.0) range, but those fixes don't generally get ported back. With the Protobuf 3.15 series, you might get by with Clang 3.6 or newer, but especially going forward, you might want to consider Clang 6 (or newer) as a hard requirement.

In your case, you mention specifically wanting consistency. Since your Mac is (presumably) using Apple Clang from Xcode, it probably corresponds to Clang/LLVM version 12 or 13. There are some pretty significant changes since Clang 6, especially around diagnostics, so the closer you can get, the better. Note also that macOS uses (LLVM's) libc++, while CentOS will generally use (GCC's) libstdc++... those have very different implementations, and slightly different behavior near the edges of the C++ standard.

It looks like RHEL has LLVM toolchain packages up to version 13, although I can't find corresponding CentOS packages. You might have some luck with the RHEL releases from https://releases.llvm.org/download.html .

Hope that helps...
--dlj

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/7ba0a048-be95-42f0-9af0-d89067d410a7n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages