This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] 编译器:clpru 'ti-CGT-PRU_Quot.4'报告'错误:应为标识符'对于extern " 2.1 "

Guru**** 2526700 points
Other Parts Discussed in Thread: AM3359

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/568096/compiler-clpru-ti-cgt-pru_2-1-4-reports-error-expected-an-identifier-for-extern-c

主题中讨论的其他部件:AM3359

工具/软件:TI C/C++编译器

编译以下代码时,clpru返回以下错误:

"/home/brendan/ti-CGT-PRU_PRU.4/example/test_xeno_pruss.c" 2.1 ,第2行:错误:需要一个标识符
"/home/brendan/ti-CGT-PRU_PRU.4/example/test_xeno_pruss.c" 2.1 ,第2行:错误:预期为";"
"/home/brendan/ti-CGT-PRU_PRU.4/example/test_xeno_pruss.c" 2.1 ,第12行:警告:解析在上一个语法错误后在此处重新启动
"/home/brendan/ti-CGT-PRU_PRU.4/example/test_xeno_pruss.c" 2.1 ,第18行:警告:隐式声明函数"AM335x_pru1_init"
编译"/home/brendan/ti-CGT-PRU_PRU.4/example/test_xeno_pruss.c"时检测到2个错误2.1。

//这是test_xeno_pruss.c的第一行

外部"C"{
   void AM335x_pru1_init(int a);
}

volatile char shared_buf[100]__attribute_((cregister("PRUIMEM")));
int local_data;
易失性寄存器无符号int __R31;

INT MAIN ()

   AM335x_pru1_init(0);

  (;;)
  {        
     //while ((__R31 & 0x1)==0);
     //shared_buf[++local_data]= 1;
  }
}

下面是命令行:

./bin/clpru \

$build_root/ti-CGT-PRU_PRU.4/example/test_xeno_pruss.c 2.1 \

--run_linker --ram_model --verbose_diagnostics \

-i $build_root/ti-CGT-PRU_PRU.4/lib 2.1 \

2.1 .4/example/test_xeno_pruss.bin \

--library=AM3359_PRU.cmd

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    问题是编译器需要C代码,但您提供了C++代码。

    编译器可以编译C或C++代码。  它使用文件扩展名来了解文件包含的内容。  扩展名为".c"的文件包含C代码。  扩展名为".cpp",".cxx"或".cc"的文件包含C++代码。

    因此,一个可能的解决方案是将test_xeno_pruss.c重命名为test_xeno_pruss.cpp。  另一个解决方案是使用生成选项--cppp_default。  此选项告诉编译器扩展名为".c"的文件包含C++代码。  PRU编译器手册中还详细介绍了其他解决方案。  从标题为指定文件名的部分开始阅读

    谢谢,此致,

    -George

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    George,
    这才是诀窍。 谢谢。