2017-12-11 9 views
0

최근에 Visual Studio를 설치하고 SFML 라이브러리 및 Boost 라이브러리로 약간의 작업을 시작했지만 이상한 (나에게) 오류가 발생했습니다. 정적 클래스의 헤더 파일에서 정적 void 함수를 선언 할 때 Visual Studio에서는 "findTextures '에 대한 함수 정의가 없다는 것을 알려줍니다. BOOST_FOREACH 코드가 함수에있는 경우에만 나타납니다. 왜 이런 일이 일어나는 지 아십니까? 무리 감사.Visual Studio C++ 및 Boost Lib : 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" ([email protected]@@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected][email protected][email protected]@@[email protected]@@[email protected]@@[email protected]@[email protected]@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 ========== 

The error log

+0

Visual Studio의 * exact * 및 * complete * 출력이 없으면 실제로 도움이되지 않습니다. 오류 메시지 (* 출력 * 창에서 * 오류 * 오류 메시지를 인용하지 않음)는 누구에게나 당신을 도울 수있는 필수 요소입니다. –

+0

@JanHudec 님이 질문을 편집했으며 오류 로그를 추가했습니다. :) – Crack498

+0

** OUTPUT ** 창에서 ** TEXT **와 (과) 같이하시기 바랍니다. –

답변

1

음, 누락 된 상징의 이름을주의 깊게 읽으십시오. 그것은 말합니다 :

std::map</*…*/> TextureLoader::textures 

그건 아무 기능이 아닙니다. 정적 멤버 변수입니다. 그리고, 글쎄, 당신은 정말로 그것을 놓치고 있습니다. 정적 멤버 변수를 선언하는 것은 충분한 하지 때문에

std::map<sf::String, sf::Texture> TextureLoader::textures; 

: 귀하의 .cpp 파일과 같이된다 그것의 정의를 포함하여야한다. 그것들도 정의해야합니다.

+0

참고 : 정확한 출력이 중요한 이유를 여기에서 확인할 수도 있습니다. 질문의 원래 텍스트는 " 'findTextures' '에 대한 함수 정의를 말했지만 문제와 완전히 다른 상징으로 밝혀졌습니다. –

+0

"findTextures 'not found"메시지에 대한 Funcion 정의가 여전히 녹색 밑줄로 표시되어 있지만 Ok입니다. 감사! – Crack498

+0

@ Crack498, 편집기 내 오류 강조 표시는 매우 유용하지만 항상 신뢰할 수는 없습니다. 그래서 실제 컴파일러 출력을 확인하는 것이 중요합니다. 일반적으로 오류 창은 충분하지만 때로는 출력 창에서만 사용할 수있는 추가 정보가 있습니다 (특히 템플리트가 관련된 경우). –