Jump to content
sheridp@umich.edu

Build error SystemC 2.3.3 with C++17

Recommended Posts

The following Dockerfile will reproduce the problem:

FROM alpine:3.9 as builder

RUN apk add --no-cache build-base linux-headers

WORKDIR /opt

FROM builder as builder_systemc

COPY systemc-2.3.3.gz /opt

RUN mkdir /opt/systemc_src && \
    tar -xf systemc-2.3.3.gz -C /opt/systemc_src --strip-components=1 && \
    cd /opt/systemc_src && ./configure --prefix /opt/systemc-2.3.3 --enable-debug CXXFLAGS="-DSC_CPLUSPLUS=201703L" && \
    make -j$(nproc) && \
    make install

Which results in the following error:

  CXX      kernel/sc_simcontext.lo
In file included from kernel/sc_simcontext.cpp:57:
../../src/sysc/utils/sc_string_view.h:62:29: error: 'string_view' in namespace 'std' does not name a type
 typedef SC_STRING_VIEW_NS_::string_view sc_string_view;
                             ^~~~~~~~~~~

It looks like the following is related:

#if SC_CPLUSPLUS >= 201402L && defined(__has_include)
#  if SC_CPLUSPLUS > 201402L && __has_include(<string_view>) /* since C++17 */
#    define SC_STRING_VIEW_NS_ std
#    include <string_view>
   /*  available in Library Fundamentals, ISO/IEC TS 19568:2015 */
#  elif __has_include(<experimental/string_view>)
#    define SC_STRING_VIEW_NS_ std::experimental
#    include <experimental/string_view>
#  endif
#else
// TODO: other ways to detect availability of std::(experimental::)string_view?
#endif

I'm guessing that defining SC_CPLUSPLUS did not cause the -std=c++17 flag to be passed to the compiler, because <string_view> contains the following:

#if __cplusplus >= 201703L

 

Update:

Modifying the ./configure command to:

./configure --prefix /opt/systemc-2.3.3 --enable-debug CXXFLAGS="-DSC_CPLUSPLUS=201703L -std=c++17"

solves the problem. 

It might be worthwhile mentioning this in the INSTALL notes.

Share this post


Link to post
Share on other sites

The INSTALL notes currently say the following about the SC_CPLUSPLUS preprocessor switch (emphasis mine):

Quote

 

This setting allows downgrading the assumed version of the underlying C++ standard on the current platform.  By default, the latest supported version is chosen.

Supported values are

  • SC_CPLUSPLUS=199701L (C++03, ISO/IEC 14882:1998, 14882:2003)
  • SC_CPLUSPLUS=201103L (C++11, ISO/IEC 14882:2011)
  • SC_CPLUSPLUS=201402L (C++14, ISO/IEC 14882:2014)
  • SC_CPLUSPLUS=201703L (C++17, ISO/IEC 14882:2017)

 

This means, that you can explicitly opt-out of some SystemC features, that would generally be supported by your compiler's C++ language support.  Selecting a newer C++ standard version than supported by your compiler (setup) will typically not work - as you have experienced.

That said, adding a preprocessor flag on the compiler command-line does not affect the language mode of the compiler.  How to switch your compiler to C++17 mode is outside of the scope of SystemC.  Your compiler (version) seems to require the -std=c++17 switch to enable this mode.  The SC_CPLUSPLUS flag is then not needed as it will be set automatically to the selected version.

Hope that helps,
  Philipp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×