Need help with makefile

This is a discussion on Need help with makefile within the C++ Programming forums, part of the General Programming Boards category; Hello! I'm just starting to learn c++. I also like to play chess against other people and against computer programs. ...

Need help with makefile

Hello! I'm just starting to learn c++. I also like to play chess against other people and against computer programs. There is a very famous chess program called Fruit 2.1 that I have been trying to compile the windows version before I edit the source code to change its playing style. You can find the source at:

Performance Questions

I finally compiled the Fruit 2.1 chess engine source without the makefile using the code::blocks IDE and the GNU GCC compiler. The executable runs fine, but I have some new questions that I hope others can answer.

A: The downloaded Fruit 2.1 chess engine source comes with an executable that runs much faster than the one I created with the GNU GCC compiler. Why is the executable I created so much slower? I have not modified the source files yet and I tried checking some of the speed optimizations in the GNU GCC compiler settings. The two programs
do exactly the same thing, but the one I created is much slower.

C: Do all commercial IDEs come with some special tools to get the most out of certain compilers? In other words are they able to fully optimize source code to create a better performing executable while those of us who use a free IDE like code::blocks cannot. If so, that is a major bummer because then I'll have to buy me an expensive IDE that can better optimize code and better utilize certain c++ compilers.

Please remember that some of us don't know the answers to these questions because we are just learning to program.

A. You may be compiling in debug mode or with no optimizations. You want to pass something like "-O3" to as a compiler option. There's probably an option in you project preferences somewhere (like release build vs. debug build or something along those lines)

B. This could again be due to compile time options, or maybe the distributed executable was built from older source. :dunno:

C. All compilers do, it has little to do with the IDE. gcc is one of the best compilers available, you don't need to buy anything special. Just use the proper compile time flags. Have a look at the flags they use in the makefile (like "-O3").

The downloaded Fruit 2.1 chess engine source comes with an executable that runs much faster than the one I created with the GNU GCC compiler. Why is the executable I created so much slower? I have not modified the source files yet and I tried checking some of the speed optimizations in the GNU GCC compiler settings. The two programs
do exactly the same thing, but the one I created is much slower.

As in you enabled optimisations when compiling and defined NDEBUG, but the program you built is still slower than the given binary? One possibility is that the program is written to be best optimised for a certain compiler, and gcc isn't it. It can also be the case that say, Microsoft or Intel compilers tend to generate better code because of inside knowledge of the platform, and it is a Microsoft or Intel compiler that was used to compile the binary that you were provided.

You may be better off asking on the Arena forums about this. Perhaps you need to set some preprocessor definition that enables these features.

Originally Posted by New_Programmer

C: Do all commercial IDEs come with some special tools to get the most out of certain compilers? In other words are they able to fully optimize source code to create a better performing executable while those of us who use a free IDE like code::blocks cannot. If so, that is a major bummer because then I'll have to buy me an expensive IDE that can better optimize code and better utilize certain c++ compilers.

The "special tools" that they come with are usually for increasing productivity rather than increasing optimisation, which is something in the domain of the compiler. One "special tool" that does allow a programmer to better optimise code is a profiler, but it tells you where the bottle necks in performance are instead of magically performing the optimisations for you. That said, gprof would be the profiler to use for gcc, but I cannot remember offhand if a gprof plugin exists for Code::Blocks.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Thanks to everyone who has answered questions and tried to help. It is much appreciated.

Yes, most of my questions had already been answered except for making the makefile work in code::blocks. I really meant to reword and post the part "c" question because i'm trying to figure out why my executable is a little slower. For example, in a 50 second opening position analysis my executable will evaluate approximately 23,300,000 nodes and the original executable will do approximately 32,200,000 nodes. In chess, all things being equal, if you can search and evaluate more positions than your opponent you will win. The speed difference is very puzzling to me because i'm using the same compiler "g++" and have checked the same optimizations for the compiler. Although I have not tried setting:

in the "Other Options" submenu. Would a simple copy and paste work? Finally, I am not really going modify the source code for Fruit 2.1 just yet because I don't know enough to do it, but am only changing the evaluation parameters to change its evaluation and playing style. I am currently working through several online tutorials to get better at c++. Any recommendations for online tutorials?

Oh and if anybody else has had the same problem using a makefile on code::blocks just go to the code::blocks forum and look for the "problems with makefile" thread. I finally got the makefile to work as well.

I will try the above optimizations by copy paste and see if that works and makes a difference but I don't think it will because the executable compiled with the makefile should have taken that into account already and it too is quite a bit slower. And no it is not a debug compiled version. I would just like to know why it is slower. Perhaps the source code that is distributed is a little different. Or does the machine itself make any difference and if so why should it make a difference after all the executables were all created with g++ and the same optimizations. I think i'm not the only person who would like to know.

-O3 will give you a good boost if you didn't have that before.
-fomit-frame-pointer gives the compiler one more register "to play with" (but makes debugging harder, and it may not apply to all functions).
-fstrict-aliasing is automatically enabled in -O3, so no need to specify that specifically.

When you say it's the same compiler, is it the same VERSION of gcc. There are big differences between gcc 3.x and 4.x (or 2.x for that matter) - some code runs faster, some slower for each version (although in general, newer version should give better [faster] code).