简体   繁体   English

使用SFML构建C ++项目时未定义的参考

[英]undefined reference when building C++ project using SFML

Yes, there are already some SO posts about this - However they didn't help me solve my issue. 是的,已经有一些关于此的SO帖子-但是它们并没有帮助我解决我的问题。

A few days ago I've already posted a question related to SFML - My project couldn't include the header files, or at least I thought so. 几天前,我已经发布了一个与SFML相关的问题 -我的项目无法包含头文件,或者至少我认为是这样。 I've marked the question as answered because the project compiled well, but silly me didn't try to actually Build the project, which involves the linking process. 我已将该问题标记为已回答,因为该项目编译良好,但是愚蠢的我并未尝试实际构建该项目,该过程涉及链接过程。

The thing is I get the following error when trying to link: 问题是尝试链接时出现以下错误:

In function AudioUtils::playSound(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': somepath: undefined reference to __imp__ZN2sf11SoundBuffer12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE' 在函数AudioUtils::playSound(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': somepath: undefined reference to __imp__ZN2sf11SoundBuffer12loadFromFileERcNSCeEchar的AudioUtils::playSound(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': somepath: undefined reference to

It seems like the string class that's used in the SFML library is different than the one I use. 似乎SFML库中使用的字符串类不同于我使用的字符串类。 If this problems occurs due to different compiler versions, then I can assure you that the version are the same. 如果由于不同的编译器版本而发生此问题,那么我可以向您保证版本是相同的。

It is also worth mentioning that I'm developing in CLion. 值得一提的是,我正在CLion中进行开发。

So what actually does cause this problem and how do we fix it? 那么究竟是什么真正导致了此问题,我们如何解决呢?

I've managed to resolve the issue - It was a pretty thin though foolish mistake: 我已经设法解决了这个问题-尽管犯了一个愚蠢的错误,但却是一个很薄的错误:

I forgot to invalidate/reload CMake's cache, which led to the issue where the compiler versions aren't the same. 我忘了使CMake的缓存无效/重新加载,这导致了编译器版本不同的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM