5

I am using Keil uVision and I keep getting this error:

C:\Keil_v5\ARM\ARMCC\bin\..\include\rw/_defs.h(781): error:  #20:
    identifier "namespace" is undefined

What could lead to this error? Isn´t namespace automatically defined?

Clifford
  • 88,407
  • 13
  • 85
  • 165
user3729617
  • 113
  • 1
  • 14
  • 5
    My hunch is that you use a C compiler for your C++ program. There are no namespaces in C. – Csq Jun 30 '14 at 10:56
  • What have you done to get that error? Some more detail would be awesome... What compiler? What System? etc... – Theolodis Jun 30 '14 at 10:57
  • I am seeing that answer in a lot of places, but my file is a .cpp file – user3729617 Jun 30 '14 at 10:58
  • Is keil not a c++ compiler? @Csq – user3729617 Jun 30 '14 at 11:03
  • @user3729617 It would help if you would show a minimal example program and the command line options you used to compile. – Csq Jun 30 '14 at 11:08
  • @Csq: The "issue" you linked to was merely to do with the fact that ARMCC is not C++11 compliant. The fact that it implements C++98 is clearly stated in the documentation as is required - that has nothing to do with the problem here - it is not a compiler problem. – Clifford Jun 30 '14 at 11:18
  • Also see [Namespaces in C](http://stackoverflow.com/questions/389827) and [Including C++ header file with namespace in C source file causes compilation error](http://stackoverflow.com/q/16058245). – jww Jun 15 '15 at 13:34
  • @Clifford - it almost sounds like you are saying C++98 did not have namespaces, and you need a C++11 compiler for them. Or do you mean [inline namespaces](http://stackoverflow.com/q/11016220)? – jww Jun 15 '15 at 13:38
  • @jww : The comment refers to a link posted in a comment now removed. I don't know that link was, but it was as stated unrelated to this question - probably why Csq deleted it. So I am saying nothing of the sort - the comment was not about this question, but the deleted link. – Clifford Feb 05 '22 at 07:17

2 Answers2

6

It looks like you are using C compilation for C++ code - check the compiler options.

In C++ namespace is a reserved word, but not in C, so the compiler will try to interpret it as an identifier rather than a keyword - which will then of course make no sense syntactically to a C compiler.

Clifford
  • 88,407
  • 13
  • 85
  • 165
3

You did not expose many details but my hunch is that you use a C compiler for your C++ program. There are no namespaces in C.

I could produce similar messages with this program:

namespace test {
}

Output:

$ gcc test.c
test.c:1:1: error: unknown type name 'namespace'
 namespace test {
 ^
test.c:1:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{
' token
namespace test {
            ^

Ideone link

Csq
  • 5,775
  • 6
  • 26
  • 39