[英]Behaviour of extern const char* in C++
在以下示例中:
file1.c中:
#include <stdlib.h>
#include <stdio.h>
extern const char* szVers;
extern const int iTest;
extern const char cText[];
int main( int argc, char** argv )
{
printf( "Result = %s - %d - %c\n", szVers, iTest, cText[0] );
return ( 0 );
}
file2.c中
const char* szVers = "Version 1.0";
const int iTest = 6;
const char cText[] = "ABCD";
当我编译源代码时,我得到以下错误:
$ g++ -o test file1.c file2.c
/tmp/cctVd57Y.o: In function `main':
file1.c:(.text+0x12): undefined reference to `cText'
file1.c:(.text+0x1b): undefined reference to `iTest'
collect2: ld returned 1 exit status
我知道在C ++中const表示内部链接,但为什么szVers没有未定义的引用错误?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.