作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想像这样在 API 中提供一个字符串常量:
extern const char* const SOME_CONSTANT;
但是如果我在我的静态库源文件中将它定义为
const char* const SOME_CONSTANT = "test";
当链接到该库并使用 SOME_CONSTANT 时,我遇到链接器错误:
Error 1 error LNK2001: unresolved external symbol "char const * const SOME_CONSTANT" (?SOME_CONSTANT@@3QBDB)
从 extern const char* const
声明和定义中删除指针常量(第二个 const 关键字)使其工作。如何使用指针常量导出它?
最佳答案
问题可能是 extern
声明在定义常量的源文件中不可见。尝试在定义之上重复声明,如下所示:
extern const char* const SOME_CONSTANT; //make sure name has external linkage
const char* const SOME_CONSTANT = "test"; //define the constant
关于c++ - extern const char* const SOME_CONSTANT 给我链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14977058/
我想像这样在 API 中提供一个字符串常量: extern const char* const SOME_CONSTANT; 但是如果我在我的静态库源文件中将它定义为 const char* cons
我是一名优秀的程序员,十分优秀!