gcc使用问题及解决方法

2021-01-23, updated 2021-09-20

C++11 error: unable to find string literal operator ‘operator"

一个简单的宏

1
#define LOG_INFORMATION(x, ...) LOG_ME("%s:%d, "x, __FUNCTION__,__LINE__, ##__VA_ARGS__)

一直都可以正常编译,但是当启用C++11的时候,报告编译错误

C++ 11 Complier ErrorShell

1
error: unable to find string literal operator 'operator""x'

网上搜了一下,说是C++11要求,当字符串跟变量连接的时候,必须增加一个空格才行。因此简单修改如下即可。

1
2
3
4
5
#if __cplusplus < 201103L
#define LOG_INFORMATION(x, ...) LOG_ME("%s:%d, "x, __FUNCTION__,__LINE__, ##__VA_ARGS__)
#else
#define LOG_INFORMATION(x, ...) LOG_ME("%s:%d, " x, __FUNCTION__,__LINE__, ##__VA_ARGS__)
#endif

注意:在“android-ndk-r10e”中使用的GCC版本,GCC-4.9之前的版本都存在"__cplusplus"宏定义错误的问题,需要参考“NDK下GCC定义__cplusplus不正确的问题”,把GCC升级到4.9

error: stray ‘\×××’ in program错误原因及解决方法

网上down了一个C++的程序,内容很简单,但g++编译时报错,报错内容如下

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 error: stray ‘\342’ in program
   VideoCapture cap(”nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, 
   ^
tx2opencv.cpp:9:3: error: stray ‘\200’ in program
tx2opencv.cpp:9:3: error: stray ‘\235’ in program
tx2opencv.cpp:9:3: error: stray ‘\342’ in program
tx2opencv.cpp:9:3: error: stray ‘\200’ in program
tx2opencv.cpp:9:3: error: stray ‘\235’ in program
tx2opencv.cpp:13:7: error: stray ‘\342’ in program
       cout << ”Failed to open camera.” << endl;  
       ^
tx2opencv.cpp:13:7: error: stray ‘\200’ in program
tx2opencv.cpp:13:7: error: stray ‘\235’ in program
tx2opencv.cpp:13:7: error: stray ‘\342’ in program
tx2opencv.cpp:13:7: error: stray ‘\200’ in program
tx2opencv.cpp:13:7: error: stray ‘\235’ in program
tx2opencv.cpp:21:7: error: stray ‘\342’ in program
       imshow(”original”, frame);  
       ^
tx2opencv.cpp:21:7: error: stray ‘\200’ in program
tx2opencv.cpp:21:7: error: stray ‘\235’ in program
tx2opencv.cpp:21:7: error: stray ‘\342’ in program
tx2opencv.cpp:21:7: error: stray ‘\200’ in program
tx2opencv.cpp:21:7: error: stray ‘\235’ in program

网上查了一下原因,是因为代码中有中文字符,比如双引号/分号等是中文格式的,因此将代码中的标点全部替换了一遍,确保为英文字符,然后重新编译,顺利通过!

编译错误error: invalid storage class

经过问题排查是少了"}",粗心导致,一定要匹配"{ }"。

words: 748 tags: gcc