SWIG 为 BWAPI 库 (C++) 制作 CFFI 包装器时出错

发布于 2024-11-03 05:51:24 字数 6284 浏览 4 评论 0原文

我正在尝试从 http:// 为 BWAPI (用 C++ 编写)制作 CFFI 包装器code.google.com/p/bwapi/ ,通过修改另一个 BWAPI-bridge(用 C# 编写)http://code.google.com/p/bwapi-mono-bridge/

我的操作系统:Window 7 Professional

SWIG 版本:2.0.3

UAC : off

(*如果我没有在 %include 部分指定 /std 文件夹,则会出现错误代码: http://pastebin.com/XkePbKjG )

  • 更新:Linux 上出现同样的错误: 在此处输入图像描述

  • 在带有 SWIG 2.0.3 的窗口上 这是我在窗口上包装过程时出现的错误:

这是我的 BuildInterface.bat 的内容修改后的

:start 

erase /s /q Classes\*.*
erase /s /q Wrapper\*.*

swig.exe -cffi  -c++ -I..\BWAPI\Include  -outdir Classes\BWAPI  -o Wrapper\bwapi-bridge.cxx Interfaces\bwapi-bridge.i

swig.exe -cffi -c++ -I..\BWAPI\Include -outdir Classes\BWTA  -o Wrapper\bwta-bridge.cxx Interfaces\bwta-bridge.i

swig.exe -cffi -c++ -I..\BWAPI\Include  -outdir Classes\BWAPIC   -o Wrapper\bwapiclient-bridge.cxx Interfaces\bwapiclient-bridge.i

pause
goto start

bwapi-bridge.i :以及修改后的

%include "cpointer.i"
%include "carrays.i"
//include headers in our generated code.
%module bwapi
%{
#include "BWAPI.h"

using namespace BWAPI;
%}                    

//special include for our dllimport attribute
%include "dllimport.i"


//resolve ambiguities
%include "ambiguities.i"

//unimplemented functions in headers (or ones that should not be called)
//uncomment these each new version of BWAPI to ensure they are not later implemented.
#%ignore getPlayerUnits;
#%ignore BWAPI::GameData::GameData;

//fix up operator overrides.
%rename (opAssign) *::operator =;
%rename (opEquals) *::operator ==;
%rename (opLessThan) *::operator <;
%rename (opGreaterThan) *::operator >;
%rename (opMinus) *::operator -;
%rename (opNotEquals) *::operator !=;                         
%rename (opPlus) *::operator +;
%rename (opAdd) *::operator +=;
%rename (opSubtract) *::operator -=;

//fix up const strings.
%apply const  string & { string &};


%include "BWAPI.h"
%include "BWAPI/EventType.h"
%include "BWAPI/GameType.h"
%include "BWAPI/Race.h"
%include "BWAPI/TechType.h"
%include "BWAPI/UpgradeType.h"
%include "BWAPI/Position.h"
%include "BWAPI/AIModule.h"
%include "BWAPI/Color.h"
%include "BWAPI/Constants.h"
%include "BWAPI/CoordinateType.h"
%include "BWAPI/DamageType.h"
%include "BWAPI/Error.h"
%include "BWAPI/ExplosionType.h"
%include "BWAPI/Flag.h"
%include "BWAPI/Force.h"
%include "BWAPI/Input.h"
%include "BWAPI/Event.h"
%include "BWAPI/Latency.h"
%include "BWAPI/Order.h"
%include "BWAPI/PlayerType.h"
%include "BWAPI/Player.h"
%include "BWAPI/BulletType.h"
%include "BWAPI/Bullet.h"
%include "BWAPI/TilePosition.h"
%include "BWAPI/UnitCommandType.h"
%include "BWAPI/UnitCommand.h"
%include "BWAPI/Game.h"
%include "BWAPI/Unit.h"
%include "BWAPI/UnitSizeType.h"
%include "BWAPI/UnitType.h"
%include "BWAPI/WeaponType.h"

%include "std/std_vector.i"
%include "std/std_set.i"
%include "std/std_pair.i"
%include "std/std_list.i"
%include "std/std_map.i"

//Instantiate our templates
namespace std {
%template (PositionVector)vector<BWAPI::Position>;
%template (BulletPtrSet)  set<BWAPI::Bullet *>;
%template (BulletTypeSet) set<BWAPI::BulletType>;
%template (DamageTypeSet) set<BWAPI::DamageType>;
%template (ErrorSet)  set<BWAPI::Error>;
%template (ExplosionTypeSet) set<BWAPI::ExplosionType>;
%template (ForcePtrSet)  set<BWAPI::Force *>;
%template (GameTypeSet)  set<BWAPI::GameType>;
%template (OrderSet)  set<BWAPI::Order>;
%template (PlayerPtrSet)  set<BWAPI::Player *>;
%template (PlayerTypeSet)  set<BWAPI::PlayerType>;
%template (RaceSet)  set<BWAPI::Race>;
%template (TechTypeSet)  set<BWAPI::TechType>;
%template (TilePositionSet)  set<BWAPI::TilePosition>;
%template (UnitPtrSet)  set<BWAPI::Unit*>;
%template (UnitCommandTypeSet)  set<BWAPI::UnitCommandType>;
%template (UnitSizeTypeSet)  set<BWAPI::UnitSizeType>;
%template (UnitTypeSet)  set<BWAPI::UnitType>;
%template (UpgradeTypeSet)  set<BWAPI::UpgradeType>;
%template (WeaponTypeSet)  set<BWAPI::WeaponType>;
%template (EventList)  list<BWAPI::Event>;
%template (UnitTypeList)  list<BWAPI::UnitType>;
%template (TilePositionDoubleMap)  map<BWAPI::TilePosition, double>;
%template (UnitTypeIntMap)  map<BWAPI::UnitType, int>;
%template (PositionPair)  pair<BWAPI::Position,BWAPI::Position>;
%template (TilePositionDoublePair)  pair<BWAPI::TilePosition, double>;
%template (UnitTypeIntPair)  pair<BWAPI::UnitType,int>;
%template (TilePositionVector)  vector<BWAPI::TilePosition>;
%template (PositionSet)  set<BWAPI::Position>;
};

bwta-bridge.i

%include "cpointer.i"
%module bwta
%{
#include "BWAPI.h"
#include "BWTA.h"

using namespace BWTA;
%}                  
//use getcolumn instead
%ignore operator[];

//import BWAPI
%import "bwapi-bridge.i"


//BWTA order of includes is important to stop SWIGTYPE_p etc class generation with and without namespace
%include "BWTA/RectangleArray.h"
%include "BWTA/BaseLocation.h"
%include "BWTA/Chokepoint.h"
%include "BWTA/Polygon.h"
%include "BWTA/Region.h"
%include "BWTA.h"


%module bwta-bridge
%include "std/std_vector.i"

%include "std/std_set.i"

%include "std/std_pair.i"




//Instantiate our templates

%template (RectangleArrayDouble) BWTA::RectangleArray<double>; 


namespace std {

    %template (BaseLocationPtrSet) set<BWTA::BaseLocation *>;
        %template (RegionPtrSet)       set<BWTA::Region *>;
        %template (ChokepointPtrSet)   set<BWTA::Chokepoint *>;
        %template (PolygonPtrSet)      set<BWTA::Polygon *>;
        %template (PolygonVector)      vector<BWTA::Polygon>;
        %template (RegionPtrRegionPtrPair) pair<BWTA::Region *, BWTA::Region *>;
}
;

您可以从 2 个页面下载原始 src 代码我在上面列出了任何 svn 客户端。 谢谢。 请帮忙!

I'm trying to make a CFFI wrapper for BWAPI (which was written on C++ ) from http://code.google.com/p/bwapi/ ,by modifying another BWAPI-bridge (which was written on C#) http://code.google.com/p/bwapi-mono-bridge/.

My OS: Window 7 Professional

SWIG version: 2.0.3

UAC : off

(*Here come the error code if I don't specify the /std folder in the %include part: http://pastebin.com/XkePbKjG )

  • Update: The same error on Linux :
    enter image description here

  • On window with SWIG 2.0.3
    Here come my error on wrapping process on window:

Here is the content of my BuildInterface.bat which was modified from the original :

:start 

erase /s /q Classes\*.*
erase /s /q Wrapper\*.*

swig.exe -cffi  -c++ -I..\BWAPI\Include  -outdir Classes\BWAPI  -o Wrapper\bwapi-bridge.cxx Interfaces\bwapi-bridge.i

swig.exe -cffi -c++ -I..\BWAPI\Include -outdir Classes\BWTA  -o Wrapper\bwta-bridge.cxx Interfaces\bwta-bridge.i

swig.exe -cffi -c++ -I..\BWAPI\Include  -outdir Classes\BWAPIC   -o Wrapper\bwapiclient-bridge.cxx Interfaces\bwapiclient-bridge.i

pause
goto start

And the modified bwapi-bridge.i :

%include "cpointer.i"
%include "carrays.i"
//include headers in our generated code.
%module bwapi
%{
#include "BWAPI.h"

using namespace BWAPI;
%}                    

//special include for our dllimport attribute
%include "dllimport.i"


//resolve ambiguities
%include "ambiguities.i"

//unimplemented functions in headers (or ones that should not be called)
//uncomment these each new version of BWAPI to ensure they are not later implemented.
#%ignore getPlayerUnits;
#%ignore BWAPI::GameData::GameData;

//fix up operator overrides.
%rename (opAssign) *::operator =;
%rename (opEquals) *::operator ==;
%rename (opLessThan) *::operator <;
%rename (opGreaterThan) *::operator >;
%rename (opMinus) *::operator -;
%rename (opNotEquals) *::operator !=;                         
%rename (opPlus) *::operator +;
%rename (opAdd) *::operator +=;
%rename (opSubtract) *::operator -=;

//fix up const strings.
%apply const  string & { string &};


%include "BWAPI.h"
%include "BWAPI/EventType.h"
%include "BWAPI/GameType.h"
%include "BWAPI/Race.h"
%include "BWAPI/TechType.h"
%include "BWAPI/UpgradeType.h"
%include "BWAPI/Position.h"
%include "BWAPI/AIModule.h"
%include "BWAPI/Color.h"
%include "BWAPI/Constants.h"
%include "BWAPI/CoordinateType.h"
%include "BWAPI/DamageType.h"
%include "BWAPI/Error.h"
%include "BWAPI/ExplosionType.h"
%include "BWAPI/Flag.h"
%include "BWAPI/Force.h"
%include "BWAPI/Input.h"
%include "BWAPI/Event.h"
%include "BWAPI/Latency.h"
%include "BWAPI/Order.h"
%include "BWAPI/PlayerType.h"
%include "BWAPI/Player.h"
%include "BWAPI/BulletType.h"
%include "BWAPI/Bullet.h"
%include "BWAPI/TilePosition.h"
%include "BWAPI/UnitCommandType.h"
%include "BWAPI/UnitCommand.h"
%include "BWAPI/Game.h"
%include "BWAPI/Unit.h"
%include "BWAPI/UnitSizeType.h"
%include "BWAPI/UnitType.h"
%include "BWAPI/WeaponType.h"

%include "std/std_vector.i"
%include "std/std_set.i"
%include "std/std_pair.i"
%include "std/std_list.i"
%include "std/std_map.i"

//Instantiate our templates
namespace std {
%template (PositionVector)vector<BWAPI::Position>;
%template (BulletPtrSet)  set<BWAPI::Bullet *>;
%template (BulletTypeSet) set<BWAPI::BulletType>;
%template (DamageTypeSet) set<BWAPI::DamageType>;
%template (ErrorSet)  set<BWAPI::Error>;
%template (ExplosionTypeSet) set<BWAPI::ExplosionType>;
%template (ForcePtrSet)  set<BWAPI::Force *>;
%template (GameTypeSet)  set<BWAPI::GameType>;
%template (OrderSet)  set<BWAPI::Order>;
%template (PlayerPtrSet)  set<BWAPI::Player *>;
%template (PlayerTypeSet)  set<BWAPI::PlayerType>;
%template (RaceSet)  set<BWAPI::Race>;
%template (TechTypeSet)  set<BWAPI::TechType>;
%template (TilePositionSet)  set<BWAPI::TilePosition>;
%template (UnitPtrSet)  set<BWAPI::Unit*>;
%template (UnitCommandTypeSet)  set<BWAPI::UnitCommandType>;
%template (UnitSizeTypeSet)  set<BWAPI::UnitSizeType>;
%template (UnitTypeSet)  set<BWAPI::UnitType>;
%template (UpgradeTypeSet)  set<BWAPI::UpgradeType>;
%template (WeaponTypeSet)  set<BWAPI::WeaponType>;
%template (EventList)  list<BWAPI::Event>;
%template (UnitTypeList)  list<BWAPI::UnitType>;
%template (TilePositionDoubleMap)  map<BWAPI::TilePosition, double>;
%template (UnitTypeIntMap)  map<BWAPI::UnitType, int>;
%template (PositionPair)  pair<BWAPI::Position,BWAPI::Position>;
%template (TilePositionDoublePair)  pair<BWAPI::TilePosition, double>;
%template (UnitTypeIntPair)  pair<BWAPI::UnitType,int>;
%template (TilePositionVector)  vector<BWAPI::TilePosition>;
%template (PositionSet)  set<BWAPI::Position>;
};

Along with modified bwta-bridge.i :

%include "cpointer.i"
%module bwta
%{
#include "BWAPI.h"
#include "BWTA.h"

using namespace BWTA;
%}                  
//use getcolumn instead
%ignore operator[];

//import BWAPI
%import "bwapi-bridge.i"


//BWTA order of includes is important to stop SWIGTYPE_p etc class generation with and without namespace
%include "BWTA/RectangleArray.h"
%include "BWTA/BaseLocation.h"
%include "BWTA/Chokepoint.h"
%include "BWTA/Polygon.h"
%include "BWTA/Region.h"
%include "BWTA.h"


%module bwta-bridge
%include "std/std_vector.i"

%include "std/std_set.i"

%include "std/std_pair.i"




//Instantiate our templates

%template (RectangleArrayDouble) BWTA::RectangleArray<double>; 


namespace std {

    %template (BaseLocationPtrSet) set<BWTA::BaseLocation *>;
        %template (RegionPtrSet)       set<BWTA::Region *>;
        %template (ChokepointPtrSet)   set<BWTA::Chokepoint *>;
        %template (PolygonPtrSet)      set<BWTA::Polygon *>;
        %template (PolygonVector)      vector<BWTA::Polygon>;
        %template (RegionPtrRegionPtrPair) pair<BWTA::Region *, BWTA::Region *>;
}
;

You can download the original src code from the 2 pages I listed above with any svn client.
Thank you.
Please Help !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

廻憶裏菂餘溫 2024-11-10 05:51:24

好吧……用至少30个字符的正文扔掉它。

Ok... Throw it away with a body that at least 30 characters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文