openigtlink / OpenIGTLink

Free, open-source network communication library for image-guided therapy
http://openigtlink.org
BSD 3-Clause "New" or "Revised" License
102 stars 184 forks source link

Build error on Ubuntu with GCC #247

Closed allemangD closed 3 years ago

allemangD commented 3 years ago

Building suddenly fails on Ubuntu 20.04 with gcc 8.4.0. I suspect I recently updated gcc or otherwise changed something in my configuration that caused the error (described below).

Steps to reproduce:

$ git clone https://github.com/openigtlink/OpenIGTLink
$ mkdir igt-build
$ cd igt-build
$ cmake -G 'Unix Makefiles' ../OpenIGTLink
$ make -j

Here are the full build logs: cmake.log make.log This is the relevant part:

/home/allem/tmp/OpenIGTLink/Source/igtlSocket.cxx: In member function ‘int igtl::Socket::Send(const void*, igtlUint64)’:
/home/allem/tmp/OpenIGTLink/Source/igtlSocket.cxx:339:75: error: ‘numeric_limits’ is not a member of ‘std’
     int n = send(this->m_SocketDescriptor, buffer + total, (length > std::numeric_limits<int>::max()) ? std::numeric_limits<int>::max() : length-total, flags);

/home/allem/tmp/OpenIGTLink/Source/igtlSocket.cxx: In member function ‘igtlUint64 igtl::Socket::Receive(void*, igtlUint64, bool&, int)’:
/home/allem/tmp/OpenIGTLink/Source/igtlSocket.cxx:368:75: error: ‘numeric_limits’ is not a member of ‘std’
     int n = recv(this->m_SocketDescriptor, buffer + total, (length > std::numeric_limits<int>::max() ? std::numeric_limits<int>::max() : length - total), 0);   

It seems the same as the issue described in gitlab.com/wg1/jpeg-xl#84:

It's because of GCC 11: https://www.gnu.org/software/gcc/gcc-11/porting_to.html

Header dependency changes

Some C++ Standard Library headers have been changed to no longer include other headers that they do need to depend on. As such, C++ programs that used standard library components without including the right headers will no longer compile.

The following headers are used less widely in libstdc++ and may need to be included explicitly when compiled with GCC 11:

<limits> (for std::numeric_limits)
<memory> (for std::unique_ptr, std::shared_ptr etc.)
<utility> (for std::pair, std::tuple_size, std::index_sequence etc.)

Adding an explicit #include <limits> to igtlSocket.cxx solves the issue. I'll create a PR shortly.