为什么我的 .cpp 文件没有被处理?
我正在尝试编译(制作)游戏源,似乎我的 gRace.cpp 文件被排除在外,因为它不断为我的所有 gRace 类方法返回未定义的引用错误。
libtron.a(libtron_a-gGame.o): In function `gGame::StateUpdate()':
gGame.cpp:(.text+0x99e9): undefined reference to `gRace::Reset()'
libtron.a(libtron_a-gGame.o): In function `gGame::Analysis(float)':
gGame.cpp:(.text+0xad48): undefined reference to `gRace::Sync(int, int, int)'
gGame.cpp:(.text+0xad4d): undefined reference to `gRace::Done()'
gGame.cpp:(.text+0xad61): undefined reference to `gRace::Winner()'
gGame.cpp:(.text+0xb786): undefined reference to `gRace::End()'
libtron.a(libtron_a-gWinZone.o): In function `gWinZoneHack::OnEnter(gCycle*, float)':
gWinZone.cpp:(.text+0x9206): undefined reference to `gRace::ZoneHit(ePlayerNetID*)'
libtron.a(libtron_a-gWinZone.o): In function `gWinZoneHack::gWinZoneHack(eGrid*, eCoord const&, bool)':
gWinZone.cpp:(.text+0xda96): undefined reference to `gRace::NewZone(gWinZoneHack*)'
libtron.a(libtron_a-gWinZone.o): In function `gWinZoneHack::gWinZoneHack(eGrid*, eCoord const&, bool)':
gWinZone.cpp:(.text+0xdcc6): undefined reference to `gRace::NewZone(gWinZoneHack*)'
collect2: ld returned 1 exit status
我通过以下方式将 gRace.h 文件包含在两个文件中:
#include "gRace.h"
关于可能导致它无法处理的任何想法?
I'm trying to compile (make) a game source and it seems that my gRace.cpp file is being excluded or something because it keeps returning undefined reference errors for all my gRace class methods.
libtron.a(libtron_a-gGame.o): In function `gGame::StateUpdate()':
gGame.cpp:(.text+0x99e9): undefined reference to `gRace::Reset()'
libtron.a(libtron_a-gGame.o): In function `gGame::Analysis(float)':
gGame.cpp:(.text+0xad48): undefined reference to `gRace::Sync(int, int, int)'
gGame.cpp:(.text+0xad4d): undefined reference to `gRace::Done()'
gGame.cpp:(.text+0xad61): undefined reference to `gRace::Winner()'
gGame.cpp:(.text+0xb786): undefined reference to `gRace::End()'
libtron.a(libtron_a-gWinZone.o): In function `gWinZoneHack::OnEnter(gCycle*, float)':
gWinZone.cpp:(.text+0x9206): undefined reference to `gRace::ZoneHit(ePlayerNetID*)'
libtron.a(libtron_a-gWinZone.o): In function `gWinZoneHack::gWinZoneHack(eGrid*, eCoord const&, bool)':
gWinZone.cpp:(.text+0xda96): undefined reference to `gRace::NewZone(gWinZoneHack*)'
libtron.a(libtron_a-gWinZone.o): In function `gWinZoneHack::gWinZoneHack(eGrid*, eCoord const&, bool)':
gWinZone.cpp:(.text+0xdcc6): undefined reference to `gRace::NewZone(gWinZoneHack*)'
collect2: ld returned 1 exit status
I'm including the gRace.h file in both files via:
#include "gRace.h"
Any ideas on what might be causing it to not be processed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不包含头文件会导致未定义函数编译器错误。这些是链接器错误,这意味着实际的源文件未与其他文件链接(也就是说,它与您是否在正确的位置包含
gRace.h
无关) 。检查您的构建脚本以确保正确链接gRace.cpp
Not including the header file would cause undefined function compiler errors. These are linker errors, which means the actual source file isn't being linked with the other files (that is, it has nothing to do with whether or not you included
gRace.h
in the right places). Check your build script to ensuregRace.cpp
is being linked in properly如果它是一个 automake 项目,则您在 Makefile.am 的 _SOURCES 部分中缺少 gRace.cpp。
If it is an automake project you are missing gRace.cpp in your _SOURCES section in the Makefile.am.
这似乎是链接错误而不是编译错误。最有可能的是,您缺少一些应该链接的外部库。
This apprears to be a linking error and not a compilation error. Most likely, you are missing some external libraries that you should be linking against.