我使用 Xcode 4.5.2,我不会使用 Boost,但我遇到了一些问题。
在 Build Setting 中,如果我选择 libc++(支持 C++11 的 LLVM C++ 标准库),我将收到错误消息“Apple Mach-O Linker (ld) Error”。像这样:
Undefined symbols for architecture x86_64:
"boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::codecvt<wchar_t, char, __mbstate_t> const&)"
referenced from:
boost::filesystem::path::path<boost::filesystem::directory_entry>(boost::filesystem::directory_entry const&, boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<boost::filesystem::directory_entry>::type>, void>::type*) in test1 - inverted index.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我包括这两个标题:
#include <boost/filesystem.hpp>
#include <boost/operators.hpp>
我还在构建阶段中添加了这些:
libboost_filesystem-mt.dylib
libboost_filesystem-mt.a
libboost_system-mt.dylib
libboost_system-mt.a
代码在这里:
#include <boost/filesystem.hpp>
#include <boost/operators.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <set>
using namespace boost::filesystem;
std::map<std::string, std::set<int>> invertedIndex;
std::map<std::string, int> number;
bool check_char(const char in)
{
if((in>='A' && in<='Z') || (in>='a' && in<='z'))
return true;
else
return false;
}
int main() {
int con = 0;
std::string word;
path root("/Users/tomhu/Desktop/pro/data/");
std::string rootDirectory = root.native();
recursive_directory_iterator iter(root);
recursive_directory_iterator end;
for (; iter != end; ++iter)
{
if(is_regular_file(*iter))
{
std::string filename;
std::string directory(rootDirectory);
filename = iter->path().filename().native();
directory.append(filename);
std::ifstream fileIn(directory.c_str());
number[filename] = con;
if(!fileIn)
{
std::cerr << "File doesn't exist!" << std::endl;
exit(1);
}
while(fileIn>>word)
{
long po = 0;
if(!check_char(*(word.end()-1)))
word.pop_back();
transform(word.begin(),word.end(),word.begin(),::tolower);
if(word=="i")
word="I";
invertedIndex[word].insert(con);
}
}
}
std::cout << con << std::endl;
return 0;
}
!!!!!!!!!如果我在“构建设置”中选择 libstdc++(GUN C++ 标准库),我不会收到任何有关 Boost 的错误消息,但我不能在 C++11 标准中使用任何东西。
如何解决这些问题?