【发布时间】:2017-12-11 11:15:05
【问题描述】:
我最近安装了 Visual Studio 并开始使用 SFML 库和 Boost 库,但是当我在头文件中声明一个静态 void 函数时,我偶然发现了这个奇怪的(对我而言)错误静态类,Visual Studio 告诉我“找不到‘findTextures’的函数定义”当且仅当函数中存在 BOOST_FOREACH 代码时。大家知道为什么会这样吗?谢谢一堆。
这将是 TextureLoader.h:
#include <SFML/Graphics.hpp>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <iostream>
class TextureLoader {
public:
static const sf::Texture& getTexture(sf::String l_name);
static void findTextures();
private:
static std::map<sf::String, sf::Texture> textures;
};
这是 TextureLoader.cpp 类:
#include "TextureLoader.h"
// Get texture using name
const sf::Texture& TextureLoader::getTexture(sf::String l_name) {
return textures.at(l_name);
}
void TextureLoader::findTextures() {
namespace fs = boost::filesystem;
fs::path targetDir("/Textures");
fs::directory_iterator it(targetDir), eod;
BOOST_FOREACH(fs::path const &p, std::make_pair(it, eod)) {
if(fs::is_regular_file(p)) {
std::cout << p.filename();
}
}
}
输出:
1>------ Build started: Project: MasterTest, Configuration: Debug Win32 ------
1>TextureLoader.cpp
1>Unknown compiler version - please run the configure tests and report the results
1>TextureLoader.obj : error LNK2001: unresolved external symbol "private: static class std::map<class sf::String,class sf::Texture,struct std::less<class sf::String>,class std::allocator<struct std::pair<class sf::String const ,class sf::Texture> > > TextureLoader::textures" (?textures@TextureLoader@@0V?$map@VString@sf@@VTexture@2@U?$less@VString@sf@@@std@@V?$allocator@U?$pair@$$CBVString@sf@@VTexture@2@@std@@@5@@std@@A)
1>F:\Coding\VSProjects\MasterTest\Debug\MasterTest.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "MasterTest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
【问题讨论】:
-
如果没有 Visual Studio 的 exact 和 complete 输出,我们将无能为力。引用错误消息(来自 output 窗口,不是错误消息!)对于任何人都能够帮助您至关重要。
-
@JanHudec 刚刚编辑了问题并添加了错误日志:)
-
请作为 OUTPUT 窗口中的 TEXT。
-
请注意,错误窗口也允许文本复制和粘贴,但我从一开始就说过您应该从输出窗口中获取它,而不是错误窗口。
-
“未知编译器版本 - 请运行配置测试并报告结果”。我怀疑你使用的是 VS2017 版本 15.5,目前 boost 不支持。
标签: c++ visual-studio boost