Unknown type name 'namespace' in Xcode 4.2
Asked Answered
H

2

12

I am compiling QCAR SDK, but it prompts an error after I added more frameworks to the project.

// Matrices.h
//
#ifndef _QCAR_MATRIX_H_
#define _QCAR_MATRIX_H_

namespace QCAR
{

/// Matrix with 3 rows and 4 columns of float items
struct Matrix34F {
    float data[3*4];   ///< Array of matrix items
};


/// Matrix with 4 rows and 4 columns of float items
struct Matrix44F {
    float data[4*4];   ///< Array of matrix items
};

} // namespace QCAR

#endif //_QCAR_MATRIX_H_

In the line namespace QCAR, it said Unknown type name 'namespace'.

What should I do?

UPDATE: Here is the build transcript

In file included from ../../build/include/QCAR/Tool.h:18:
In file included from /Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/ImageTargets/EAGLView.h:14:
In file included from /Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/ImageTargets/ImageTargetsAppDelegate.h:9:
In file included from /Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/CouponBook.m:12:
../../build/include/QCAR/Matrices.h:16:1: error: unknown type name 'namespace' [1]
 namespace QCAR
 ^
../../build/include/QCAR/Matrices.h:16:15: error: expected ';' after top level declarator [1]
 namespace QCAR
               ^
               ;
fix-it:"../../build/include/QCAR/Matrices.h":{16:15-16:15}:";"
In file included from /Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/ImageTargets/ImageTargetsAppDelegate.h:9:
In file included from /Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/CouponBook.m:12:
/Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/ImageTargets/EAGLView.h:52:5: error: type name requires a specifier or qualifier [1]
     QCAR::Matrix44F projectionMatrix;
     ^
/Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/ImageTargets/EAGLView.h:52:10: error: expected expression [1]
     QCAR::Matrix44F projectionMatrix;
          ^
/Users/Raptor.Kwok/Documents/xCodeProjects/qcar-ios-1-0-0/samples/ImageTargets/ImageTargets/EAGLView.h:52:5:{52:5-52:9}: warning: type specifier missing, defaults to 'int' [-Wimplicit-int,3]
     QCAR::Matrix44F projectionMatrix;
     ^~~~
1 warning and 4 errors generated.
Hypochondrium answered 2/11, 2011 at 2:40 Comment(1)
Note for future readers: QCAR is now renamed to Vulforia, where the above errors won't appear again in any of the sample projects.Hypochondrium
C
18

I suspect the translation is C or Objective-C, where namespace is not a keyword as it is in C++ and Objective-C++.

Another possibility is that a previous header did not close a body (e.g. forgotten }; at end of class declaration of forgotten } at end of function definition).

Cattycornered answered 2/11, 2011 at 2:55 Comment(4)
It probably is the compatibility problem between xCode 4.2 & QCAR SDK 1.0. See: ar.qualcomm.com:443/arforums/showthread.php?t=1079 ( require QCAR SDK Login )Hypochondrium
@Shivan MoSR had the same suggestion I made. If you edit your post and add the build transcript for the file which produces the error(s), then I can verify that this is or is not the case.Cattycornered
@Shivan the file you are compiling is an .m file, for objc. the command invocation is missing from the beginning of the transcript, so I can't say for sure that the compiler has been told to compile the file as objc++. so, try this: change the extension, from CouponBook.m to CouponBook.mm. with .mm, the file will be compiled as objc++ unless you have explicitly disabled that behavior someplace else. for the compiler to recognize c++ and objc programs in the same translation, you will need to compile as objc++.Cattycornered
Correct. After I renamed to .mm, the problem vanished. Thanks for your help!Hypochondrium
T
20

You can rename your file with .mm or you can select your .m file and change the "File Type" to "Objective-C++ Source".

filetype

Theine answered 17/5, 2013 at 9:11 Comment(0)
C
18

I suspect the translation is C or Objective-C, where namespace is not a keyword as it is in C++ and Objective-C++.

Another possibility is that a previous header did not close a body (e.g. forgotten }; at end of class declaration of forgotten } at end of function definition).

Cattycornered answered 2/11, 2011 at 2:55 Comment(4)
It probably is the compatibility problem between xCode 4.2 & QCAR SDK 1.0. See: ar.qualcomm.com:443/arforums/showthread.php?t=1079 ( require QCAR SDK Login )Hypochondrium
@Shivan MoSR had the same suggestion I made. If you edit your post and add the build transcript for the file which produces the error(s), then I can verify that this is or is not the case.Cattycornered
@Shivan the file you are compiling is an .m file, for objc. the command invocation is missing from the beginning of the transcript, so I can't say for sure that the compiler has been told to compile the file as objc++. so, try this: change the extension, from CouponBook.m to CouponBook.mm. with .mm, the file will be compiled as objc++ unless you have explicitly disabled that behavior someplace else. for the compiler to recognize c++ and objc programs in the same translation, you will need to compile as objc++.Cattycornered
Correct. After I renamed to .mm, the problem vanished. Thanks for your help!Hypochondrium

© 2022 - 2024 — McMap. All rights reserved.