Compiling Daydreamer in Visual Studio

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

CThinker
Posts: 388
Joined: Wed Mar 08, 2006 10:08 pm

Re: Compiling Daydreamer in Visual Studio

Post by CThinker »

Dann Corbit wrote:
CThinker wrote:
CThinker wrote:
Greg Strong wrote:
CThinker wrote:
Dann Corbit wrote: You have no shot to compile it with VC++ without doing a big conversion.
It isn't big. It does not even involve a "conversion".

1. cast all calls to malloc() with the target type. there is just 3 or 4 of these.
2. wrap with #ifndef _MSC_VER (or remove) the line #include <strings.h>
3. in compatibility.h, add the following lines under the _MSC_VER section:
typedef __int64 int64_t;
#define PRIu64 "%I64u"
#define PRIx64 "%I64x"
#define INT32_MAX INT_MAX
#define INT64_MAX _I64_MAX
#include <time.h>
int gettimeofday(struct timeval *tv, struct timezone *tz){clock_t c=clock();tv->tv_sec=c/1000;tv->tv_usec=(c%1000)*1000;return 0;}
This assumes that CLOCKS_PER_SEC is 1000. It probably is on most MS compilers, but CLOCKS_PER_SEC will have the right value and be more portable.
#define snprintf _snprintf
4. in eval_pieces.c, define 'file_t file' and 'int rrank' at the start of the function instead of before its use.
5. in hash.c, add "={}" to the declaration of piece_random, castle_random and enpassant_random

that's it! now compile "as C++" (-TP option).
cl -Oxt -W0 -TP *.c

btw, the gettimeofday above is not correct. the engine is not looking for the time of day anyway - but just some timer. so, that is what is provided here in a compact form.
What version of VC++ does this work with? Asking because it doesn't look this will address the fact that it doesn't recognize "bool" (and won't let me define it.)
It works with PSDKs (VC7, VC8,VC9), and VC10 (VS 2010 RC).

The reason why you can't get 'bool' to work is that you are trying to compile "as C". You should compile "as C++", using the "-TP" option.
Oh, I forgot one more thing...

This engine has code that does arithmetic operations on enum types. To get around that, you do this:

Replace enum definitions that looks like:
typedef enum { E1, E2 } my_t;

with:
enum { E1, E2 };
typedef int my_t;
Did you actually try it?

I get thousands of compilation errors due to variables declared after the execution of a statement and other things like that.
Yes, I have.

The reason you are getting those errors is that you are compiling them as C. You should instead compile them as C++. In VC, that is option -TP.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Compiling Daydreamer in Visual Studio

Post by Sven »

CThinker wrote:
Greg Strong wrote:
CThinker wrote:
Dann Corbit wrote: You have no shot to compile it with VC++ without doing a big conversion.
It isn't big. It does not even involve a "conversion".
[...]
that's it! now compile "as C++" (-TP option).
cl -Oxt -W0 -TP *.c
What version of VC++ does this work with? Asking because it doesn't look this will address the fact that it doesn't recognize "bool" (and won't let me define it.)
It works with PSDKs (VC7, VC8,VC9), and VC10 (VS 2010 RC).

The reason why you can't get 'bool' to work is that you are trying to compile "as C". You should compile "as C++", using the "-TP" option.
I can't even get the following single-file micro example project to compile with VC8 (=VS 2005), PSDK 2003, and default project settings which do include /TP option:

Code: Select all

// main.c
#ifdef _WIN32
#include <windows.h>
#endif

extern bool xyz;

int main&#40;)
&#123;
    return 0;
&#125;
On my system it delivers the same error message for the "extern bool big_endian;" line in "compatibility.h" as for compiling the original daydreamer sources, even with the modifications given by Lance.

So it seems Gregory and myself (and Dann?) are doing wrong something very basic here. But what?

After taking a brief look into daydreamer sources I have the same impression as Lance that making it compilable under C++ would not be a big deal, but there is some trivial stuff around preventing me from actually doing it ...

Puzzled,
Sven
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Compiling Daydreamer in Visual Studio

Post by Sven »

It isn't even related to <windows.h>. "bool xyz;" => error ?!

I am regularly using "bool" in my own projects which I compile with VC8. I don't understand what's happening here. Microsoft online doc says "bool" is a built-in type since VC++ 5.0 which is also what I had in mind for a long time. Can someone enlighten me? Obviously the "default" project settings in VS2005 (VC8) are not "default" enough to use the bool built-in type?

Sven
User avatar
Jim Ablett
Posts: 1384
Joined: Fri Jul 14, 2006 7:56 am
Location: London, England
Full name: Jim Ablett

Re: Compiling Daydreamer in Visual Studio

Post by Jim Ablett »

Sven Schüle wrote:It isn't even related to <windows.h>. "bool xyz;" => error ?!

I am regularly using "bool" in my own projects which I compile with VC8. I don't understand what's happening here. Microsoft online doc says "bool" is a built-in type since VC++ 5.0 which is also what I had in mind for a long time. Can someone enlighten me? Obviously the "default" project settings in VS2005 (VC8) are not "default" enough to use the bool built-in type?

Sven

Hi Sven,

Msvc's built-in type BOOL is not the same.
http://www.codeguru.com/forum/showthread.php?t=332831

So need to add to 'compatibility.h' >

Code: Select all

#undef bool
#define bool int
#define true 1
#define false 0
Jim.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Compiling Daydreamer in Visual Studio

Post by Sven »

Jim Ablett wrote:
Sven Schüle wrote:It isn't even related to <windows.h>. "bool xyz;" => error ?!

I am regularly using "bool" in my own projects which I compile with VC8. I don't understand what's happening here. Microsoft online doc says "bool" is a built-in type since VC++ 5.0 which is also what I had in mind for a long time. Can someone enlighten me? Obviously the "default" project settings in VS2005 (VC8) are not "default" enough to use the bool built-in type?

Sven

Hi Sven,

Msvc's built-in type BOOL is not the same.
http://www.codeguru.com/forum/showthread.php?t=332831

So need to add to 'compatibility.h' >

Code: Select all

#undef bool
#define bool int
#define true 1
#define false 0
Jim.
The link you refer to correctly says the opposite of what you say:
'bool' is a built-in C++ type while 'BOOL' is a Microsoft specific type that is defined as an 'int'.
Instead, I found the real reason which is very weird. If the filename ends in ".c" then MSVC does not know "bool" as built-in type, while filenames ending in ".cpp" make no problem. :shock: :shock:

I have not found out yet whether this is normal and documented behaviour, or some setup problem. At least the registry settings under HKEY_CLASSES_ROOT look ok for me for both .c and .cpp entries.

This explains why I never got any problems in the past with "bool": my C++ source files always have the extension ".cpp". Really weird behaviour of the compiler, it ignores the /TP option if the file is *.c.

Does anyone know more about this?

Sven
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Compiling Daydreamer in Visual Studio

Post by Sven »

Sven Schüle wrote:Instead, I found the real reason which is very weird. If the filename ends in ".c" then MSVC does not know "bool" as built-in type, while filenames ending in ".cpp" make no problem. :shock: :shock:

I have not found out yet whether this is normal and documented behaviour, or some setup problem. At least the registry settings under HKEY_CLASSES_ROOT look ok for me for both .c and .cpp entries.

This explains why I never got any problems in the past with "bool": my C++ source files always have the extension ".cpp". Really weird behaviour of the compiler, it ignores the /TP option if the file is *.c.

Does anyone know more about this?

Sven
The MSVC 2005 GUI maintains a "compile as C" resp. "compile as C++" setting also on a per-file level. When adding a .c file to a project that file by default gets the "compile as C" setting, so the project setting /TP does simply not apply, which creates the weird behaviour mentioned above. Using MSVC++ 2005 via commandline only should not suffer from that problem.

After changing this setting to "compile as C++" for all *.c files of Daydreamer and applying the few changes mentioned above by Lance, I can now compile Daydreamer 1.75 without errors under MS Visual Studio 2005, although with some warnings about float-int conversions or similar stuff.

Everything looks "easy" once you know how to do it ...

Sven
CThinker
Posts: 388
Joined: Wed Mar 08, 2006 10:08 pm

Re: Compiling Daydreamer in Visual Studio

Post by CThinker »

Sven Schüle wrote: After changing this setting to "compile as C++" for all *.c files of Daydreamer and applying the few changes mentioned above by Lance, I can now compile Daydreamer 1.75 without errors under MS Visual Studio 2005, although with some warnings about float-int conversions or similar stuff.
Sven
Its good to know that you too got it working. Daydreamer is quite an interesting engine.

I now see the difference in building. People use the MSVC GUI to compile, and I never do (except when I have to create GUI apps, COM apps, or anything where auto-genarated code helps). Come to think of it, I don't even install the MS Dev Env on most of my machines. I just install the PSDK or the WDK.

For those who really want to use the MSVC GUI and could not get the correct compile options, it is probably easier to just rename the source code files from ".c" to ".cpp".

Cheers...
User avatar
Greg Strong
Posts: 388
Joined: Sun Dec 21, 2008 6:57 pm
Location: Washington, DC

Re: Compiling Daydreamer in Visual Studio

Post by Greg Strong »

Awesome! Thanks, guys. Glad it's doable without too much rewriting. I'll get it compiled shortly.
Aaron Becker
Posts: 292
Joined: Tue Jul 07, 2009 4:56 am

Re: Compiling Daydreamer in Visual Studio

Post by Aaron Becker »

Thanks for the third-party tech support, guys. I'll try to make sure that Daydreamer can compile under a C++ compiler out of the box in the next release. I always wonder if anyone actually reads the code I publish, so it's nice to hear that people are reading it and experimenting with it.