Using gcc/g++ instrument functions with MinGW? - c++

i try to use the gcc instrument functions with g++ compiler of MinGW, but i
always got linker issues. Is it possible to use the instrument functions with
MinGW/MSYS?
The linker failure output:
$ g++ instrumentFunctions.cpp -o iftest -finstrument-functions >> iflog.txt
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x4e): undefined reference to `__cyg_prof
ile_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x158): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x179): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x18c): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x1a7): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x1bf): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x1db): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x1f3): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x22f): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x27a): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x29b): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x2e4): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x2ff): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x326): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x341): undefined reference to `__cyg_pro
file_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x368): undefined reference to `__cyg_pro
file_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text$printf[_printf]+0x16): undefined referenc
e to `__cyg_profile_func_enter'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text$printf[_printf]+0x43): undefined referenc
e to `__cyg_profile_func_exit'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text$_ZSt3minIjERKT_S2_S2_[unsigned int const&
std::min<unsigned int>(unsigned int const&, unsigned int const&)]+0x15): undefined reference to `__cyg_profile_func_ent
er'
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text$_ZSt3minIjERKT_S2_S2_[unsigned int const&
std::min<unsigned int>(unsigned int const&, unsigned int const&)]+0x42): undefined reference to `__cyg_profile_func_exi
t'
collect2: ld returned 1 exit status
g++ command i use:
g++ iftest.cpp -o iftest -finstruction-functions
Listing of my testsource:
#include <stdio.h>
void __cyg_profile_func_enter( void *, void * ) __attribute__ ((no_instrument_function));
void __cyg_profile_func_enter(void *func, void *callsite)
{
printf("%p\n", (int)func);
}
void func_c( void )
{
return;
}
void func_b( void )
{
func_c();
return;
}
void func_a( void )
{
func_b();
return;
}
int main()
{
func_a();
func_c();
}

You need to give the __cyg* functions "C" linkage. A function defined in C++ normally gets a mangled name which can't be used from libraries not written in C++. You can ask the compiler to give a function the name C would give it by using an `extern "C"{} block. The following should compile fine.
#include <stdio.h>
extern "C" {
void __cyg_profile_func_enter( void *, void * ) __attribute__ ((no_instrument_function));
void __cyg_profile_func_enter(void *func, void *callsite)
{
printf("enter %p\n", func);
}
void __cyg_profile_func_exit( void *, void * ) __attribute__ ((no_instrument_function));
void __cyg_profile_func_exit(void *func, void *callsite)
{
printf("exit %p\n", func);
}
}
void func_c( void )
{
return;
}
void func_b( void )
{
func_c();
return;
}
void func_a( void )
{
func_b();
return;
}
int main()
{
func_a();
func_c();
}

Related

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;
}

Undefined reference with JsonBox functions

I am trying to follow the penguin programmer text-based rpg guide (http://www.penguinprogrammer.co.uk/rpg-tutorial/introduction/). I am working on the item class and I am having some undefined reference errors with JsonBox functions.
#include "Item.hpp"
#include "Entity.hpp"
#include "JsonBox/include/JsonBox.h"
//#include "EntityManager.hpp"
Item::
Item(std::string _id, std::string _name, std::string _description)
: Entity(_id) {
this->SetName(_name);
this->SetDescription(_description);
}
Item::
Item(std::string _id, JsonBox::Value& _v, EntityManager* _mgr)
: Entity (_id) {
this->Load(_v, _mgr);
}
void
Item::
Load(JsonBox::Value& _v, EntityManager* _mgr) {
JsonBox::Object o = _v.getObject();
this->SetName(o["name"].getString());
this->SetDescription(o["description"].getString());
return;
}
Then I am compiling this main.
//#include "EntityManager.cpp"
#include "Item.cpp"
#include "JsonBox/include/JsonBox.h"
int main() {
return 0;
}
And getting this error
/tmp/cc1sZXwe.o: In function `Item::Load(JsonBox::Value&, EntityManager*)':
main.cpp:(.text+0x286): undefined reference to `JsonBox::Value::getObject() const'
main.cpp:(.text+0x2d4): undefined reference to `JsonBox::Value::getString() const'
main.cpp:(.text+0x35c): undefined reference to `JsonBox::Value::getString() const'
/tmp/cc1sZXwe.o: In function `std::pair<std::string const, JsonBox::Value>::~pair()':
main.cpp: (.text._ZNSt4pairIKSsN7JsonBox5ValueEED2Ev[_ZNSt4pairIKSsN7JsonBox5ValueEED5Ev]+ 0x18): undefined reference to `JsonBox::Value::~Value()'
/tmp/cc1sZXwe.o: In function `std::pair<std::string const, JsonBox::Value>::pair(std::pair<std::string const, JsonBox::Value> const&)':
main.cpp: (.text._ZNSt4pairIKSsN7JsonBox5ValueEEC2ERKS3_[_ZNSt4pairIKSsN7JsonBox5ValueEEC5 ERKS3_]+0x3b): undefined reference to `JsonBox::Value::Value(JsonBox::Value const&)'
/tmp/cc1sZXwe.o: In function `std::pair<std::string const, JsonBox::Value>::pair<std::string&&, 0ul>(std::tuple<std::string&&>&, std::tuple<>&, std::_Index_tuple<0ul>, std::_Index_tuple<>)':
main.cpp: (.text._ZNSt4pairIKSsN7JsonBox5ValueEEC2IIOSsEILm0EEIEIEEERSt5tupleIIDpT_EERS6_I IDpT1_EESt12_Index_tupleIIXspT0_EEESF_IIXspT2_EEE[_ZNSt4pairIKSsN7JsonBox5ValueE EC5IIOSsEILm0EEIEIEEERSt5tupleIIDpT_EERS6_IIDpT1_EESt12_Index_tupleIIXspT0_EEESF _IIXspT2_EEE]+0x47): undefined reference to `JsonBox::Value::Value()'
Inside your main you include Item.cpp source file, changing your main to this might help you:
//#include "EntityManager.cpp"
#include "Item.hpp"
#include "JsonBox/include/JsonBox.h"
int main() {
return 0;
}
Including source files is usually a bad practice, and can cause many problems, you can read more about Including .cpp files

Cannot get min_element to work in 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);

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.