0

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.

Person
  • 429
  • 1
  • 8
  • 16

2 Answers2

2

Add the library option when you are linking your program:

g++:

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

vc++:

Phong
  • 6,600
  • 4
  • 32
  • 61
  • This isn't the problem. The libraries are linked. – Person Feb 20 '10 at 15:08
  • 1
    No, they aren't. If they were, the linker would be lying. And linkers don't do that. – sbi Feb 20 '10 at 15:40
  • In the Project Properties, under Linker, under Additional Library directories, I've put in C:\boost_1_42\lib That was all boost's documentation said was required when linking using VC++. – Person Feb 20 '10 at 16:41
  • 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 Feb 20 '10 at 18:31
  • Project property -> Configuration Properties -> Linker -> Input Additionnal Dependencies – Phong Feb 20 '10 at 18:31
  • 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 Feb 20 '10 at 18:43
  • 1
    You probably get better help at the boost users' mailing list: http://www.boost.org/community/groups.html#users – sbi Feb 21 '10 at 18:25
  • 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 Feb 21 '10 at 23:48
0

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.

Community
  • 1
  • 1
sbi
  • 219,715
  • 46
  • 258
  • 445
  • 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 Feb 20 '10 at 14:46
  • Which compiler are you using ? – Phong Feb 20 '10 at 14:48