Wednesday, May 10, 2017

Error compiling SystemC-2.2 with GCC 4.9

GCC now requires some headers to be explicitly defined (whereas in the past they were implicitly included when some functions were used). When trying to compile SystemC-2.2.0 with GCC 4.9 (or latter) the following error is raised:

g++ -I. -I. -I. -I../../../src  -fpermissive  -Wall -DSC_USE_PTHREADS -DSC_INCLUDE_FX -O3 -c -o sc_utils_ids.o `test -f 'sc_utils_ids.cpp' || echo './'`sc_utils_ids.cpp
sc_utils_ids.cpp: In function ‘int sc_core::initialize()’:
sc_utils_ids.cpp:109:36: error: ‘getenv’ is not a member of ‘std’
     const char* deprecation_warn = std::getenv("SC_DEPRECATION_WARNINGS");


This can be solved removing the std:: before getenv, and adding the #include <stdlib.h> header.

In addition to this, #include <string.h> must be also included, otherwise the following error is raised:

sc_utils_ids.cpp: In function ‘int sc_core::initialize()’:
sc_utils_ids.cpp:110:69: error: ‘strcmp’ was not declared in this scope
     if ( (deprecation_warn!=0) && !strcmp(deprecation_warn,"DISABLE") )

Compiling SystemC-2.2.0 with newer versions of GCC

When trying to make SystemC-2.2 with newer (post 4.7?) versions of GCC, the process fails with the following error:

In file included from ../../../src/sysc/datatypes/bit/sc_bv_base.h:47:0,
                 from ../../../src/sysc/datatypes/bit/sc_lv_base.h:50,
                 from sc_signal.cpp:95:
../../../src/sysc/datatypes/bit/sc_bit_proxies.h:698:16: error: reference ‘m_obj’ cannot be declared ‘mutable’ [-fpermissive]
     mutable X& m_obj;
                ^
../../../src/sysc/datatypes/bit/sc_bit_proxies.h:1175:18: error: reference ‘m_left’ cannot be declared ‘mutable’ [-fpermissive]
     mutable X&   m_left;
                  ^
../../../src/sysc/datatypes/bit/sc_bit_proxies.h:1176:18: error: reference ‘m_right’ cannot be declared ‘mutable’ [-fpermissive]
     mutable Y&   m_right;
                  ^
../../../src/sysc/datatypes/bit/sc_bit_proxies.h:1178:18: error: reference ‘m_refs’ cannot be declared ‘mutable’ [-fpermissive]
     mutable int& m_refs;

The error is caused by the increasingly strict parser in GCC; syntax that used to be OK is now failing to compile.

To fix the issue simply set the EXTRA_CXXFLAGS environment variable to -fpermissive, then configure again with ./configure, then recompile with make.