views:

345

answers:

2

I'm using boost::function to enable the passing of a function to a Button constructor so it holds that function. Calling it whenever it is activated.

typedef boost::function< void() > Action;

In my TitleState I've constructed a Button like this.

  m_play( 
    ButtonAction, // This is where I pass a function to Button's Action argument
    sf::Vector2f( 500, 400 ), 
    sf::IntRect( 500, 400, 700, 500 ) 
  )

where ButtonAction is a static void function privately held in TitleState's header, defined in the implementation file as simply outputting to the console via std::cout (just as a test for whether it is working).

In my code, if the mouse clicks a button in TitleState's HandleEvents function, the program calls that button's Activate function which looks like this.

void Button::Activate() const {
  m_action(); // m_action is the Action member that holds the ButtonAction I passed earlier
}

The problem is that, when the program tries to link I get this error....

unresolved external symbol "public: void __thiscall Button::Activate(void)" (?Activate@Button@@QAEXXZ) referenced in function "public: virtual void __thiscall TitleState::HandleEvents(void)" (?HandleEvents@TitleState@@UAEXXZ)

I'm not sure what the problem is besides that the linker can't find the definition of the function. Everything is #included or declared properly. Any assistance is appreciated. Thanks.

P.S. When I used the BoostPro installer, I only installed the single-threaded stuff and none of the multi-threaded stuff. Could this be a reason why it isn't working? I read that linker problems can occur when libraries are linking in different ways. If this could be an issue, I'll add that I'm also using the SFML library.

+1  A: 

Add the library option when you are linking your program:

g++:

g++ -L/your/library/path -lyour_library_name

vc++:

Phong
This isn't the problem. The libraries are linked.
Person
No, they aren't. If they were, the linker would be lying. And linkers don't do that.
sbi
In the Project Properties, under Linker, under Additional Library directories, I've put in C:\boost_1_42\libThat was all boost's documentation said was required when linking using VC++.
Person
The path just indicate where you library is located, you also have to specify which library (file.dll or file.lib) you want to use.
Phong
Project property -> Configuration Properties -> Linker -> Input Additionnal Dependencies
Phong
Right, but what do I put there. I tried libboost_system-vc90-s-1_42.lib because I couldn't find any specific boost function library, but it didn't work.
Person
You probably get better help at the boost users' mailing list: http://www.boost.org/community/groups.html#users
sbi
I don't know the boost library you are using, If a link to the referenced library would be helpful. Maybe you just didn't build/download the library for your system
Phong
A: 

I'm not sure what the problem is. Everything is #included or declared properly. Any assistance is appreciated. Thanks.

That just means the compiler finds the declaration. But the linker has to find the definitions of the symbols. (See this SO question for what's the difference between a declaration and a definition.) You need to provide it with the library. If you're using GCC, follow Phong's advice.

sbi
I probably should have added, I understand that the linker can't find the definition, but I don't know why. The definition is clearly provided. I'm not using GCC.
Person
Which compiler are you using ?
Phong
I'm using VC++.
Person
I edited my answer for this purpose
Phong