"类"在这里有一个先前的声明
'class" has a previous declaration here
我一辈子都无法弄清楚出了什么问题。
我的制作文件:
all: main.o rsa.o
g++ -Wall -o main bin/main.o bin/rsa.o -lcrypto
main.o: src/main.cpp inc/rsa.h
g++ -Wall -c src/main.cpp -o bin/main.o -I inc
rsa.o: src/rsa.cpp inc/rsa.h
g++ -Wall -c src/rsa.cpp -o bin/rsa.o -I inc
我的主要课程:
#include <iostream>
#include <stdio.h>
#include "rsa.h"
using namespace std;
int main()
{
//RSA rsa;
return 0;
}
我.cpp:
#include "rsa.h"
#include <iostream>
using namespace std;
RSA::RSA(){}
我的.h:
#ifndef RSA_H
#define RSA_H
class RSA
{
RSA();
};
#endif
我收到以下错误:
In file included from src/main.cpp:7:0:
inc/rsa.h:7:7: error: using typedef-name ‘RSA’ after ‘class’
/usr/include/openssl/ossl_typ.h:140:23: error: ‘RSA’ has a previous declaration here
我觉得我已经尝试了一切,但我被卡住了。有什么想法吗?
/usr/include/openssl/ossl_typ.h:140:23:错误:"RSA"在此处具有先前的声明
从错误消息来看,您的符号名称似乎与 OpenSSL 中定义的名为RSA
的另一个类冲突。
有两种方法可以克服这个问题:
- 更改课程名称或 如果要
- 保留相同的名称,请包装在命名空间中。
编译器在 ossl_typ.h 文件中发现了 RSA 的 typedef,在编译程序时会间接 #included。我至少可以想到三种解决方案:
-
将类名更改为其他名称。
-
把你的班级放在一个
namespace
. -
弄清楚为什么 OpenSSL 标头包含在您的构建中。环顾四周后,我发现了这个问答,上面说
gcc -w -H <file>
会向你展示 #included 的文件。从那里,您可以删除对OpenSSL标头的依赖。
相关文章:
- 有一个打印语句的函数是一种糟糕的编程实践吗
- VSCode-有一个红色下划线,但程序构建和运行正确,并且出现配音错误
- 如果有一个模板构造函数只有一个泛型参数,为什么我必须有一个复制构造函数
- 有没有可能有一个只有ADL才能找到的非好友功能
- 我有一个对象,它将在整个程序的持续时间内实例化,但一个类成员不会,我应该动态分配它吗?
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- 在 C++ 中声明 const 对象需要用户定义的默认构造函数.如果我有一个可变成员变量,为什么不呢?
- c++ 在类中声明私有的向量,但有一个 get 函数
- 函数在类中声明时应该有一个原型
- "类"在这里有一个先前的声明
- C++:在main.cpp中声明一个结构,但在头中有一个带类的模板的任何可能性
- 为什么C++有一个额外的类名声明
- std::map-C++要求所有声明都有一个类型说明符
- 编译器声明调用没有匹配的函数,即使原型中有一个
- C++要求所有声明都有一个类型说明符
- 将构造函数声明为private会显示错误.是否至少有一个公共构造函数是必需的
- 如何可能在C++中的main()中不声明任何内容,却在编译后有一个可用的应用程序
- Qt:在c++类中有一个未声明为指针的小部件字段是很好的
- c++的前向声明,里面有一个列表
- visual studio 2010 -智能感知:期望在c++中有一个声明