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.

[参考译文] TMS320F28069M:通过链接器解析静态类变量

Guru**** 2535750 points


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

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/976271/tms320f28069m-resolving-static-class-variables-by-linker

器件型号:TMS320F28069M
当使用标准28069_RAM_lnk.cmd 时、为什么我无法在代码中使用静态类变量? 

给定的错误(在链接时):未定义符号 ADC:nAdcClassVariable。

我可以使用全局变量来实现相同的行为、但我想使用类变量。

///---------------------------------- // ADC 类 ////------------------------------------------------------- ADC 类 { 公共: 静态 int nAdcClassVariable; 静态空 InitModule( void ); };}-->----------------- // ADC 模块的初始化------------------------------------------------------- void adc::InitModule() { nAdcClassVariable = 4;//尝试使用/分配类变量时出现链接错误 返回; }

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

    在上面的代码中、链接器为什么使用静态类变量对未解析的符号抛出错误?

    如果我修改代码、将 nAdcClassVariable 从 ADC 类中删除、作为全局变量、代码编译和链接正常。

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

    请参阅常见问题条目: 为什么具有静态数据成员的类会遇到链接器错误? (不是来自 TI)。

    谢谢、此致、

    乔治

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

    谢谢 George!

    在.cpp 中添加声明、例如以下 orked:

    int ADC::nAdcClassVariable;
    
    <rest of .cpp file with function implementations.