开发者

Simple compiler question

开发者 https://www.devze.com 2023-02-28 12:43 出处:网络
I\'m having a problem compiling a multiple-part project. I thought I had included the开发者_Go百科 correct #ifndef/#define statements and included header files correctly, but apparently not. When atte

I'm having a problem compiling a multiple-part project. I thought I had included the开发者_Go百科 correct #ifndef/#define statements and included header files correctly, but apparently not. When attempting to compile this error came up:

[23:18]andrew final_project$:g++ driver2.cpp fish.cpp bay.cpp
ld: duplicate symbol Fish::Fish()  in /var/folders/cc/cc+as-5yHSqg0Jcr+X2+uk+++TI/-Tmp-//ccqNXrPE.o 
and /var/folders/cc/cc+as-5yHSqg0Jcr+X2+uk+++TI/-Tmp-//cc5dOIm5.o for
architecture x86_64
collect2: ld returned 1 exit status

I can include more information if necessary, but my two header files (fish.h and bay.h) are bookended with.

#ifndef FOO
#define FOO
...
#endif

my two implementation files are fish.cpp and bay.cpp.

fish.cpp: #include "fish.h"

bay.cpp: #include "bay.h" #include "fish.h"

My driver program driver2.cpp: #include "fish.cpp" #include "bay.cpp"

I assume the problem lies in the fact that bay.cpp includes both fish.h and bay.h, but when I don't include fish.h the "bay" (a grid of fish) is undefined. I would guess the problem isn't too hard, but I can't seem to find a solution.

--Thanks in advance, SegFaults McGee


Don't include the .cpp files in driver2.cpp. Include fish.h and bay.h instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消