编译c++源码问题

Issue compiling c++ source

本文关键字:问题 源码 c++ 编译      更新时间:2023-10-16

我在编译c++程序时遇到了问题,我试图找到问题并解决它,但目前我无法找到问题的根源。如果有人能帮我一把,我会很感激的。

给出的错误是:(在Centos 6.3与gcc 4.4.7下编译)

In file included from /home/server/Sources/MOP/MistCore/src/server/scripts/PrecompiledHeaders/ScriptPCH.h:25,
                 from /home/server/Sources/MOP/MistCore/src/server/game/Anticheat/AnticheatMgr.h:7,
                 from /home/server/Sources/MOP/MistCore/src/server/game/Anticheat/AnticheatData.h:4,
                 from /home/server/Sources/MOP/MistCore/src/server/game/Anticheat/AnticheatData.cpp:1:
/home/server/Sources/MOP/MistCore/src/server/game/Spells/SpellScript.h: In constructor ‘AuraScript::AuraScript()’:
/home/server/Sources/MOP/MistCore/src/server/game/Spells/SpellScript.h:619: error: no matching function for call to ‘std::shared_ptr<Aura>::shared_ptr(NULL)’
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/shared_ptr.h:1263: note: candidates are: std::shared_ptr<_Tp>::shared_ptr(std::shared_ptr<_Tp>&&) [with _Tp = Aura]
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/shared_ptr.h:1238: note:                 std::shared_ptr<_Tp>::shared_ptr() [with _Tp = Aura]
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/shared_ptr.h:1236: note:                 std::shared_ptr<Aura>::shared_ptr(const std::shared_ptr<Aura>&)
make[2]: *** [src/server/game/CMakeFiles/game.dir/Anticheat/AnticheatData.cpp.o] Error 1
make[1]: *** [src/server/game/CMakeFiles/game.dir/all] Error 2
make: *** [all] Error 2

文件:

  • SpellScript.cpp: http://pastebin.com/Cam59CWt
  • SpellScript.h: http://pastebin.com/XYp6pSf9

是的,这是一段很长的代码。

根据这个站点,std::shared_ptr是在c++ 11中引入的。

使用GCC编译c++ 11需要4.7或更高版本。

注意,MistCore是基于TrinityCore,而不是使用c++ 11特定的定义命名为AuraPtr使用一个简单的Aura*指针。将其恢复到原始状态应该就像在原始项目中使用一样。

您可以简单地编辑/src/server/game/SharedPtrs/SharedPtrs.h,并通过用简单的指针替换定义来取消std::shared_ptr的需要。但不能保证它能解决所有问题。为例。

您可以使用-std=c++11

指定标志。