davidbp13 Posted April 15, 2020 Report Share Posted April 15, 2020 Hi, I'm implemented a small virtual prototype using SystemC. The CPU model of my system is very simple and only has a function read and a function to write to a memory mapped address. I need to be able to call this functions from a C file, not a C++ file. Hoewver, when trying to do this and compile everything together I get an error: /cad/gnu/gcc/systemc-2.3.1/include/sysc/packages/boost/config/select_stdlib_config.hpp:20:19: fatal error: utility: No such file or directory #include <utility> ^ compilation terminated. make[2]: *** [prj/CMakeFiles/mpslvp.x.dir/src/mpslvp/c_test.c.o] Error 1 make[1]: *** [prj/CMakeFiles/mpslvp.x.dir/all] Error 2 make: *** [all] Error 2 The problem has to do with the fact that my C file includes the header file of the CPU module which of course includes the systemc library. When removing the systemc dependencies, the code compiles. Is it possible to have a C file implementing functions that indirectly start a SystemC transaction? Hope I explained myself. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
David Black Posted April 15, 2020 Report Share Posted April 15, 2020 You cannot compile C++ under a C compiler and SystemC is C++. You will need to create an extern "C" wrapper and you will need to deal with maintaining objects. This is really a C++ issue and you should probably read <https://isocpp.org/wiki/faq/mixing-c-and-cpp>. Quote Link to comment Share on other sites More sharing options...
davidbp13 Posted April 15, 2020 Author Report Share Posted April 15, 2020 Thanks for your reply David! So using g++ to compile instead of gcc may fix my issue? If so, do I still need extern C wrappers when using a c++ compiler? Also, how much of a straight forward solution is moving my c files to cpp files only? Thansk! Quote Link to comment Share on other sites More sharing options...
Bas Arts Posted April 16, 2020 Report Share Posted April 16, 2020 If you separate application code and read/write implementation code, you can keep your C code application and compile it still for your CPU module. Yes, you will need a C++ compiler then, but it also allows you to port your application to e.g. a commercial CPU model which could use plain C. You'd only need to replace your read/write C++ implementation with a C implementation. // C header file #ifndef C_H #define C_H #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ void mywrite(uint32_t address, uint32_t value); void myread (uint32_t address, uint32_t *value); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* C_H */ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.