0

When I tried to run unit test for a simple main program in C++:

#include <iostream>

int main()
{
  std::cout << "hello world" << std::endl;

  return 0;
}

it occurred the following problem:

C++test analysis errors in /Demo_aCpp
    1. Test execution: error preparing instrumentation / symbols data for file.
"/usr/include/sys/features.h", line 25: error: expected an identifier
  extern "C" {
         ^

"/usr/include/sys/features.h", line 25: error: expected a ";"
  extern "C" {
             ^

"/usr/include/sys/reent.h", line 9: error: expected an identifier
  extern "C" {
         ^

"/usr/include/sys/reent.h", line 9: error: expected a ";"
  extern "C" {
             ^
...
Error limit reached.
100 errors detected in the compilation of "C:\Users\username\AppData\Local\Temp\ParaSoft.1840.28297.c".
Compilation terminated.

I have no idea about this. Any hint on this? Thanks in advance

never_
  • 11
  • 3
  • We need to see your program code, not just the error messages. – jkb Aug 23 '22 at 03:28
  • The file name is ending in `.c`, so it is probably assuming that the code is supposed to be C, not C++. – user17732522 Aug 23 '22 at 03:30
  • The origin source file is ending in ```.cpp```, but the temp file that autogenerated by the Parasoft C/C++ Test is ending in ```.c```. So the actually compiled file was the temp file, and the compiler is C-compiler, C-compiler cannot understand extern "C", then the error occurred. Is this right? – never_ Aug 23 '22 at 03:51
  • @never_ Yes, if the compiler is told that the file is C code or determines it is C code from the file ending, then it will fail because `extern "C"` is not syntactically valid in C. In C there must always be an identifier or keyword following the `extern`, not a string literal. I don't know whether or not this is a matter of a wrong setting in Parasoft, but it seems like it to me. – user17732522 Aug 23 '22 at 04:00

0 Answers0