无法解析的外部符号“public: void __thiscall...”
我使用 boost::function
来将函数传递给 Button
构造函数,以便它保存该函数。每当它被激活时调用它。
typedef boost::function< void() > Action;
在我的 TitleState 中,我构建了一个像这样的按钮。
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 )
)
其中 ButtonAction 是一个静态 void 函数,私有地保存在 TitleState 的标头中,在实现文件中定义为简单地通过 std::cout 输出到控制台(只是作为其是否正常工作的测试)。
在我的代码中,如果鼠标单击 TitleState 的 HandleEvents
函数中的按钮,程序将调用该按钮的 Activate
函数,如下所示。
void Button::Activate() const {
m_action(); // m_action is the Action member that holds the ButtonAction I passed earlier
}
问题是,当程序尝试链接时,我收到此错误......
函数中引用的未解析的外部符号“public: void __thiscall Button::Activate(void)” (?Activate@Button@@QAEXXZ) "public: virtual void __thiscall TitleState::HandleEvents(void)" (?HandleEvents@TitleState@@UAEXXZ)
除了链接器找不到函数的定义之外,我不确定问题是什么。所有内容均已#included
或正确声明。如有任何帮助,我们将不胜感激。谢谢。
PS 当我使用BoostPro安装程序时,我只安装了单线程的东西,没有安装多线程的东西。这可能是它不起作用的原因吗?我读到,当库以不同方式链接时,可能会出现链接器问题。如果这可能是一个问题,我会补充说我也在使用 SFML 库。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
链接程序时添加库选项:
g++:
vc++:
Add the library option when you are linking your program:
g++:
vc++:
这仅仅意味着编译器找到了声明。但链接器必须找到符号的定义。 (有关声明和定义之间的区别,请参阅这个 SO问题。)您需要将其与库一起提供。如果您使用的是 GCC,请遵循 Phong 的建议。
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.