【发布时间】:2021-04-02 16:39:53
【问题描述】:
我在
a.h
#IFNDEF
#define A_H
struct a_struct
{
int val;
int val_b;
}a;
#endif
main.cpp 和 a.cpp 都包含标题
#include "a.h"
当我使用 makefile 时:
a.o: a.cpp a.h
g++ -std=c++11 -c $<
main.o: main.cpp a.h
g++ -std=c++11 -c $<
main: main.o a.o
g++ -std=c++ $^ -o $@
发生编译错误:
duplicate symbol '_a' in:
a.o
main.o
a 是否在 a.cpp 和 main.cpp 中重新定义?
有没有办法在不改变 a.h 的情况下解决这个问题?
如果不可能,我该如何更改代码?
提前谢谢你:)
【问题讨论】:
-
Is a being redefined in a.cpp and main.cpp?是的。Is there a way to resolve this issue without changing a.h?没有 -
你为什么不想改变
a.h?你能复制一份,叫它b.h,然后修复它吗? -
@Beta @tkausl 我想尽量减少对
a.h的更改,因为它不属于我。如果我能够获得a.h,我该如何解决这个问题?