. M file import C ++ header file error,. m Import
I have dug a lot of pitfalls in my work over the past few days and encountered various strange mistakes. Now let's make a summary.
Create a new project, and then create the HelloCPP. h, HelloCPP. cpp file. The content of HelloCPP. h is as follows:
#ifndef __CPPWrong__HelloCPP__#define __CPPWrong__HelloCPP__//#include <stdio.h>namespace hello{ };#endif /* defined(__CPPWrong__HelloCPP__)
Is an empty namespace.
Then Import HelloCPP. h In ViewController. m, as shown below:
# Import "ViewController. h "// import the C ++ header file # import" HelloCPP. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib .} -(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end
Run, and an error is reported. The prompt is as follows:
The imported C ++ header file cannot recognize its namespace.
Solution:
Generally, in the project, if the C ++ code running exception is encountered in the OC, it is because the C ++ header file is referenced by an OC. m file. To achieve mixed compilation of OC and C ++, you mustModify the suffix of the referenced. m file to. mm..
An error occurred while importing the C ++ header file.
Delete this sentence and rewrite it. Note that the input method is English. I don't know if it doesn't work.
Why does the header file not be found when the c and H files are imported by VC?