Page 1 of 1
Problems compiling Test AI
Posted: 28 Aug 2005, 20:59
by submarine
I just tried to compile the global test ai from the taspring0.62b1 source code using c::b (i don´t want to spend hundreds of megabytes for visual studio)
compiling has been succesfull (although my dll is about 125kb compared to 64kb of the original test.dll), so i tried to set up a game; but everytime i want to run global ai script, there´s just the "wrong ai dll"-message that is displayed when using the old jcai version with spring 0.62b1.
does anybody have any ideas which mistakes i made?
Posted: 28 Aug 2005, 22:02
by jcnossen
See if the function names are exported correctly. They should be exported in the DLL like this:
Code: Select all
GetGlobalAiVersion
GetAiName
GetNewAI
ReleaseAI
The problem is that the used calling convention here (which is __stdcall) will export the function names differently, with argument sizes attached to it.
So you need to use the .def file that is included with the source, but maybe you didn't use that which would cause "Wrong ai dll" i guess.
If this is not the cause then you have either a wrong spring version or a wrong spring source...
Posted: 28 Aug 2005, 22:28
by submarine
yes you´re right; c::b exported more than 100 functions; i´ll just try to figure out how to tell it to only export those 4 functions...
Posted: 29 Aug 2005, 15:54
by submarine
well i should now export the needed functions, at least the autocreated .def-file says
Code: Select all
EXPORTS
GetAiName @1
GetGlobalAiVersion @2
GetNewAI @3
ReleaseAI @4
but now spring always terminates when loading the ai. i only made some changes in the testai.cpp in order to be able to compile it with code::blocks, but the functions themselves have not been changed.
testai.h, globalai.cpp and globalai.h are just the same as in the 0.62b1 source
Code: Select all
//testai.cpp
#include <windows.h>
#include "TestAI.h"
#include "globalai.h"
#include <set>
#define EXPORT __declspec(dllexport)
#ifdef __cplusplus
extern "C" {
#endif
std::set<IGlobalAI*> ais;
EXPORT int GetGlobalAiVersion()
{
return GLOBAL_AI_INTERFACE_VERSION;
}
EXPORT void GetAiName(char* name)
{
strcpy(name,AI_NAME);
}
EXPORT IGlobalAI* GetNewAI()
{
CGlobalAI* ai=new CGlobalAI();
ais.insert(ai);
return ai;
}
EXPORT void ReleaseAI(IGlobalAI* i)
{
delete (CGlobalAI*)i;
ais.erase(i);
}
#ifdef __cplusplus
}
#endif
Posted: 29 Aug 2005, 17:59
by jcnossen
Does it use __stdcall calling convention?, most compilers default to cdecl
Posted: 29 Aug 2005, 23:49
by submarine
well i´m not quite shure; afaik you use
Code: Select all
void foo() __attribute__((stdcall));
to tell a gnu gcc compiler to use stdcalling convention; but this didnt work as well and always results in a crash at the beginning of the game.
so far i´ve given up, i´ll try it with another compiler; microsoft c++ compiler would be the best, but there aren´t even basic headers like windows.h included in the microsoft c++ toolkit

Posted: 30 Aug 2005, 17:43
by submarine
i don´t think a wrong calling convention is the problem because it says
Code: Select all
Warning: resolving _GetAiName by linking to _GetAiName@4
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Warning: resolving _GetNewAI by linking to _GetNewAI@0
Warning: resolving _ReleaseAI by linking to _ReleaseAI@4
so by the leading _ and the @n appended these functions should use stdcall. i´ve absolutely no idea whats wrong.
@zaphod: which compiler do you use? im facing exactly the same problem compiling jcai

Posted: 30 Aug 2005, 19:22
by jcnossen
I had to say I had the same problem back when I was compiling on GCC, but I stopped trying when I got my hands on VS .net. I guess I could try again on GCC...
Posted: 01 Sep 2005, 15:01
by submarine
ok finally i was able to compile it with vs.net and *tata* it works :)
nevertheless i think i would be goud to figure out how to do that with gnu gcc under code::blocks, not only because it is free but it also saves a lot of disc space...
Posted: 01 Sep 2005, 18:19
by jcnossen
nevertheless i think i would be goud to figure out how to do that with gnu gcc under code::blocks, not only because it is free but it also saves a lot of disc space...
True, it's always good to have compatibility across compilers. Though I think we should just wait for the linux port to be merged and then see how modules are handled...
I don't really like the use of a .def file, since normally you can just see the calling convention from the function name.
Posted: 01 Sep 2005, 19:42
by submarine
I don't really like the use of a .def file, since normally you can just see the calling convention from the function name.
i agree with you :)
i think beeing able to compile with gcc would would increase the number of people who could work on ais or other stuff. installing vc.net probably scares a lot of people....