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.

CCS/CCSTUDIO: Errors when adding first C++ file to existing CCS Project ('C')

Part Number: CCSTUDIO
Other Parts Discussed in Thread: CC1352P

Tool/software: Code Composer Studio

Hello -

I inherited an existing CCS Project which had source code in 'C' that was based on the CC13532P "Sensor" application.  I wrote a single C++ class (within a interface file and implementation file pair) and added this to the project.  A number of errors appeared which were unrelated to the syntax in the new source code, but rather appear to be related to the project not being configured properly for C++.  I could use some help reconfiguring the project, hopefully not re-creating).

Errors that have appeared include:

1. The new source code includes <cstdint>.   The preprocessor cannot find a symbol used in <cstdint>:     #20 identifier _LIBCPP_BEGIN_NAMESPACE_STD is undefined.

2. None of the definitions which are listed in the "sensors.opts" file are provided to the compiler when processing the new C++ files.  For example, "sensors.opts" includes this definition: "-DOSAL_PORT2TIRTOS".  This macro is not defined when compiling the C++ file, but is defined when compiling the 'C' files.

The project build configuration is using TI compiler v20.2.3 LTS, which uses the "armcl" compiler capable of both C and C++.

Other posts on the E2E forum suggest Enabling the "Treat C files as C++ files" option under the project properties [ARM Compiler->Advanced Options->Language Options].  I tried this, but this caused a large number of compile errors in the existing 'C' code which have up until now compiled cleanly.

Lastly, in order to resolve as many of the compile errors as possible, I had to explicitly add the 2 new C++ files to the "File is a C++ file (default for .C .cpp .cc) (--cpp_file, -fp)" section of the project properties [ARM Compiler->Advanced Options->File Type Specifier].  Given that the armcl compiler is used for 'C' and C++, I would not think explicitly identification of the files would be necessary because the suffix on the file name would be a hint to the compiler as to the content within.

I am using CCS v10.1.1.00004.  Project details include:

  • Project is based on the CC1352P "Sensor" application.
  • Build configurations are using the TI compiler v20.2.3 LTS 
  • Including XDCTools 3_61_02_27_core
  • Including SimpleLink CC13x2/26x2 SDK 3_40_00_02

Thanks in advance for your thoughtful replies.

Jason

  • More project settings:

    • C Dailect: C11
    • C++ Dailect: C++14

  • Make sure the C++ source files use the extension .cpp.  Otherwise, it is the same as adding any other source file to the project.  None of these other project changes such as ...

    JasonR said:
    Enabling the "Treat C files as C++ files" option under the project properties [ARM Compiler->Advanced Options->Language Options]

    ... or ...

    JasonR said:
    explicitly add the 2 new C++ files to the "File is a C++ file (default for .C .cpp .cc) (--cpp_file, -fp)" section of the project properties [ARM Compiler->Advanced Options->File Type Specifier]

    ... are needed.  

    If that does not resolve the problem, then I need to see the build log.  Please rebuild all the files.  Right click on the name of the project and select Rebuild Project.  In the Console view, save everything to a text file with the icon Copy Build Log.  Be sure the log file uses the file extension .txt.  Attach it to your next project.

    Thanks and regards,

    -George

  • Thank you George.

    I've done as you've said above.

    • Made sure the C++ files have the .cpp suffix
    • Disabled the "Treat C files as C++ files"
    • Removed C++ file names from the list.
    • Cleaned and then rebuilt the project.

    I've attached the log file after rebuilding.

    Thank you,

    Jason

    3632.Build Log.txt

  • All of the errors occur for one file named BoardLevelTest.c.

    This file must #include <cstdint> either directly, or through another include file.  Normally, this would result in an error similar to ...

    "file.c", line 1: fatal error: cannot open source file "cstdint"

    That doesn't happen in this case, because of this compiler option ...

    --include_path="/Applications/ti/ccs1011/ccs/tools/compiler/ti-cgt-arm_20.2.3.LTS/include/libcxx"

    Please do not specify this include directory.  If, as is typical, this include directory is specified ...

    --include_path="/Applications/ti/ccs1011/ccs/tools/compiler/ti-cgt-arm_20.2.3.LTS/include"

    ... the compiler automatically searches the libcxx subdirectory as needed.  Because libcxx is explicitly specified, it is incorrectly searched.  This causes the C++ header file cstdint to be included in a C source file.

    This explains many of the errors, but not all of them.

    Consider this error diagnostic ...

    "../application/RadioManager.hpp", line 16: error #66: expected a ";"

    The file extension of any include file does not affect how it is compiled.  This header file is compiled as if it is C, and not C++, because it is included in a C file.  

    Consider this error diagnostic ...

    "../application/BoardLevelTest.c", line 116: error #760: variable "RadioManager" is not a type name

    That is probably a case of C++ syntax being used in a C file.

    The solution is to arrange for BoardLevelTest.c to be compiled as a C++ file.  One method is to change the file extension to .cpp.  For more details, please search the TI ARM compiler manual for the sub-chapter titled Specifying Filenames.

    Thanks and regards,

    -George

  • I removed the explicit include path to include/libcxx, then renamed the suffix on a few files, and lastly to work through a few minor things related to the mix of C and C++ code (extern "C").   All compiles and links now.

    Thank you again.