Jump to content

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.

Link to comment
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

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 years later...
On 3/16/2019 at 3:33 PM, Philipp A Hartmann said:

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

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

Hello Philipp,
May I know what is the state of C++20 support for SystemC? When I tried to build a project with C++20 I got a linker error. I tried to find a suitable preprocessor switch for C++20 in the INSTALL notes but there isn't any. Kindly let me know.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...