构建过程中的 Clion 编译器错误
Clion compiler error during the builduing process
我试图做一个简单的 类 program,但我收到一个奇怪的错误,据我所知,这不是代码的问题,而是 Clion 的问题。
CMakeFiles\Assignment_4.dir/objects.a(Box.cpp.obj):Box.cpp:(.bss+0x0): multiple definition of `Box::objectCount'
CMakeFiles\Assignment_4.dir/objects.a(Q_1.cpp.obj):Q_1.cpp:(.bss+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Assignment_4.exe] Error 1
CMakeFiles\Assignment_4.dir\build.make:147: recipe for target 'Assignment_4.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Assignment_4.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/Assignment_4.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Assignment_4.dir/rule] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Assignment_4.dir/rule' failed
mingw32-make.exe: *** [Assignment_4] Error 2
Makefile:117: recipe for target 'Assignment_4' failed
即使直接用 g++ 编译我也出现多重对象定义错误。它在 visual studio.
之前有效
C:\Users\fsa\CLionProjects\McMaster\Assignment_4>g++ Q_1.cpp clock.cpp box.cpp -o Q1.exe
C:\Users\fsa\AppData\Local\Temp\ccmD1R6t.o:box.cpp:(.bss+0x0): multiple definition of `Box::objectCount'
C:\Users\fsa\AppData\Local\Temp\cc0nh7LU.o:Q_1.cpp:(.bss+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
问题是 int Box::objectCount = 0;
在 header 中。所以它出现在多个编译单元中(Q1.o和Box.o)。它应该移动到 Box.cpp.
我试图做一个简单的 类 program,但我收到一个奇怪的错误,据我所知,这不是代码的问题,而是 Clion 的问题。
CMakeFiles\Assignment_4.dir/objects.a(Box.cpp.obj):Box.cpp:(.bss+0x0): multiple definition of `Box::objectCount'
CMakeFiles\Assignment_4.dir/objects.a(Q_1.cpp.obj):Q_1.cpp:(.bss+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Assignment_4.exe] Error 1
CMakeFiles\Assignment_4.dir\build.make:147: recipe for target 'Assignment_4.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Assignment_4.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/Assignment_4.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Assignment_4.dir/rule] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Assignment_4.dir/rule' failed
mingw32-make.exe: *** [Assignment_4] Error 2
Makefile:117: recipe for target 'Assignment_4' failed
即使直接用 g++ 编译我也出现多重对象定义错误。它在 visual studio.
之前有效C:\Users\fsa\CLionProjects\McMaster\Assignment_4>g++ Q_1.cpp clock.cpp box.cpp -o Q1.exe
C:\Users\fsa\AppData\Local\Temp\ccmD1R6t.o:box.cpp:(.bss+0x0): multiple definition of `Box::objectCount'
C:\Users\fsa\AppData\Local\Temp\cc0nh7LU.o:Q_1.cpp:(.bss+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
问题是 int Box::objectCount = 0;
在 header 中。所以它出现在多个编译单元中(Q1.o和Box.o)。它应该移动到 Box.cpp.