单独编译word_transform.cc文件的时候报错:
word_transform.cc:(.text+0x133):对‘open_file(std::basic_ifstream<char, std::char_traits<char> >&, std::string const&)’未定义的引用 word_transform.cc:(.text+0x533):对‘open_file(std::basic_ifstream<char, std::char_traits<char> >&, std::string const&)’未定义的引用 word_transform.cc:(.text+0x703):对‘open_file(std::basic_ifstream<char, std::char_traits<char> >&, std::string const&)’未定义的引用 collect2: 错误: ld 返回 1
原因:word_transform.cc这个文件的源码中,只在最上面声明了open_file()函数。但是没有在后面实现该函数,所以,会报open_file()未定义的错误。
ifstream& open_file(ifstream&, const string&); 其源码如下: ifstream& open_file(ifstream &in, const string &file) { in.close(); // close in case it was already open in.clear(); // clear any existing errors // if the open fails, the stream will be in an invalid state in.open(file.c_str()); // open the file we were given return in; // condition state is good if open succeeded }在word_transform.cc文件最下面加上open_file()函数源码就可以正常运行了。
注:通过makefile文件将gnu_files文件夹下所有源码一起编译word_transform.cc是可以通过的,所以,说明open_file这个函数是在某个文件里面实现了。只是本来找人半天没找到在哪里。如果有人找到可以tell me,tks
原文:http://blog.csdn.net/zhouhong1026/article/details/19493833