【问题标题】:'class" has a previous declaration here“类”在这里有一个先前的声明
【发布时间】:2012-10-03 04:08:21
【问题描述】:

我终其一生都无法弄清楚出了什么问题。

我的生成文件:

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

我觉得我已经尝试了所有方法,但我被卡住了。有什么想法吗?

【问题讨论】:

    标签: c++ compiler-errors g++


    【解决方案1】:

    /usr/include/openssl/ossl_typ.h:140:23: error: ‘RSA’ has a previous declaration here

    从错误消息看来,您的符号名称与 OpenSSL 中定义的另一个名为 RSA 的类发生冲突。
    有两种方法可以解决这个问题:

    1. 更改您的班级名称或
    2. 如果您想保持相同的名称,请在命名空间中进行包装。

    【讨论】:

      【解决方案2】:

      您的编译器在 ossl_typ.h 文件中找到了 RSA 的 typedef,当您编译您的程序时,它间接 #included。我至少能想到三个解决方案:

      1. 将您的班级名称更改为其他名称。

      2. 将您的课程放入namespace

      3. 弄清楚为什么 OpenSSL 标头包含在您的构建中。环顾四周后,我发现this Q&Agcc -w -H &lt;file&gt; 将向您显示#included 的文件。从那里您可能能够删除对 OpenSSL 标头的依赖。

      【讨论】:

        猜你喜欢
        • 2011-07-28
        • 1970-01-01
        • 1970-01-01
        • 2014-12-10
        • 2021-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-22
        相关资源
        最近更新 更多