main.cpp
#include <stdio.h>
#include <stdlib.h>
#include "gh.h"
int main()
{
printf("%d \n",a);
return 0;
}
fun.cpp
#include <stdio.h>
#include "./gh.h"
void fun2()
{
printf("a2:%d \n",a);
}
gh.h
#ifndef GH_H_
#define GH_H_
int a=0;
int b=1;
#endif
(只编译)没错误,但这该死的水印.
链接阶段出现错误,重复定义.
使用objdump -t 查看 *.o文件内的符号如下:
main.o: 文件格式 elf64-x86-64
SYMBOL TABLE:
0000000000000000 l df *ABS* 0000000000000000 main.cpp
0000000000000000 l d .text 0000000000000000 .text
0000000000000000 l d .data 0000000000000000 .data
0000000000000000 l