Stockfish-1.2 compile on Ubuntu - Error

Discussion of anything and everything relating to chess playing software and machines.

Moderator: Ras

Pradu
Posts: 287
Joined: Sat Mar 11, 2006 3:19 am
Location: Atlanta, GA

Re: Stockfish-1.2 compile on Ubuntu - Error

Post by Pradu »

ilari wrote:Actually none of the C libraries (including cstring) needs the namespace qualifier. Otherwise Roy's compile would have failed
They should. Perhaps he was using a non-conformant C++ library?

http://www.cplusplus.com/reference/clibrary/
The C++ library includes the same definitions as the C language library organized in the same structure of header files, with the following differences:

* Each header file has the same name as the C language version but with a "c" prefix and no extension. For example, the C++ equivalent for the C language header file <stdlib.h> is <cstdlib>.
* Every element of the library is defined within the std namespace.

Nevertheless, for compatibility with C, the traditional header names name.h (like stdlib.h) are also provided with the same definitions within the global namespace. In the examples provided in this reference, this version is used so that the examples are fully C-compatible, although its use is deprecated in C++.
Also take a look at the C++ standard (ISO/IEC 14882:1998(E)) pg319, Section 17.4.12 Headers clause 4:
Except as noted in clauses 18 through 27, the contents of each header cname shall be the same as that of the corresponding header name.h, as specified in ISO/IEC 9899:1990 Programming Languages C (Clause 7), or ISO/IEC:1990 Programming Languages--C AMENDMENT 1: C Integrity, (Clause 7), as appropriate, as if by inclusion. In the C++ Standard Library, however, the declarations and definitions (except for names which are defined as macros in C) are within namespace scope (3.35) of the namespace std.
User avatar
ilari
Posts: 750
Joined: Mon Mar 27, 2006 7:45 pm
Location: Finland

Re: Stockfish-1.2 compile on Ubuntu - Error

Post by ilari »

That's interesting. I highly doubt that the GNU Standard C++ Library (which very likely is what Roy's using) is non-conformant. std::memset() works as well, so obviously the functions are in the std namespace. The headers may already include a using-declaration for every function, but not using-directive which would make the whole namespace available. Does the standard say anything about that?
Pradu
Posts: 287
Joined: Sat Mar 11, 2006 3:19 am
Location: Atlanta, GA

Re: Stockfish-1.2 compile on Ubuntu - Error

Post by Pradu »

ilari wrote:That's interesting. I highly doubt that the GNU Standard C++ Library (which very likely is what Roy's using) is non-conformant. std::memset() works as well, so obviously the functions are in the std namespace. The headers may already include a using-declaration for every function, but not using-directive which would make the whole namespace available. Does the standard say anything about that?
I can't see anything about putting the symbols in global scope as well in the standard. Putting the stuff into the std namespace defeats the purpose of a namespace if they exist in global scope as well. You wouldn't be able to do something like this:

Code: Select all

#include <cstdio>

void printf(char const* test)
{
    std::printf("Hello World Custom!\n");
}

int main()
{
    std::printf("Hello World\n");
    printf("Hello World\n");
}
GCC headers are just non-conformant (or perhaps loosly-conformant?) to the standard here. Some like Microsoft even do some vodoo magic in their documentation saying that the symbols may be in global namespace and sometimes may not be in global namespace (http://msdn.microsoft.com/en-us/library/58dt9f24.aspx) :
Including this header also ensures that the names declared with external linkage in the Standard C library header are declared in the std namespace. In this implementation, the names may or may not also be declared in the global namespace, depending on the specific translation environment.
Maybe in the future the standards committee might have to say whether the symbols should be in the global namespace or not. However, a good safe bet is to assume that they won't be if you are using the symbols and that they will be if you are trying to write your own version of say printf in the global namespace. Assume the worst 8-)
BBauer
Posts: 658
Joined: Wed Mar 08, 2006 8:58 pm

Re: Stockfish-1.2 compile on Ubuntu - Error

Post by BBauer »

You may simply change the CXX variable in the makefile to
CXX = g++

kind regards
Bernhard
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Stockfish-1.2 compile on Ubuntu - Error

Post by mcostalba »

ilari wrote:
royb wrote:Sorry, I don't code in C or C++ or C# -- what file is :

#include <string>

needed in now?

I tried adding it to position.h but that did not work
It's <cstring>, not <string>. You should put it in position.cpp.

Obviously the developer of Stockfish should have done it, but I guess he didn't test it in Linux.
Very sorry for the compile error!

Actually I have tested on Linux (but on Mandriva).

Ubuntu gave problems also with previous version. I tought I have fixed up all the reported errors because I had no more feedback from the tester...but it seems one include was still missing.

I would REALLY apreciate if someone can confirm me that with the added include now Stockfish compile fine under Ubuntu...finally!

Thanks again and sorry for this.
Marco
royb
Posts: 566
Joined: Thu Mar 09, 2006 12:53 am

Re: Stockfish-1.2 compile on Ubuntu - Error

Post by royb »

mcostalba wrote:
ilari wrote:
royb wrote:Sorry, I don't code in C or C++ or C# -- what file is :

#include <string>

needed in now?

I tried adding it to position.h but that did not work
It's <cstring>, not <string>. You should put it in position.cpp.

Obviously the developer of Stockfish should have done it, but I guess he didn't test it in Linux.
Very sorry for the compile error!

Actually I have tested on Linux (but on Mandriva).

Ubuntu gave problems also with previous version. I tought I have fixed up all the reported errors because I had no more feedback from the tester...but it seems one include was still missing.

I would REALLY apreciate if someone can confirm me that with the added include now Stockfish compile fine under Ubuntu...finally!

Thanks again and sorry for this.

Marco
I can confirm that with the changes recommended in this thread (adding #include <cstring> to both pawns.h and position.cpp) that the code compiled cleanly under Ubuntu 8.10 (both 32-bit and 64-bit).

Thanks for making Stockfish available to us!

Roy