Cannot get min_element to work in C++ - c++

I'm writing a small recursive algorithm. Here is the code:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> coins;
int checkchange(int left) {
vector<int> choices (coins.size());
if (left == 0)
return 0;
else {
int min;
for (int i=0;i<coins.size();i++) {
choices.at(i) = (1 + checkchange(left - coins.at(i)));
}
return min_element(choices.front(),choices.back());
}
}
int main() {
int N;
cin >> N;
for (int i=0;i<N;i++) {
int c,m,temp,change;
cin >> c >> m;
for (int j=0;j<c;j++) {
cin >> temp;
coins.push_back(temp);
}
for (int j=0;j<m;j++) {
cin >> temp;
change = checkchange(temp);
cout << change;
}
}
return 0;
}
I get the following error:
In file included from
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/algorithm:62,
from burningcoins.cpp:3: /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algo.h:
In function ‘_FIter std::min_element(_FIter, _FIter) [with _FIter =
int]’: burningcoins.cpp:19: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algo.h:5998:
error: invalid type argument of ‘unary *’
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algo.h:5998:
error: invalid type argument of ‘unary *’
I've tried compiling with both g++ and gcc, both give me the same error. What am I doing wrong?
Edit:
New Code:
int checkchange(int left) {
vector<int> choices (coins.size());
if (left == 0)
return 0;
else {
for (int i=0;i<coins.size();i++) {
choices[i] = (1 + checkchange(left - coins.at(i)));
}
return *min_element(choices.begin(), choices.end());
}
}
New error message:
/tmp/ccV3VLsK.o: In function main': <br/>
burningcoins.cpp:(.text+0x16a): undefined reference tostd::cin'
burningcoins.cpp:(.text+0x16f): undefined reference to std::basic_istream<char, std::char_traits<char> >::operator>>(int&)' <br/>
burningcoins.cpp:(.text+0x187): undefined reference tostd::cin'
burningcoins.cpp:(.text+0x18c): undefined reference to std::basic_istream<char, std::char_traits<char> >::operator>>(int&)' <br/>
burningcoins.cpp:(.text+0x19b): undefined reference tostd::basic_istream >::operator>>(int&)'
burningcoins.cpp:(.text+0x1b0): undefined reference to std::cin' <br/>
burningcoins.cpp:(.text+0x1b5): undefined reference tostd::basic_istream >::operator>>(int&)'
burningcoins.cpp:(.text+0x1ec): undefined reference to std::cin' <br/>
burningcoins.cpp:(.text+0x1f1): undefined reference tostd::basic_istream >::operator>>(int&)'
burningcoins.cpp:(.text+0x208): undefined reference to std::cout' <br/>
burningcoins.cpp:(.text+0x20d): undefined reference tostd::basic_ostream >::operator<<(int)'
/tmp/ccV3VLsK.o: In function __static_initialization_and_destruction_0(int, int)': <br/>
burningcoins.cpp:(.text+0x261): undefined reference tostd::ios_base::Init::Init()'
burningcoins.cpp:(.text+0x266): undefined reference to std::ios_base::Init::~Init()' <br/>
/tmp/ccV3VLsK.o: In functionstd::vector >::_M_range_check(unsigned long) const':
burningcoins.cpp:(.text._ZNKSt6vectorIiSaIiEE14_M_range_checkEm[std::vector >::_M_range_check(unsigned long) const]+0x2d): undefined reference to std::__throw_out_of_range(char const*)' <br/>
/tmp/ccV3VLsK.o: In functionstd::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, int const&)':
burningcoins.cpp:(.text._ZNSt6vectorIiSaIiEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPiS1_EERKi[std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, int const&)]+0x259): undefined reference to __cxa_begin_catch' <br/>
burningcoins.cpp:(.text._ZNSt6vectorIiSaIiEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPiS1_EERKi[std::vector<int, std::allocator<int> >::_M_insert_aux(__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, int const&)]+0x2be): undefined reference to__cxa_rethrow'
burningcoins.cpp:(.text._ZNSt6vectorIiSaIiEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPiS1_EERKi[std::vector >::_M_insert_aux(__gnu_cxx::__normal_iterator > >, int const&)]+0x2c8): undefined reference to __cxa_end_catch' <br/>
/tmp/ccV3VLsK.o: In functionstd::vector >::_M_check_len(unsigned long, char const*) const':
burningcoins.cpp:(.text._ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc[std::vector >::_M_check_len(unsigned long, char const*) const]+0x4c): undefined reference to std::__throw_length_error(char const*)' <br/>
/tmp/ccV3VLsK.o: In function__gnu_cxx::new_allocator::deallocate(int*, unsigned long)':
burningcoins.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE10deallocateEPim[__gnu_cxx::new_allocator::deallocate(int*, unsigned long)]+0x1c): undefined reference to operator delete(void*)' <br/>
/tmp/ccV3VLsK.o: In function__gnu_cxx::new_allocator::allocate(unsigned long, void const*)':
burningcoins.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE8allocateEmPKv[__gnu_cxx::new_allocator::allocate(unsigned long, void const*)]+0x35): undefined reference to std::__throw_bad_alloc()' <br/>
burningcoins.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE8allocateEmPKv[__gnu_cxx::new_allocator<int>::allocate(unsigned long, void const*)]+0x45): undefined reference tooperator new(unsigned long)'
/tmp/ccV3VLsK.o:(.eh_frame+0x12): undefined reference to __gxx_personality_v0' <br/>
/tmp/ccV3VLsK.o:(.eh_frame+0x4f): undefined reference to__gxx_personality_v0'
collect2: ld returned 1 exit status

std::min_element takes a range. front and back return references to actual values. You should be using the begin and end methods to return an iterator to the corresponding positions in the vector:
min_element(choices.begin(), choices.end());
// ^^^^^ ^^^
If you find this tedious, you can create a function which wraps around the standard min_element:
template <class Container>
auto min_element(Container c) -> decltype(std::min_element(c.begin(), c.end()))
{
return std::min_element(c.begin(), c.end());
}
And use it as:
min_element(choices);

Related

undefined reference to std::experimental::net

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.

Issues with Makefile C++ using mingw-32

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

C++ template construction for class member lists

So I have made a little bit of C++ templates before: some quite basic examples of the curiously recurring template pattern for classes of mathematical numbers. This time I tried using the same pattern to create a list or "network" for objects of a class which they could add themselves to and look around for other objects. I thought I could use a static std::list to do this. So my attempt goes like this:
template<class C> class HasNetwork{
public:
HasNetwork(){}
static list<C*> m;
};
template<class C> list<C*> HasNetwork<C>::m = list<C*>();
class IHaveNetwork: public HasNetwork<IHaveNetwork>{
public:
IHaveNetwork(){ m.push_back(this); }
};
int main(){
IHaveNetwork lHF, lHF2;
//for(list<IHaveNetwork*>::iterator it = lHF.m->begin(); ; it++);
return 0;
}
It seems to compile, but I get nasty link errors ( even with the for loop iterator commented out ). Maybe I need to do some cast or maybe "this" is not defined until after the constructor finishes?
Here is the link error:
/tmp/templatest-912860.o: In function `__clang_call_terminate':
templatest.cpp:
(.text.__clang_call_terminate[__clang_call_terminate]+0x9): undefined reference to `__cxa_begin_catch'
templatest.cpp:(.text.__clang_call_terminate[__clang_call_terminate]+0x12): undefined reference to `std::terminate()'
/tmp/templatest-912860.o: In function `__gnu_cxx::new_allocator<std::_List_node<IHaveNetwork*>
>::deallocate(std::_List_node<IHaveNetwork*>*, unsigned long)':
templatest.cpp:
(.text._ZN9__gnu_cxx13new_allocatorISt10_List_nodeIP12IHaveNetworkEE10deallocateEPS4_m[_ZN9__gnu_cxx13new_allocatorISt10_List_nodeIP12IHaveNetworkEE10deallocateEPS4_m]+0x1c): undefined reference to `operator delete(void*)'
/tmp/templatest-912860.o: In function `std::list<IHaveNetwork*, std::allocator<IHaveNetwork*>
>::_M_insert(std::_List_iterator<IHaveNetwork*>, IHaveNetwork* const&)':
templatest.cpp:
(.text._ZNSt4listIP12IHaveNetworkSaIS1_EE9_M_insertESt14_List_iteratorIS1_ERKS1_[_ZNSt4listIP12IHaveNetworkSaIS1_EE9_M_insertESt14_List_iteratorIS1_ERKS1_]+0x31): undefined reference to
`std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
/tmp/templatest-912860.o: In function `std::list >::_M_create_node(IHaveNetwork* const&)':
templatest.cpp:
(.text._ZNSt4listIP12IHaveNetworkSaIS1_EE14_M_create_nodeERKS1_[_ZNSt4listIP12IHaveNetworkSaIS1_EE14_M_create_nodeERKS1_]+0xa0): undefined reference to `__cxa_begin_catch'
templatest.cpp:(.text._ZNSt4listIP12IHaveNetworkSaIS1_EE14_M_create_nodeERKS1_[_ZNSt4listIP12IHaveNetworkSaIS1_EE14_M_create_nodeERKS1_]+0xbb): undefined reference to `__cxa_rethrow'
templatest.cpp:
(.text._ZNSt4listIP12IHaveNetworkSaIS1_EE14_M_create_nodeERKS1_[_ZNSt4listIP12IHaveNetworkSaIS1_EE14_M_create_nodeERKS1_]+0xce): undefined reference to `__cxa_end_catch'
/tmp/templatest-912860.o: In function `__gnu_cxx::new_allocator<std::_List_node<IHaveNetwork*> >::allocate(unsigned long, void const*)':
templatest.cpp:(.text._ZN9__gnu_cxx13new_allocatorISt10_List_nodeIP12IHaveNetworkEE8allocateEmPKv[_ZN9__gnu_cxx13new_allocatorISt10_List_nodeIP12IHaveNetworkEE8allocateEmPKv]+0x33): undefined reference to `std::__throw_bad_alloc()'
templatest.cpp:(.text._ZN9__gnu_cxx13new_allocatorISt10_List_nodeIP12IHaveNetworkEE8allocateEmPKv[_ZN9__gnu_cxx13new_allocatorISt10_List_nodeIP12IHaveNetworkEE8allocateEmPKv]+0x40): undefined reference to `operator new(unsigned long)'
/tmp/templatest-912860.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
I cannot reproduce.
Here is a slightly modified version of you code that compiles links and runs without even a warning (I only had to fix some indirection level errors):
#include <iostream>
#include <list>
#include <string>
template<class C> class HasNetwork{
public:
HasNetwork(){}
static std::list<C*> m;
};
template<class C> std::list<C*> HasNetwork<C>::m = std::list<C*>();
class IHaveNetwork: public HasNetwork<IHaveNetwork>{
std::string name;
public:
IHaveNetwork(const std::string &name): name(name) { m.push_back(this); }
std::string getName() const {
return name;
}
};
int main(){
IHaveNetwork lHF("foo"), lHF2("bar");
for(std::list<IHaveNetwork*>::iterator it = lHF.m.begin(); it != lHF.m.end(); it++) {
std::cout << (*it)->getName() << std::endl;
}
return 0;
}

function invoking undefined reference

hi every one I have this class with those headers
class WuManber
{
public:
WuManber( void );
virtual ~WuManber( void );
void Initialize( const vector<const char *> &patterns,
bool bCaseSensitive = false, bool bIncludeSpecialCharacters = false, bool bIncludeExtendedAscii = false );
when I try try to create an instance of WuManber and invoke Initialize I get the following error:
/tmp/ccx19Os5.o: In function main': Test.cpp:(.text+0x8d): undefined
reference toWuManber::WuManber()' Test.cpp:(.text+0xbc): undefined
reference to WuManber::Initialize(std::vector<char const*,
std::allocator<char const*> > const&, bool, bool, bool)'
Test.cpp:(.text+0xc8): undefined reference toWuManber::~WuManber()'
Test.cpp:(.text+0x115): undefined reference to `WuManber::~WuManber()'
collect2: ld returned 1 exit status
int main(int argc, char* argv[])
{
Parser CustomParserEx;
CustomParserEx.open("/home/abdullah/Project IDS/rules");
WuManber WmAlgorithm;
WmAlgorithm.Initialize(CustomParserEx.patterns,true,true,true);
}
so any hints of what I am doing wrong
You didn't implement the three methods of WuManber, or you didn't include the implementations where the linker can find them.

Error with compile source file, which used cppunit classes

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.