C++:"错误收集 2:错误:ld 返回 1 退出状态"
C++: "error collect2: error: ld returned 1 exit status"
我正在编写一个简单的程序来计算函数的导数,但我总是得到错误:
collect2:错误:ld 返回 1 个退出状态
这是我的程序:
#include <iostream>
#include <stdlib.h>
#include <math.h>
using namespace std;
double derivative2(double (fun), double step, double x);
double fun(double);
int main(int argc, char* argv[]) {
double h = atof(argv[1]);
double x = sqrt(2);
cout << derivative2(fun(x), h, x) << endl;
return 0;
}
double derivative2(double fun(double), double step, double x) {
return ((fun(x + step) - fun(x))/step);
}
double fun(double x) {
return atan(x);
}
我找到了这篇文章,但它对我的情况没有用。
double derivative2(double (fun), double step, double x);
和
double derivative2(double fun(double), double step, double x)
是不同的东西。在第一个声明中fun
是double
,在第二个fun
是double(*)(double)
(指向函数的指针)。
由于此函数在某个点计算导数,因此正确的声明是带有函数指针的声明。
修复:
double derivative2(double fun(double), double step, double x); // 'fun' is a function pointer.
// ...
cout << derivative2(fun, h, x) << endl; // Pass fun as a function pointer.
相关文章:
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 试图在崇高中奔跑. 错误 已发生: 收集2.exe: 错误: ld 返回 1 退出状态
- collect2:错误:ld 返回 1 个退出状态未定义的引用
- 退出分段错误 ¿如何解决此问题?
- C++ collect2:错误:ld 返回 1 退出状态
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 找不到 -llibmysqld Collect2.exe:错误:ld 返回 1 退出状态
- 当我选择大于 720 的矩阵大小时,程序退出并显示错误代码.可能是什么原因?
- 虽然循环即使应用了错误条件也不会退出
- 每次我要使用外部资源时,我都会得到:collect2。exe:错误 ld 返回 1 退出状态
- 当出现错误ld return 1退出状态时,如何编译程序
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 无法访问 Arduino 结构字段。错误"退出状态 1。xxxx 不命名类型"
- _CrtIsValidHeapPointer(块)错误在应用单例-帕特恩后退出主窗口时引发
- ld返回1个错误退出状态C++