【发布时间】:2011-07-23 23:23:04
【问题描述】:
获取这些文件:
啊。
#ifndef A_H
#define A_H
char EL[] = "el";
#endif
a.cpp
#include "a.h"
b.h
#ifndef B_H
#define B_H
#include "a.h"
#endif
b.cpp
#include "b.h"
main.cpp
#include "b.h"
#include "a.h"
int main() { }
这只是一个例子,但我确实有这个问题:
g++ -c a.cpp
g++ -c b.cpp
g++ -c main.cpp
g++ -o main main.o a.o b.o
a.o:(.data+0x0): multiple definition of `EL'
main.o:(.data+0x0): first defined here
b.o:(.data+0x0): multiple definition of `EL'
main.o:(.data+0x0): first defined here
collect2: ld returned 1 exit status
为什么以及如何解决?
【问题讨论】:
标签: c++ c linker-errors include-guards multiple-definition-error