Boost logo

Boost Users :

Subject: [Boost-users] undefined reference to member function in AUTO_TEST_CASE
From: Moritz Beber (moritz.beber_at_[hidden])
Date: 2010-06-17 10:33:15


Dear all,

I have a peculiar problem when compiling my unit tests. The reason why I
find it peculiar is that I can compile the same code in a normal
function just fine. Here is what I have in a main function:

// std
#include <iostream>

// project
#include "headers/common_definitions.hpp"
#include "classes/C_ParameterManager.hpp"

int main(int argc, char** argv) {
     using std::cout;
     using std::endl;
     gsl_error_handler_t* const old_handler = gsl_set_error_handler_off();
     rfn::ParameterManager* my_test = NULL;
     my_test->instance(rfn::flow_evolved);
     cout << my_test->instance() << endl;
     return (EXIT_SUCCESS);

The ParameterManager::instance function is declared as follows:

static ParameterManager* instance(const FunctionalNetworkScheme scheme);

and in the main function it correctly returns a pointer.

For testing purposes I use the following code:

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE rfn test suite

// project
#include "../headers/common_definitions.hpp"
#include "../classes/C_ParameterManager.hpp"

// boost
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(ParameterManagerTest)

BOOST_AUTO_TEST_CASE(test_default_constructor)
{
     rfn::ParameterManager* c = NULL;
     c = c->instance(rfn::flow_evolved);
     BOOST_CHECK_NE(c->instance()->seed(), 0);
}

BOOST_AUTO_TEST_SUITE_END() // ParameterManagerTest

When I try to compile it I get the following errors:

/tmp/ccOI5FiJ.o: In function
`ParameterManagerTest::test_default_constructor::test_method()':
test_rfn.cpp:(.text+0xcf): undefined reference to
`rfn::ParameterManager::instance(rfn::FunctionalNetworkScheme)'
test_rfn.cpp:(.text+0x136): undefined reference to
`rfn::ParameterManager::instance()'

I see no reason why the reference should be undefined as I include the
class header and specify the path to the .cpp file. Does the unit test
framework have a problem with static member functions?

Thank you for your help,
Moritz


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net