C ++具有用户定义函数的架构x86_64的未定义符号 [英] C++ Undefined symbols for architecture x86_64 with user defined function

查看:127
本文介绍了C ++具有用户定义函数的架构x86_64的未定义符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编译时收到以下错误讯息。

I'm getting the following error message at compilation.

    Undefined symbols for architecture x86_64:
  "LSMDP2<HC_Base, HC_Base, Sine>::LSMDP2(int, int, std::unique_ptr<Forward, std::default_delete<Forward> >&, std::unique_ptr<BrownianMotionIncGenerator, std::default_delete<BrownianMotionIncGenerator> >&, std::unique_ptr<Driver, std::default_delete<Driver> >&, Sine&&, gsl_vector*, std::unique_ptr<Regression, std::default_delete<Regression> >&, std::unique_ptr<UniformSims, std::default_delete<UniformSims> >&, std::unique_ptr<TimeGrid, std::default_delete<TimeGrid> >&, HC_Base&&, HC_Base&&)", referenced from:
      LSMDP2<HC_Base, HC_Base, Sine> make_LSMDP2<HC_Base, HC_Base, Sine>(int, int, std::unique_ptr<Forward, std::default_delete<Forward> >&, std::unique_ptr<BrownianMotionIncGenerator, std::default_delete<BrownianMotionIncGenerator> >&, std::unique_ptr<Driver, std::default_delete<Driver> >&, Sine&&, gsl_vector*, std::unique_ptr<Regression, std::default_delete<Regression> >&, std::unique_ptr<UniformSims, std::default_delete<UniformSims> >&, std::unique_ptr<TimeGrid, std::default_delete<TimeGrid> >&, HC_Base&&, HC_Base&&) in main.o


ld: symbol(s) not found for architecture x86_64

collect2: error: ld returned 1 exit status

make: *** [BSDESimV2] Error 1

假定未定义的符号是

template<class BasisY, class BasisZ, class Term>  LSMDP2<BasisY,BasisZ,Term> make_LSMDP2(int N, int q , F_Forward_  & F  ,
         BM_Inc_ & B,   B_Driver_ & D,  Term && Ter,  gsl_vector * X0 ,
        A_Regression_& R, A_UniSims_ & M, T_Grid_ & T /*Time grid initializer*/, BasisY && BY, BasisZ && BZ){
return LSMDP2<BasisY,BasisZ,Term>{N, q ,F, B, D, std::forward<Term>(Ter), X0, R, M , T, std::forward<BasisY>(BY), std::forward<BasisZ>( BZ) };
}

此函数包含在定义LSMDP2类的头文件中。我检查了链接,它的罚款,和构造函数'LSMPD2(....)'在一个单独的cpp文件中定义。我已经确保不要做一般的错误,如拧紧链接,忘记建立cpp文件,忘记定义构造函数,或使用gcc而不是g ++。

This function is contained in the header file in which the LSMDP2 class is defined. I've checked the linking, it's fine, and the constructor 'LSMPD2(....)' is defined in a separate cpp file. I've made sure not to do the usual mistakes, like screw up linking, forget to build the cpp file, forgot defined the constructor, or use gcc rather than g++.

实际上,我尝试了一个更简单的例子相同的结构 - 只有一个cpp文件在编译,更少的参数,但模板和unique_ptrs在使用 - 它工作正常。有没有人知道是什么原因导致这个问题?

Actually, I tried the same construction on a much simpler example - only one cpp file in the compilation, fewer arguments, but both templates and unique_ptrs in use - and it worked fine. Does anyone know what could be causing this problem?

推荐答案

你说LSMPD2构造函数是在一个单独的cpp文件中定义的。这是你的问题。因为类显然是一个模板,所以在外部使用的类的所有方法必须在头文件中定义,而不是一个单独编译的实现文件。

You say the LSMPD2 constructor is "defined in a separate cpp file." That's your problem. Since the class is apparently a template, all methods of the class which are used outside must be defined in the header file, not a separately-compiled implementation file.

详情,请参阅:为什么模板只能在头文件?

这篇关于C ++具有用户定义函数的架构x86_64的未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆