1

This is the error I get

Undefined symbols:
  "Config::fmap", referenced from:
      register_function(unsigned int (*)(unsigned int))in Config.o
      print_config()     in shared.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Config.h

#include <map>
#include <boost/preprocessor/stringize.hpp>

typedef unsigned int (*fptr_t)(unsigned int);
typedef std::map<fptr_t, std::string> function_name_map_type;

void register_hash_names();
void register_function(fptr_t funct_pointer);

class Config
{
public:

    static function_name_map_type fmap;
};

Config.cpp

function_map_t fmap;


void register_hash_names()
{
    register_function(sha1);
    ...
}

void register_function(fptr_t funct_pointer)
{
    (Config::fmap)[funct_pointer] = BOOST_PP_STRINGIZE(funct_pointer);
}

Shared.cpp where the error originates from:

std::cout << "\t " << Config::fmap[Config::current_hash_function] << "\n";

1 Answer 1

7

The definition in the .cpp should be:

function_map_t Config::fmap;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.