小编raj*_*shk的帖子

在C源文件中包含带有命名空间的C++头文件会导致编译错误

我不是一个专业的C++程序员,我最近在C++中做了一个技巧,这引起了我的下面的问题.

我的任务目标:复制特定的非系统线程(实际上是协作线程)安全模块,以创建系统线程安全版本,以支持系统中的不同需求.但是,我们决定创建一个命名空间来保护C++头文件中的系统线程版本,而不是创建sys_XXX函数以保持兼容性.我实际上可以将它包含在CPP文件中并愉快地工作但我刚刚意识到我的funcInit调用在它到达CPP文件控件之前没有被调用.不幸的是,协作线程版本的这个init在C文件中.现在我需要从同一个地方初始化我的系统线程安全版本,但我已被编译错误阻止,这是我知道很难解决的.

编译错误日志: -

In file included from sysinit.c:87:
sys_unicode.h:39: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'SystemThreadUtils' <== corresponds to line [namespace SystemThreadUtils {]
sysinit.c:88:
sysinit.c:512: error: expected identifier or '(' before string constant <== corresponds to line [extern "C" bool SystemThreadUtils::funcInit(void);]
sysinit.c:513: error: expected identifier or '(' before string constant <== corresponds to line [extern "C" bool SystemThreadUtils::funcTerm(void);]
sysinit.c: In function 'SysInit':
sysinit.c:817: error: 'SystemThreadUtils' undeclared (first use in this function) <= corresponds to line [SystemThreadUtils::funcInit();] …
Run Code Online (Sandbox Code Playgroud)

c c++ namespaces compilation header

7
推荐指数
1
解决办法
2万
查看次数

grep精确单词匹配(-w)不适用于文本文件中的文件路径

我试图在文件中grep一个带有完整路径的文件名,其中包含'ls -l'输出,但它无法正确匹配.

执行字符串搜索的shell脚本中的行

pcline=`grep -w "$file1" $file2` # grep for file1 in file2 contents
Run Code Online (Sandbox Code Playgroud)

如果我回显命令,命令的输出如下所示

grep -w run /home/rajesh/rootfs.layout

Expected
lrwxrwxrwx 1 root root 3 Aug 28 run

Actual
lrwxrwxrwx 1 root root 7 Aug 28 bin/run-parts
lrwxrwxrwx 1 root root 3 Aug 28 run
-rwxr-xr-x 1 root root 303 Aug 28 tests/aes/run.sh
-rwxr-xr-x 1 root root 445 Aug 28 tests/auto_ui/run.sh
-rwxr-xr-x 1 root root 320 Aug 28 tests/available_memory/run.sh
-rwxr-xr-x 1 root root 308 Aug 28 tests/fonts/run.sh
-rwxr-xr-x 1 root …
Run Code Online (Sandbox Code Playgroud)

linux shell grep

5
推荐指数
1
解决办法
3822
查看次数

一次读取一行输入文件作为输入传递给grep

我的要求是读取一个文件,然后在读取行上一次运行一个grep命令,用于文件中的所有行.

过滤与模式匹配的所需文件

find . -name *.ini -exec grep -w HTC {} \; -print | grep ini > input.files
Run Code Online (Sandbox Code Playgroud)

cat input.files

./PLATFORM/android/build/integration/android/suites/android_Prefs_Devices_Comms_Suite/ini/android_0019.ini
./PLATFORM/android/build/integration/android/suites/android_Prefs_Devices_Comms_Suite/ini/android_0150.ini
./PLATFORM/android/build/integration/android/suites/android_Prefs_Devices_Comms_Suite/ini/android_0616_1.ini
./PLATFORM/android/build/integration/android/suites/android_SI_Query_Suite/ini/android_0547_4.ini
./PLATFORM/android/build/integration/android/suites/android_SI_Query_Suite/ini/android_0578.ini
./PLATFORM/android/build/integration/android/suites/android_PDL_Suite/ini/android_5203_1.ini
./PLATFORM/android/build/integration/android/suites/android_System_Maintenance_Suite/ini/android_0579_2.ini
Run Code Online (Sandbox Code Playgroud)

知道如何从input.files一次读取一行并执行grep命令吗?

cat input.files -exec grep -w HTC_One {} \;
Run Code Online (Sandbox Code Playgroud)

linux command-line command-line-arguments

3
推荐指数
1
解决办法
6383
查看次数

Makefile Awk 使用 $ 表示列出现语法错误,但在控制台上运行良好

我在控制台上使用下面的行非常好,但是当我在 makefile 中使用它时,我收到以下错误。过去一小时我尝试了不同的事情,但没有任何帮助。另外我必须在 makefile 中的命令之前使用“@”,这只是正常的。非常欢迎任何帮助。

控制台上的命令

cpio -itv < rootfs.cpio | awk '!/^d/{$8="";print}' | sort -k8 > rootfs.layout.trim
Run Code Online (Sandbox Code Playgroud)

错误

awk: !/^d/{="";print}
awk:       ^ syntax error
Run Code Online (Sandbox Code Playgroud)

在生成文件中

log-rootfs:
# copy the layout dump with all the modification needed to sync with stb output
# get the file list from cpio file => remove the lines with directory name => sort the output and store the same in layout file
cpio -itv < $(ROOTFS_CPIO_FILE) | awk '!/^d/{$8="";print}' | sort -k8 > $(ROOTFS_LAYOUT) …
Run Code Online (Sandbox Code Playgroud)

awk makefile syntax-error

2
推荐指数
1
解决办法
854
查看次数