2012-10-03 25 views
0

我不能为我的生活出了什么问题“类”在这里有一个先前的声明

我的生成文件:

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 

我觉得我已经尝试了一切,但我坚持。有任何想法吗?

回答

4

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

从错误消息,看来你有一个符号名称冲突与名为RSA内的OpenSSL定义的另一个类。
有两种方法来克服这个问题:

  1. 更改您的类名或
  2. 结束语在命名空间中,如果你想保持相同的名称。
1

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

  1. 更改您的类名称到别的东西。

  2. 把你的课放在namespace

  3. 找出为什么OpenSSL头包含在您的构建中。环顾四周后,我发现this Q&A其中说gcc -w -H <file>会显示#included的文件。从那里你可能可以删除对OpenSSL头文件的依赖。

相关问题