the code is like this
#include <experimental/net>
#include <iostream>
#include <string>
#include <chrono>
namespace net = std::experimental::net;
using namespace std::chrono_literals;
int main()
{
std::cout << "networking ts stream example" << std::endl;
net::ip::tcp::iostream s;
s.expires_after(5s);
s.connect("ipecho.net", "http");
if(!s) {
std::cout << "error: " << s.error().message() << std::endl;
return -1;
}
s << "GET /plain HTTP/1.0\r\n";
s << "Host: ipecho.net\r\n";
s << "Accept: */*\r\n";
s << "Connection: close\r\n\r\n";
std::string header;
while(s && std::getline(s, header) && header != "\r")
std::cout << header << "\n";
std::cout << s.rdbuf();
std::cout << std::endl;
}
I have tried complier it by tdm-gcc 10 , fedora g++ (GCC) 11.2.1 and g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0.All of them failed,and the output are like this:
/usr/bin/ld: /tmp/ccUtsmxu.o: in function `std::experimental::net::v1::basic_socket_iostream<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >::basic_socket_iostream()':
a.cpp:(.text._ZNSt12experimental3net2v121basic_socket_iostreamINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEC1Ev[_ZNSt12experimental3net2v121basic_socket_iostreamINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEC1Ev]+0xd1): undefined reference to `std::experimental::net::v1::basic_socket_streambuf<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >::~basic_socket_streambuf()'
/usr/bin/ld: /tmp/ccUtsmxu.o: in function `void std::experimental::net::v1::basic_socket_iostream<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >::connect<char const (&) [10], char const (&) [5]>(char const (&) [10], char const (&) [5])':
a.cpp:(.text._ZNSt12experimental3net2v121basic_socket_iostreamINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEE7connectIJRA10_KcRA5_SC_EEEvDpOT_[_ZNSt12experimental3net2v121basic_socket_iostreamINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEE7connectIJRA10_KcRA5_SC_EEEvDpOT_]+0x4f): undefined reference to `std::experimental::net::v1::basic_socket_streambuf<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >* std::experimental::net::v1::basic_socket_streambuf<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >::connect<char const (&) [10], char const (&) [5]>(char const (&) [10], char const (&) [5])'
/usr/bin/ld: /tmp/ccUtsmxu.o: in function `std::experimental::net::v1::basic_socket_iostream<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >::~basic_socket_iostream()':
a.cpp:(.text._ZNSt12experimental3net2v121basic_socket_iostreamINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEED1Ev[_ZNSt12experimental3net2v121basic_socket_iostreamINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEED1Ev]+0x4d): undefined reference to `std::experimental::net::v1::basic_socket_streambuf<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >::~basic_socket_streambuf()'
/usr/bin/ld: /tmp/ccUtsmxu.o:(.data.rel.ro._ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE[_ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE]+0x10): undefined reference to `std::experimental::net::v1::basic_socket_streambuf<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >::~basic_socket_streambuf()'
/usr/bin/ld: /tmp/ccUtsmxu.o:(.data.rel.ro._ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE[_ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE]+0x18): undefined reference to `std::experimental::net::v1::basic_socket_streambuf<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >::~basic_socket_streambuf()'
/usr/bin/ld: /tmp/ccUtsmxu.o:(.data.rel.ro._ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE[_ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE]+0x28): undefined reference to `std::experimental::net::v1::basic_socket_streambuf<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >::setbuf(char*, long)'
/usr/bin/ld: /tmp/ccUtsmxu.o:(.data.rel.ro._ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE[_ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE]+0x40): undefined reference to `std::experimental::net::v1::basic_socket_streambuf<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >::sync()'
/usr/bin/ld: /tmp/ccUtsmxu.o:(.data.rel.ro._ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE[_ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE]+0x58): undefined reference to `std::experimental::net::v1::basic_socket_streambuf<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >::underflow()'
/usr/bin/ld: /tmp/ccUtsmxu.o:(.data.rel.ro._ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE[_ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE]+0x68): undefined reference to `std::experimental::net::v1::basic_socket_streambuf<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >::pbackfail(int)'
/usr/bin/ld: /tmp/ccUtsmxu.o:(.data.rel.ro._ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE[_ZTVNSt12experimental3net2v122basic_socket_streambufINS1_2ip3tcpENSt6chrono3_V212steady_clockENS1_11wait_traitsIS7_EEEE]+0x78): undefined reference to `std::experimental::net::v1::basic_socket_streambuf<std::experimental::net::v1::ip::tcp, std::chrono::_V2::steady_clock, std::experimental::net::v1::wait_traits<std::chrono::_V2::steady_clock> >::overflow(int)'
collect2: error: ld returned 1 exit status
what's wrong with them? My complier option is '-std=gnu++2a' or '-std=c++2a',both do not work.
I'm very new to C++. I am having some trouble with using a makefile to compile my C++ project. The project consists of: main.cpp, position.cpp, movegen.cpp, move.cpp and their respective headers. I am using Windows and mingw-64.
Here is the makefile I have written:
CXX = g++
CXXFLAGS = -Wall -g
all: main
main: main.o position.o movegen.o move.o
$(CXX) $(CXXFLAGS) -o main main.o position.o movegen.o move.o
main.o: main.cpp position.h movegen.h move.h
$(CXX) $(CXXFLAGS) -c main.cpp
position.o: position.cpp position.h move.h
$(CXX) $(CXXFLAGS) -c position.cpp
movegen.o: movegen.cpp movegen.h position.h move.h
$(CXX) $(CXXFLAGS) -c movegen.cpp
move.o: move.cpp move.h
$(CXX) $(CXXFLAGS) -c move.cpp
Here is a very messy dependency diagram, each file is dependent on the one with a line drawn below it downwards e.g. movegen depends on position and move headers.
When I try running the mingw-64_make.exe command in the directory of the project, all of the object files are created successfully, but main.exe is not.
This is the console output:
C:\Users\Hutch\pepegaengine>mingw32-make.exe
g++ -Wall -g -c main.cpp
main.cpp: In static member function 'static void TestEngine::displayBB(U64)':
main.cpp:22:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'unsigned int'} [-Wsign-compare]
for (int j = 0; j < eightBit.length(); j++) {
~~^~~~~~~~~~~~~~~~~~~
g++ -Wall -g -c position.cpp
position.cpp: In member function 'void Position::unmakeMove(cmove::Move)':
position.cpp:771:30: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
} else if (flags = capture) {
~~~~~~^~~~~~~~~
position.cpp:766:17: warning: unused variable 'toPiece' [-Wunused-variable]
int toPiece = move.getToPiece();
^~~~~~~
g++ -Wall -g -c movegen.cpp
movegen.cpp: In function 'cmove::Move* cmovegen::legalMoveGenerator(cposition::Position&, cposition::enumColour, cmove::Move*)':
movegen.cpp:9:13: warning: unused variable 'enemyPawns' [-Wunused-variable]
U64 enemyPawns = pos.getPieceSet(blackPawns - colourMove);
^~~~~~~~~~
g++ -Wall -g -c move.cpp
g++ -Wall -g -o main main.o position.o movegen.o move.o
main.o: In function `main':
C:\Users\Hutch\pepegaengine/main.cpp:34: undefined reference to `cposition::Position::Position(unsigned long long*)'
C:\Users\Hutch\pepegaengine/main.cpp:35: undefined reference to `cposition::Position::initializeStartPosition()'
C:\Users\Hutch\pepegaengine/main.cpp:39: undefined reference to `cposition::Position::getEmptyBB()'
C:\Users\Hutch\pepegaengine/main.cpp:42: undefined reference to `cposition::Position::getOccupiedBB()'
C:\Users\Hutch\pepegaengine/main.cpp:108: undefined reference to `cmove::Move::Move()'
C:\Users\Hutch\pepegaengine/main.cpp:109: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/main.cpp:110: undefined reference to `cposition::Position::makeMove(cmove::Move)'
C:\Users\Hutch\pepegaengine/main.cpp:112: undefined reference to `cmovegen::legalMoveGenerator(cposition::enumColour, cmove::Move*)'
C:\Users\Hutch\pepegaengine/main.cpp:115: undefined reference to `cmove::Move::getFrom()'
C:\Users\Hutch\pepegaengine/main.cpp:116: undefined reference to `cmove::Move::getTo()'
C:\Users\Hutch\pepegaengine/main.cpp:121: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/main.cpp:122: undefined reference to `cposition::Position::makeMove(cmove::Move)'
C:\Users\Hutch\pepegaengine/main.cpp:124: undefined reference to `cmovegen::legalMoveGenerator(cposition::enumColour, cmove::Move*)'
C:\Users\Hutch\pepegaengine/main.cpp:127: undefined reference to `cmove::Move::getFrom()'
C:\Users\Hutch\pepegaengine/main.cpp:128: undefined reference to `cmove::Move::getTo()'
movegen.o: In function `ZN8cmovegen18legalMoveGeneratorERN9cposition8PositionENS0_10enumColourEPN5cmove4MoveE':
C:\Users\Hutch\pepegaengine/movegen.cpp:8: undefined reference to `cposition::Position::getPieceSet(int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:9: undefined reference to `cposition::Position::getPieceSet(int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:22: undefined reference to `cposition::Position::getEmptyBB()'
C:\Users\Hutch\pepegaengine/movegen.cpp:22: undefined reference to `cposition::Position::singlePushTargets(unsigned long long, unsigned long long, cposition::enumColour)'
C:\Users\Hutch\pepegaengine/movegen.cpp:23: undefined reference to `cposition::Position::getEmptyBB()'
C:\Users\Hutch\pepegaengine/movegen.cpp:23: undefined reference to `cposition::Position::doublePushTargets(unsigned long long, unsigned long long, cposition::enumColour)'
C:\Users\Hutch\pepegaengine/movegen.cpp:24: undefined reference to `cposition::Position::pawnCaptures(unsigned long long, cposition::enumColour)'
C:\Users\Hutch\pepegaengine/movegen.cpp:25: undefined reference to `cposition::Position::pawnAllAttacks(unsigned long long, cposition::enumColour)'
C:\Users\Hutch\pepegaengine/movegen.cpp:25: undefined reference to `cposition::Position::getEnPassantTarget()'
C:\Users\Hutch\pepegaengine/movegen.cpp:28: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:47: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:48: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:49: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:50: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
movegen.o:C:\Users\Hutch\pepegaengine/movegen.cpp:56: more undefined references to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)' follow
movegen.o: In function `ZN8cmovegen18legalMoveGeneratorERN9cposition8PositionENS0_10enumColourEPN5cmove4MoveE':
C:\Users\Hutch\pepegaengine/movegen.cpp:72: undefined reference to `cposition::Position::pieceOnSquare(unsigned long long)'
C:\Users\Hutch\pepegaengine/movegen.cpp:76: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:77: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:78: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:79: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:85: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:95: undefined reference to `cposition::Position::getPieceSet(int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:102: undefined reference to `cposition::Position::getOccupiedBB()'
C:\Users\Hutch\pepegaengine/movegen.cpp:102: undefined reference to `cposition::Position::rookCaptures(unsigned long long, int, cposition::enumColour)'
C:\Users\Hutch\pepegaengine/movegen.cpp:103: undefined reference to `cposition::Position::getOccupiedBB()'
C:\Users\Hutch\pepegaengine/movegen.cpp:103: undefined reference to `cposition::Position::rookQuietMoves(unsigned long long, int, cposition::enumColour)'
C:\Users\Hutch\pepegaengine/movegen.cpp:108: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:114: undefined reference to `cposition::Position::pieceOnSquare(unsigned long long)'
C:\Users\Hutch\pepegaengine/movegen.cpp:114: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:121: undefined reference to `cposition::Position::getPieceSet(int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:126: undefined reference to `cposition::Position::getOccupiedBB()'
C:\Users\Hutch\pepegaengine/movegen.cpp:126: undefined reference to `cposition::Position::queenCaptures(unsigned long long, int, cposition::enumColour)'
C:\Users\Hutch\pepegaengine/movegen.cpp:127: undefined reference to `cposition::Position::getOccupiedBB()'
C:\Users\Hutch\pepegaengine/movegen.cpp:127: undefined reference to `cposition::Position::queenQuietMoves(unsigned long long, int, cposition::enumColour)'
C:\Users\Hutch\pepegaengine/movegen.cpp:130: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:136: undefined reference to `cposition::Position::pieceOnSquare(unsigned long long)'
C:\Users\Hutch\pepegaengine/movegen.cpp:136: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:144: undefined reference to `cposition::Position::getPieceSet(int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:149: undefined reference to `cposition::Position::getOccupiedBB()'
C:\Users\Hutch\pepegaengine/movegen.cpp:149: undefined reference to `cposition::Position::bishopCaptures(unsigned long long, int, cposition::enumColour)'
C:\Users\Hutch\pepegaengine/movegen.cpp:150: undefined reference to `cposition::Position::getOccupiedBB()'
C:\Users\Hutch\pepegaengine/movegen.cpp:150: undefined reference to `cposition::Position::bishopQuietMoves(unsigned long long, int, cposition::enumColour)'
C:\Users\Hutch\pepegaengine/movegen.cpp:153: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:159: undefined reference to `cposition::Position::pieceOnSquare(unsigned long long)'
C:\Users\Hutch\pepegaengine/movegen.cpp:159: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:167: undefined reference to `cposition::Position::getPieceSet(int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:173: undefined reference to `cposition::Position::singleKnightQuietMoves(int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:174: undefined reference to `cposition::Position::singleKnightCaptures(int, cposition::enumColour)'
C:\Users\Hutch\pepegaengine/movegen.cpp:177: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:183: undefined reference to `cposition::Position::pieceOnSquare(unsigned long long)'
C:\Users\Hutch\pepegaengine/movegen.cpp:183: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:191: undefined reference to `cposition::Position::getPieceSet(int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:192: undefined reference to `cposition::Position::kingQuietMoves(unsigned long long)'
C:\Users\Hutch\pepegaengine/movegen.cpp:193: undefined reference to `cposition::Position::kingCaptures(unsigned long long, cposition::enumColour)'
C:\Users\Hutch\pepegaengine/movegen.cpp:196: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:197: undefined reference to `cposition::Position::getOccupiedBB()'
C:\Users\Hutch\pepegaengine/movegen.cpp:197: undefined reference to `cposition::Position::isAttackedSquare(unsigned long long, int, int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:205: undefined reference to `cposition::Position::pieceOnSquare(unsigned long long)'
C:\Users\Hutch\pepegaengine/movegen.cpp:205: undefined reference to `cmove::Move::Move(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
C:\Users\Hutch\pepegaengine/movegen.cpp:206: undefined reference to `cposition::Position::getOccupiedBB()'
C:\Users\Hutch\pepegaengine/movegen.cpp:206: undefined reference to `cposition::Position::isAttackedSquare(unsigned long long, int, int)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe: *** [makefile:12: main] Error 1
main.cpp:
#include <iostream>
#include <iostream>
#include <bitset>
#include "position.h"
#include "movegen.h"
#include "move.h"
using namespace cmove;
using namespace cposition;
using namespace cmovegen;
using namespace std;
int main() {
U64 pieceBB[14];
Position pos(pieceBB);
pos.initializeStartPosition();
cout << "empty: " << endl;
TestEngine::displayBB(pos.getEmptyBB());
cout << "occupied: " << endl;
TestEngine::displayBB(pos.getOccupiedBB());
Move moves[150];
Move d4(11,27, quietMove, whitePawns, 0);
pos.makeMove(d4);
legalMoveGenerator(white, moves);
...
position.cpp:
#include<string>
#include "position.h"
#define C64(constantU64) constantU64##ULL
typedef unsigned long long U64;
using namespace std;
using namespace cmove;
using namespace cposition;
class Position {
U64 pieceBB[14];
U64 emptyBB;
U64 occupiedBB;
U64 enPassantTarget;
bool castleRights[4];
U64 arrPawnAttacks[2][64];
U64 arrKnightAttacks[64];
U64 arrKingAttacks[64];
public:
U64 getEmptyBB() {
return emptyBB;
}
U64 getOccupiedBB() {
return occupiedBB;
}
U64 getPieceSet(int piece) {
return pieceBB[piece];
}
...
position.h:
#ifndef POSITION
#define POSITION
#define C64(constantU64) constantU64##ULL
typedef unsigned long long U64;
#include "move.h"
namespace cposition {
typedef unsigned long long U64;
enum enumPiece {
whitePieces,
blackPieces,
whitePawns,
blackPawns,
whiteRooks,
blackRooks,
whiteKnights,
blackKnights,
whiteBishops,
blackBishops,
whiteQueens,
blackQueens,
whiteKing,
blackKing,
};
enum enumSquare {
a1, b1, c1, d1, e1, f1, g1, h1,
a2, b2, c2, d2, e2, f2, g2, h2,
a3, b3, c3, d3, e3, f3, g3, h3,
a4, b4, c4, d4, e4, f4, g4, h4,
a5, b5, c5, d5, e5, f5, g5, h5,
a6, b6, c6, d6, e6, f6, g6, h6,
a7, b7, c7, d7, e7, f7, g7, h7,
a8, b8, c8, d8, e8, f8, g8, h8
};
enum enumDirection {
n,
ne,
e,
se,
s,
sw,
w,
nw
};
enum enumColour {
white,
black
};
enum enumFlag {
quietMove,
doublePawnPush,
kingCastle,
queenCastle,
capture,
epCapture,
knightPromotion,
bishopPromotion,
rookPromotion,
queenPromotion,
knightPromoCapture,
bishopPromoCapture,
rookPromoCapture,
queenPromoCapture
};
enum enumCastleRights {
whiteKingsideCastleRights,
blackKingsideCastleRights,
whiteQueensideCastleRights,
blackQueensideCastleRights
};
class Position {
U64 pieceBB[14];
U64 emptyBB;
U64 occupiedBB;
U64 enPassantTarget;
bool castleRights[4];
U64 arrPawnAttacks[2][64];
U64 arrKnightAttacks[64];
U64 arrKingAttacks[64];
public:
U64 getEmptyBB();
U64 getOccupiedBB();
U64 getPieceSet(int piece);
U64 getEnPassantTarget();
...
movegen.cpp:
#include <math.h>
#include "movegen.h"
using namespace cmove;
using namespace cposition;
namespace cmovegen {
cmove::Move * legalMoveGenerator(Position& pos, enumColour colourMove, Move * moves) {
U64 pawns = pos.getPieceSet(whitePawns + colourMove);
U64 enemyPawns = pos.getPieceSet(blackPawns - colourMove);
U64 pawnPush = 0;
U64 pawnDoublePush = 0;
U64 pawnCap = 0;
U64 pawnEP = 0;
//TestEngine::displayBB(pawns);
//TestEngine::displayBB(enemyPawns);
while (pawns) {
U64 currentPawn = pawns & -pawns;
pawnPush = pos.singlePushTargets(currentPawn, pos.getEmptyBB(), colourMove);
pawnDoublePush = pos.doublePushTargets(currentPawn, pos.getEmptyBB(), colourMove);
pawnCap = pos.pawnCaptures(currentPawn, colourMove);
pawnEP = pos.pawnAllAttacks(currentPawn, colourMove) & pos.getEnPassantTarget();
if (pawnEP) {
Move newMove (log2(currentPawn), log2(pawnEP), epCapture, (whitePawns + colourMove), (blackPawns - colourMove));
*moves++ = newMove;
}
...
movegen.h:
#ifndef MOVEGEN
#define MOVEGEN
#include "position.h"
namespace cmovegen {
cmove::Move * legalMoveGenerator(cposition::enumColour colourMove, cmove::Move * moves);
}
#endif
move.cpp:
#include "move.h"
using namespace cmove;
class Move {
unsigned int move24 = 0;
public:
Move() {
move24 = 0;
}
Move(unsigned int from, unsigned int to, unsigned int flags, unsigned int fromPiece, unsigned int toPiece) {
move24 = ((flags & 0xf) << 20) | ((from & 0x3f) << 14) | ((to & 0x3f) << 8) | ((fromPiece & 0xf) << 4) | (toPiece & 0xf);
}
unsigned int getFrom() {
return (move24 >> 14) & 0x3f;
}
unsigned int getTo() {
return (move24 >> 8) & 0x3f;
}
unsigned int getFlags() {
return (move24 >> 20) & 0xf;
}
unsigned int getFromPiece() {
return (move24 >> 4) & 0xf;
}
unsigned int getToPiece() {
return move24 & 0xf;
}
void setFrom(unsigned int from) {
move24 &= 0xf03fff;
move24 |= ((from & 0x3f) << 14);
}
void setTo(unsigned int to) {
move24 &= 0xffc0ff;
move24 |= ((to & 0x3f) << 8);
}
void setFlags(unsigned int flags) {
move24 &= 0x0fffff;
move24 |= ((flags & 0xf) << 20);
}
void setFromPiece(unsigned int fromPiece) {
move24 &= 0xffff0f;
move24 |= ((fromPiece & 0xf) << 4);
}
void setToPiece(unsigned int toPiece) {
move24 &= 0xfffff0;
move24 |= (toPiece & 0xf);
}
};
move.h:
#ifndef MOVE
#define MOVE
namespace cmove {
class Move {
unsigned int move24;
public:
Move();
Move(unsigned int from, unsigned int to, unsigned int flags, unsigned int fromPiece, unsigned int toPiece);
unsigned int getFrom();
unsigned int getTo();
unsigned int getFlags();
unsigned int getFromPiece();
unsigned int getToPiece();
void setFrom(unsigned int from);
void setTo(unsigned int to);
void setFlags(unsigned int flags);
void setFromPiece(unsigned int fromPiece);
void setToPiece(unsigned int toPiece);
};
}
#endif
I'va installed cppunit library on my kubuntu 11.10, using this command:
sudo apt-get install libcppunit-1.12-1 libcppunit-dev libcppunit-doc
sudo apt-get install libcppunit-subunit-dev libcppunit-subunit0
before this i run the: apt-cache search cppunit command, as a result:
libcppunit-1.12-1 - Unit Testing Library for C++
libcppunit-dev - Unit Testing Library for C++
libcppunit-doc - Unit Testing Library for C++
libcppunit-subunit-dev - SubunitTestProgressListener for CPPUnit - Development headers
libcppunit-subunit0 - SubunitTestProgressListener for CPPUnit - C++ shared library
libcunit1 - Unit Testing Library for C
libcunit1-dev - Unit Testing Library for C -- development files
libcunit1-doc - Unit Testing Library for C -- documentation
libcunit1-ncurses - Unit Testing Library for C (ncurses)
libcunit1-ncurses-dev - Unit Testing Library for C (ncurses) -- development files
libqxcppunit-dev - A Qt4-based GUI for running tests with CppUnit - development files
libqxcppunitd1 - A Qt4-based GUI for running tests with CppUnit
I've got a simple source file for studying unit-testing:
#include <iostream>
#include <cppunit/TestCase.h>
#include <cppunit/extensions/HelperMacros.h>
class MyDate
{
private:
struct Duration
{
int year;
int month;
int day;
Duration( int y, int m, int d ) :
year( y ), month( m ), day( d )
{}
} mdata;
public:
MyDate() : mdata( 2011, 11, 15 )
{}
MyDate( int year, int month, int day ) : mdata( year, month, day )
{}
int getYear() const
{ return mdata.year; }
int getMonth() const
{ return mdata.month; }
int getDay() const
{ return mdata.day; }
friend bool operator < ( MyDate const& lhs, MyDate const& rhs )
{
if ( lhs.mdata.year > rhs.mdata.year )
return false;
else if ( lhs.mdata.year < rhs.mdata.year )
return true;
else if ( lhs.mdata.year == rhs.mdata.year )
{
if ( lhs.mdata.month > rhs.mdata.month )
return false;
else if ( lhs.mdata.month < rhs.mdata.month )
return true;
else if ( lhs.mdata.month == rhs.mdata.month )
{
if ( lhs.mdata.day < rhs.mdata.day )
return true;
else
return false;
}
}
return false;
}
};
class MyDateTest : public CppUnit::TestCase
{
MyDate mybday;
MyDate today;
public:
MyDateTest() : mybday( 1951, 10, 1 ) {}
void run()
{
testOps();
}
void testOps()
{
CPPUNIT_ASSERT( mybday < today );
}
};
int main()
{
MyDateTest test;
test.run();
return 0;
}
but when i compile my cpp file, using g++, i have the following errors:
$ g++ -Wall -pedantic date_module_test.cpp -o date_module_test
/tmp/ccLgvOFj.o: In function `MyDateTest::MyDateTest()':
date_module_test.cpp:(.text._ZN10MyDateTestC2Ev[_ZN10MyDateTestC5Ev]+0xd): undefined reference to `CppUnit::TestCase::TestCase()'
/tmp/ccLgvOFj.o: In function `MyDateTest::~MyDateTest()':
date_module_test.cpp:(.text._ZN10MyDateTestD2Ev[_ZN10MyDateTestD5Ev]+0x20): undefined reference to `CppUnit::TestCase::~TestCase()'
/tmp/ccLgvOFj.o:(.rodata._ZTV10MyDateTest[vtable for MyDateTest]+0x10): undefined reference to `CppUnit::TestCase::run(CppUnit::TestResult*)'
/tmp/ccLgvOFj.o:(.rodata._ZTV10MyDateTest[vtable for MyDateTest]+0x14): undefined reference to `CppUnit::TestLeaf::countTestCases() const'
/tmp/ccLgvOFj.o:(.rodata._ZTV10MyDateTest[vtable for MyDateTest]+0x18): undefined reference to `CppUnit::TestLeaf::getChildTestCount() const'
/tmp/ccLgvOFj.o:(.rodata._ZTV10MyDateTest[vtable for MyDateTest]+0x1c): undefined reference to `CppUnit::Test::getChildTestAt(int) const'
/tmp/ccLgvOFj.o:(.rodata._ZTV10MyDateTest[vtable for MyDateTest]+0x20): undefined reference to `CppUnit::TestCase::getName() const'
/tmp/ccLgvOFj.o:(.rodata._ZTV10MyDateTest[vtable for MyDateTest]+0x24): undefined reference to `CppUnit::Test::findTestPath(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, CppUnit::TestPath&) const'
/tmp/ccLgvOFj.o:(.rodata._ZTV10MyDateTest[vtable for MyDateTest]+0x28): undefined reference to `CppUnit::Test::findTestPath(CppUnit::Test const*, CppUnit::TestPath&) const'
/tmp/ccLgvOFj.o:(.rodata._ZTV10MyDateTest[vtable for MyDateTest]+0x2c): undefined reference to `CppUnit::Test::findTest(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/tmp/ccLgvOFj.o:(.rodata._ZTV10MyDateTest[vtable for MyDateTest]+0x30): undefined reference to `CppUnit::Test::resolveTestPath(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
/tmp/ccLgvOFj.o:(.rodata._ZTV10MyDateTest[vtable for MyDateTest]+0x34): undefined reference to `CppUnit::Test::checkIsValidIndex(int) const'
/tmp/ccLgvOFj.o:(.rodata._ZTV10MyDateTest[vtable for MyDateTest]+0x38): undefined reference to `CppUnit::TestLeaf::doGetChildTestAt(int) const'
/tmp/ccLgvOFj.o:(.rodata._ZTV10MyDateTest[vtable for MyDateTest]+0x3c): undefined reference to `CppUnit::TestCase::runTest()'
/tmp/ccLgvOFj.o:(.rodata._ZTI10MyDateTest[typeinfo for MyDateTest]+0x8): undefined reference to `typeinfo for CppUnit::TestCase'
collect2: ld returned 1 exit status
What's the problem ?
You have to instruct g++ to link against the correct CPPUnit static library.