0
votes

I finished working on my Checkers game engine and about to make it CheckerBoard (http://www.fierz.ch/cbdeveloper.php) compatible, and it states that.

CheckerBoard expects your engine to be compiled as a dll and to be in the working directory of checkerboard.exe - or in the path. An engine must support 2 required functions. ..., you must provide 2 more functions for multi-version support. The calling convention for all functions is __stdcall().

Required Functions

The current CheckerBoard API (version 2) requires the following 2 functions:

int WINAPI getmove(int board[8][8], int color, double maxtime, char str[1024], int *playnow, int info, int moreinfo, struct CBmove *move);
int WINAPI enginecommand(char command[256], char reply[1024]);

my engine includes the two above functions, i've got everything setup (the code) but i'm having troubles compiling it as dll, heres what i tried (using gcc)

gcc -c engine.c
gcc -shared -o engine.dll engine.o

it creates the dll as expected but the dll doesn't export any of the functions (as expected).

I used the Dependency walker program to scan the engine.dll file, and it shows that the dll exports the functions

  • _getmove@28
  • _enginecommand@20

i scanned one of the engines in the CheckerBoard directory and i found that they export the following functions:

  • getmove
  • enginecommand

i cant figure out why the dll i created exports differently, maybe its got something to do with the WINAPI ?.

Any ideas ?

here's what it looks like

#define EXPORT __declspec(dllexport)

EXPORT int WINAPI getmove(int b[8][8], int color, double time, char str[1024], int *playnow, int info, int unused, struct CBmove *cbmove){
    // ....
    return 0;
}


EXPORT int WINAPI enginecommand (char str[256], char reply[1024]){
    // ...
    return 0;
}

i need both functions to be exported through the dll.

1
Please edit your question by giving some minimal reproducible example, or at least by showing the relevant code (and declarations) in your engine.c; show the lines declaring and defining getmove etcBasile Starynkevitch

1 Answers

1
votes

You probably need to annotate (the declaration of) these exported functions with Windows function attributes like __attribute__((dllexport)); I recommend having a declaration like

extern WINAPI getmove(int b[8][8], int color, double time, 
                      char str[1024], int *playnow, int info, 
                      int unused, struct CBmove *cbmove) 
       __attribute__((dllexport));

before that function's definition.

You may need to compile your source as position independent code (on Linux it is nearly required with -fPIC, for Windows DLL you need to check your documentation).

So try to compile with gcc -Wall -O -g -fPIC -shared engine.c -o engine.dll

See also this related question (and answers there).

PS. I never used Windows (only Unix since 1987 and Linux since 1993). I recommend reading Levine's Linkers and loaders book