error: conflicting declaration of C function
时间: 2023-07-12 09:03:07 浏览: 314
这个错误通常是因为在代码中存在重复定义的函数声明。可能是在头文件中定义了函数,但在源文件中也定义了同名的函数,导致编译器无法判断该使用哪个定义。
解决方法是检查代码中是否存在重复定义的函数声明,如果有的话,需要将其中一个删除或重命名。也可以考虑使用头文件保护宏来防止头文件被重复包含,从而避免重复定义函数的问题。
相关问题
D:\ZBY\CodeBase\eigen-3.4.0\Eigen\src\LU\FullPivLU.h:332: error: conflicting declaration of C function 'long long int std::abs(long long int)' using std::abs; ^
这个错误是因为在 FullPivLU.h 文件中使用了 `using std::abs`,而 `std::abs` 与 C 语言的 `abs` 函数重名了,导致冲突。解决这个问题的方法是使用命名空间 `std::` 来明确使用 C++ 标准库中的 `abs` 函数,而不是使用 `using` 语句。你可以在 FullPivLU.h 文件中将 `using std::abs` 改为 `using namespace std;` 或者直接使用 `std::abs` 替代原来的 `abs`。
D:\ZBY\CodeBase\eigen-3.4.0\Eigen\src\SVD\SVDBase.h:150: error: conflicting declaration of C function 'long long int std::abs(long long int)' using std::abs; ^
这个错误可能是因为您在代码中使用了 `std::abs` 函数,但是有另一个名为 `abs` 的函数与其冲突了。建议您使用 `std::abs` 代替 `abs`,或者使用 `using namespace std;` 来避免命名冲突。例如:
```cpp
#include <iostream>
#include <cmath>
using namespace std;
int main() {
long long int x = -123456789;
cout << abs(x) << endl; // 冲突
cout << std::abs(x) << endl; // 使用 std::abs
return 0;
}
```
如果您仍然想使用 `abs` 函数,您可以将其重命名为其他名称,如:
```cpp
#include <iostream>
#include <cmath>
namespace mymath {
using std::abs;
}
int main() {
long long int x = -123456789;
cout << abs(x) << endl; // 冲突
cout << mymath::abs(x) << endl; // 重命名为 mymath::abs
return 0;
}
```
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)