This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/MSP430F6748: CCS makefile vs support for c and c++

Part Number: MSP430F6748

Tool/software: TI C/C++ Compiler

Hi!

I'm using cl6x compiler and CCSv7

I have big project in C with many linked C libs, and i need include into the big one 1 smaller(still few thosands of code lines) project/lib that has been written in c++.

Both are made on makefiles

Converting the big one into c++ would be to much work, and when I try just link c++ as c I get errors like:

"C:/ti/ccsv6/tools/compiler/c6000_7.4.19/include/exception", line 10: error #20: 
identifier "class" is undefined
class exception;
^

"C:/ti/ccsv6/tools/compiler/c6000_7.4.19/include/iosfwd", line 532: error #41: 
expected an identifier
typedef basic_ostream<wchar_t, char_traits<wchar_t> > wostream;

all displayed errors(in .log file) ale from compiler, and none is from projects code.

Smaller project is properly building in c++, and it have "#ifdef __cplusplus..." there where it caused errors.(errors in building big one)

There comes my question: Is there a supported makefile command that allow me to properly link/include both projects? without need to make big changes?

  • The header files exception and iosfwd contain C++ code.  If you somehow #include them in source files that have the file extension .c, then you will see diagnostics like that.  When the compiler sees the file extension .c, it presumes all the source seen, whether from #include files or not, is only C code, and not C++ code.  For further detail, please see the section titled Specifying Filenames in the C6000 compiler manual.

    If this does not explain your problem, then please show, for the build command that leads to the errors above, the entire command invocation, along with all the diagnostics for it.

    Thanks and regards,

    -George

  • C++ is designed to allow you to mix C and C++ files in one project. One requirement is that function "main" must be in a C++ file. You should think of mixing C++ and C code as writing a C++ program, and mixing in some C code that you don't want to change. You should not need to make any changes to the C part of the project; in particular, you don't need to change it to be valid C++ code. Instead, in C++ code, declare C functions you wish to call as extern "C". There are lots of web pages that clearly discuss the details of how to mix C and C++ code; here's one: isocpp.org/.../mixing-c-and-cpp
  • main must not be in c++ ;)
    just like: e2e.ti.com/.../531064
    AartiG uploaded .zip with main.c which used c++ files

  • While it's true many C++ programs can get away with defining main as a C function, in practice doing so can lead to hard-to-explain bugs when you have global objects that require construction. Thus, it is best practice to make main a C++ function.