Compiling Daydreamer in Visual Studio

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

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

Compiling Daydreamer in Visual Studio

Post by Greg Strong »

I'm very impressed with Daydreamer. In games against it, it's beating me about 93% of the time :shock:

I'd like to be able to make my own builds so I can experiment, but it doesn't seem to want to compile under Visual Studio. It doesn't recognize the "bool" type. My guess is because all the code is in extern "C" { } sections, but removing didn't seem to help. Everything in the documentation seems to indicate that "bool" is built-in; can't find anything in project options. Also defining bool myself didn't seem to be legal...

Anyone know how to compile Daydreamer in Visual C++ (using Visual Studio 2010 RC at the moment- maybe should try older version).
Dann Corbit
Posts: 12538
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Compiling Daydreamer in Visual Studio

Post by Dann Corbit »

Greg Strong wrote:I'm very impressed with Daydreamer. In games against it, it's beating me about 93% of the time :shock:

I'd like to be able to make my own builds so I can experiment, but it doesn't seem to want to compile under Visual Studio. It doesn't recognize the "bool" type. My guess is because all the code is in extern "C" { } sections, but removing didn't seem to help. Everything in the documentation seems to indicate that "bool" is built-in; can't find anything in project options. Also defining bool myself didn't seem to be legal...

Anyone know how to compile Daydreamer in Visual C++ (using Visual Studio 2010 RC at the moment- maybe should try older version).
Daydreamer requires a C99 compiler, which VC++ is not.
You have no shot to compile it with VC++ without doing a big conversion.

It is not just the data types, but also variable scopes, const rules, variant arrays and other things that simply are not allowed in C90.

You can build it with the GCC tool chain.
I was able to successfully build a 64 bit version using MINGW (64 bit version).
Dann Corbit
Posts: 12538
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Compiling Daydreamer in Visual Studio

Post by Dann Corbit »

Dann Corbit wrote:
Greg Strong wrote:I'm very impressed with Daydreamer. In games against it, it's beating me about 93% of the time :shock:

I'd like to be able to make my own builds so I can experiment, but it doesn't seem to want to compile under Visual Studio. It doesn't recognize the "bool" type. My guess is because all the code is in extern "C" { } sections, but removing didn't seem to help. Everything in the documentation seems to indicate that "bool" is built-in; can't find anything in project options. Also defining bool myself didn't seem to be legal...

Anyone know how to compile Daydreamer in Visual C++ (using Visual Studio 2010 RC at the moment- maybe should try older version).
Daydreamer requires a C99 compiler, which VC++ is not.
You have no shot to compile it with VC++ without doing a big conversion.

It is not just the data types, but also variable scopes, const rules, variant arrays and other things that simply are not allowed in C90.

You can build it with the GCC tool chain.
I was able to successfully build a 64 bit version using MINGW (64 bit version).
Here is my build {has source and binaries} (you have to do a few little tweaky things to get it to work):
http://cap.connx.com/chess-engines/new- ... dreamer.7z
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 »

Dann Corbit wrote:
Dann Corbit wrote:
Greg Strong wrote:I'm very impressed with Daydreamer. In games against it, it's beating me about 93% of the time :shock:

I'd like to be able to make my own builds so I can experiment, but it doesn't seem to want to compile under Visual Studio. It doesn't recognize the "bool" type. My guess is because all the code is in extern "C" { } sections, but removing didn't seem to help. Everything in the documentation seems to indicate that "bool" is built-in; can't find anything in project options. Also defining bool myself didn't seem to be legal...

Anyone know how to compile Daydreamer in Visual C++ (using Visual Studio 2010 RC at the moment- maybe should try older version).
Daydreamer requires a C99 compiler, which VC++ is not.
You have no shot to compile it with VC++ without doing a big conversion.

It is not just the data types, but also variable scopes, const rules, variant arrays and other things that simply are not allowed in C90.

You can build it with the GCC tool chain.
I was able to successfully build a 64 bit version using MINGW (64 bit version).
Here is my build {has source and binaries} (you have to do a few little tweaky things to get it to work):
http://cap.connx.com/chess-engines/new- ... dreamer.7z
Ok, thanks. I'll give it a quick try, but won't spend much time with it. Didn't realise that C code was not compatable with C++ anymore. (Can't remember the last time I tried to compile something in straight C.)
Aaron Becker
Posts: 292
Joined: Tue Jul 07, 2009 4:56 am

Re: Compiling Daydreamer in Visual Studio

Post by Aaron Becker »

Greg Strong wrote:
Dann Corbit wrote:
Dann Corbit wrote:
Greg Strong wrote:I'm very impressed with Daydreamer. In games against it, it's beating me about 93% of the time :shock:

I'd like to be able to make my own builds so I can experiment, but it doesn't seem to want to compile under Visual Studio. It doesn't recognize the "bool" type. My guess is because all the code is in extern "C" { } sections, but removing didn't seem to help. Everything in the documentation seems to indicate that "bool" is built-in; can't find anything in project options. Also defining bool myself didn't seem to be legal...

Anyone know how to compile Daydreamer in Visual C++ (using Visual Studio 2010 RC at the moment- maybe should try older version).
Daydreamer requires a C99 compiler, which VC++ is not.
You have no shot to compile it with VC++ without doing a big conversion.

It is not just the data types, but also variable scopes, const rules, variant arrays and other things that simply are not allowed in C90.

You can build it with the GCC tool chain.
I was able to successfully build a 64 bit version using MINGW (64 bit version).
Here is my build {has source and binaries} (you have to do a few little tweaky things to get it to work):
http://cap.connx.com/chess-engines/new- ... dreamer.7z
Ok, thanks. I'll give it a quick try, but won't spend much time with it. Didn't realise that C code was not compatable with C++ anymore. (Can't remember the last time I tried to compile something in straight C.)
Unfortunately some of the rules about types have diverged between C and C++, which, as Dann said, stops it from working with C++ compilers (there are a few other issues, but that's the biggest thing). I've thought about converting it to compile cleanly with a C++ compiler, but it hasn't ever made it to the top of my priority queue.

In any case, I'm happy that daydreamer got your attention. If you have any questions about it I'd be happy to discuss, and if you do happen to get it compiling and do some experiments, I'd love to hear what you learn.
CThinker
Posts: 388
Joined: Wed Mar 08, 2006 10:08 pm

Re: Compiling Daydreamer in Visual Studio

Post by CThinker »

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;}
#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.
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 »

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;}
#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.)
CThinker
Posts: 388
Joined: Wed Mar 08, 2006 10:08 pm

Re: Compiling Daydreamer in Visual Studio

Post by CThinker »

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;}
#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.
CThinker
Posts: 388
Joined: Wed Mar 08, 2006 10:08 pm

Re: Compiling Daydreamer in Visual Studio

Post by CThinker »

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;}
#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;
Dann Corbit
Posts: 12538
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Compiling Daydreamer in Visual Studio

Post by Dann Corbit »

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.