【发布时间】:2012-09-15 15:57:06
【问题描述】:
我不明白为什么编译不正确,链接器报告缺少符号:
架构 x86_64 的未定义符号: “bool swinadventure::Utils::is_last<:__normal_iterator>>, std::vector > >(__gnu_cxx::__normal_iterator >>, std::vector > const&)”,引用自: swinadventure::Inventory::get_item_list(std::string, std::string) in Inventory.cpp.o
因为在这个过程的早期,我也看到了这个错误:/usr/bin/ranlib: file: liblibswinadventure.a(Utils.cpp.o) has no symbols 我认为由于某种原因它没有正确编译 utils 文件。
作为参考,我在安装并链接了大多数自制工具的 Mac OS X 10.7 系统上使用 CMake。
Utils.h
#ifndef UTILS_H_
#define UTILS_H_
#include <vector>
namespace swinadventure {
/**
* Static class for various utilities and helper functions
*/
class Utils {
public:
template <typename Iter>
static Iter next_iterator(Iter iter);
template <typename Iter, typename Cont>
static bool is_last(Iter iter, const Cont& cont);
};
} /* namespace swinadventure */
#endif /* UTILS_H_ */
Utils.cpp
#include "Utils.h"
namespace swinadventure {
/**
* Returns the next iterator
* http://stackoverflow.com/questions/3516196/testing-whether-an-iterator-points-to-the-last-item
* @param iter
* @return
*/
template <typename Iter>
Iter Utils::next_iterator(Iter iter) {
return ++iter;
}
/**
* Checks if the iterator is the last of the vector array
* http://stackoverflow.com/questions/3516196/testing-whether-an-iterator-points-to-the-last-item
* @param iter iterator
* @param cont vector array
* @return
*/
template <typename Iter, typename Cont>
bool Utils::is_last(Iter iter, const Cont& cont)
{
return (iter != cont.end()) && (next_iterator(iter) == cont.end());
}
} /* namespace swinadventure */
【问题讨论】:
-
这个问题有很多问题的重复。
标签: c++ templates vector compiler-errors cmake