为什么我得到"函数func具有内部链接但未定义"在Mac上

时间:2016-06-26 17:03:06

标签: c++ c++11 gcc

main.cpp我有

#include "helper.h"
#include <list>
using namespace std;
int main(int argc, const char * argv[]) {

    //switch between list and vector
    list<int> a = {0, 1};
    list<char> b = {'a', 'b'};

    func(a, b);

    return 0;
}

我的helper.h看起来像

template <class C1, class C2>
void func(C1 &a, C2 &b)

我的helper.cpp看起来像

#include <list>
#include "helper.h"

template <class C1, class C2>
void func (C1 &a, C2 &b)
{
    //do stuff
}

然后使用g++ main.cpp mysort.cpp -o sorting -std=c++11在Mac上的终端中构建它会生成错误"function func has internal linkage but is not defined"Undefined symbols for architecture x86_64: "void func<std::__1::list<char, std::__1::allocator<char> >, std::__1::list<int, std::__1::allocator<int> >, main::$_0>(std::__1::list<char, std::__1::allocator<char> >&, std::__1::list<int, std::__1::allocator<int> >&, main::$_0)", referenced from: _main in main-202a16.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

0 个答案:

没有答案