"Undefined symbols for architecture x86_64"尝试包含另一个文件中的功能
"Undefined symbols for architecture x86_64" trying to include function from another file
我试图在另一个程序event_rate.cpp中包含一个名为kinematic_factor的函数,该函数用kinematic_filter.cpp编写。
kinematic_factor.cpp:
#include "kinematic_factor.hpp"
double kinematicfactor (double md) {
double mt = 17.6924; // Mass of Fluorine [GeV/c^2]
double r = 4*mt*md/pow(mt+md, 2);
return r;
}
kinematic_factor.hp:
#ifndef kinematic_factor_hpp
#define kinematic_factor_hpp
double kinematicfactor (double md);
#endif /* kinematic_factor_hpp */
事件速率:
#include "event_rate.hpp"
#include "kinematic_factor.hpp"
#include <iostream>
#include <cmath>
using namespace std;
int main() {
cout << kinematic_factor(1.0) << endl;
}
据我所知,这是我应该做的,但我得到了一个错误:
Undefined symbols for architecture x86_64:
"kinematicfactor(double)", referenced from:
_main in event_rate-1d17f7.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 "kinematic_factor.cpp"
它奏效了。但我听说包括cpp文件(而不是头文件)对学习者来说是一种糟糕的做法。。。我能做什么?
你们是如何编译这个程序的,我能够正确地编译同一个程序。我怀疑这应该是一个关联问题。
您需要将源代码一起编译才能进行编译和链接。
g++ kinematic_factor.cpp event_rate.cpp -o event_rate
相关文章:
- 在作为静态成员包含在另一个类中的类的构造函数中使用 cout
- 检查路径是否包含C++中的另一个路径
- C++ .h 包含从一个类传递到另一个类的类和.cpp
- CMake 将库包含在另一个库中
- 如何将包含另一个对象向量的对象保存到文件中,并使用C++中的二进制文件从文件中读回?
- 创建一个 const std::vector ,其中包含另一个 const std::vector 和其他值
- 包含来自另一个文件的函数会导致范围错误(openFoam)
- 如何为包含另一个类实例的数组制作常量 getter?
- 使用按位运算确定值是否包含另一个值
- C++将包含的库 (ref DLL) 从根目录更改为另一个位置
- 如何在我的 cmake 项目中包含另一个 cmake 项目的头文件?
- 继承一个类,该类继承另一个已包含的类
- 如何查找哪个标头在包含树中包含另一个标头
- 将 2 个链表中包含的相同值写入另一个链表
- 如何从另一个包含目录中的标头访问包含目录中的标头
- 如何将另一个项目中用 C 编写的源代码包含在我自己的项目中,C++在 Visual Studio 中
- 包含另一个实例的特征实例,该实例持有固定大小的特征对象
- 如何隐藏另一个包含的静态库的API
- 如何从文件中的类调用,以使用着色器显示在另一个包含gl代码的文件中(其中两个文件都在jni文件夹中)
- 如何在另一个包含对象的文件中创建一个函数并从 main 调用它