2012-07-21 2 views
7

C++ linux에서 crypto ++을 사용하고 있습니다. 내가 그것을 실행하면 몇 가지 오류가 발생CryptoPP :: AlignedAllocate (unsigned int)에 대한 정의되지 않은 참조

#include <iostream> 
#include <fstream> 
#include <string.h> 

#include "crypto++/cryptlib.h" 
#include "crypto++/modes.h" 
#include "crypto++/filters.h" 
#include "crypto++/aes.h" 
#include "crypto++/osrng.h" 
#include "crypto++/strciphr.h" 

using namespace std; 
using namespace CryptoPP; 

ifstream::pos_type size; 
char * memblock; 
int length; 
char * _iv[AES::BLOCKSIZE]; 
char * keys[AES::MAX_KEYLENGTH]; 


void encriptCTR(byte * outbyte, const byte * inbyte, const byte * key, const byte * iv); 

void encriptCTR(byte * outbyte, const byte * inbyte, const byte * key, const byte * iv) 
{ 
    size_t inbyte_len = strlen((const char *)inbyte); 
    CTR_Mode<AES>::Encryption ctr_encription(key, strlen((const char*)key), iv); 
    ctr_encription.ProcessData(outbyte, inbyte, inbyte_len); 
} 

int main() 
{ 
    ifstream file; 
    file.open("testaja", ios::binary); 
    if (file.is_open()) 
    { 
     file.seekg (0, ios::end); 
     length = file.tellg(); 
     memblock = new char [length]; 
     file.seekg (0, ios::beg); 
     file.read (memblock, length); 


     if (!file) 
     { 
      int a; 
      a = (int)file.gcount(); 
      file.clear(); 
     } 
     else 
     { 
      file.close(); 

      for (int i = 0; i < length; ++i) 
      { 
       cout << hex << (int)memblock[i] << " "; 
      } 

     } 
    } 
} 

: 여기 내 간단한 코드입니다

undefined reference to `CryptoPP::AlignedAllocate(unsigned int)' 
undefined reference to `CryptoPP::UnalignedAllocate(unsigned int)' 
undefined reference to `CryptoPP::AlignedDeallocate(unsigned int)' 
undefined reference to `CryptoPP::UnalignedDeallocate(unsigned int)' 

을 다음, 나는 명령

gcc -o test test.cpp -L/usr/lib/crypto++ -lcrypto++ 

을 사용하지만, 여전히이 오류 :

undefined reference to `CryptoPP::AlignedAllocate(unsigned int)' 
undefined reference to `CryptoPP::UnalignedAllocate(unsigned int)' 
undefined reference to `CryptoPP::AlignedDeallocate(unsigned int)' 
undefined reference to `CryptoPP::UnalignedDeallocate(unsigned int)' 

어떻게이 오류를 해결할 수 있습니까? 내 코드에 문제가 있습니까?

나는이 패키지에 대한 시냅스 패키지 관리자를 사용하여 ++ 암호화를 설치하고있다 :..

libcrypto++-utils 
libcrypto++8 
libcrypto++8-dbg 
libcrypto++-dev 
libcrypto++-doc 

및 libcrypto ++ a와 libcrypto는 ++ 그래서 미리는/usr/lib 디렉토리/

감사에서 찾을 수 있습니다.

+0

내가 사용 g ++ 컴파일하지만, 여전히 그 오류를 시도했다. 어떤 C++ 코드를 링크해야합니까? 감사. – user1533464

+0

AlignedAllocate (unsigned int)는 Crypto ++/secblock.h에 AlignedAllocate (unsigned int)가 선언되었지만 AlignedAllocate (unsigned int) 구현을 찾을 수 없으며이 오류가 발생하는 ++/misc.h를 포함한다고 생각합니다. 나는 어떻게해야합니까? – user1533464

+0

내 프로그램에 crypto ++/misc.h를 포함 시키려고했지만 오류가 계속 발생합니다. – user1533464

답변

5

이 명령은 잘못된 같습니다 다음

-L/usr/lib/crypto++ 말을해서는 안된다 (당신이 말하는대로) libs와 /usr/lib에있는 경우

gcc -o test test.cpp -L/usr/lib/crypto++ -lcrypto++ 

나는 libcrypto++8 패키지는 -L/usr/lib/crypto++ 년 libs가 설치 생각 디렉토리와 호환되지 않으며 프로그램에 필요한 정의되지 않은 기호를 제공하지 않는 것으로 추정됩니다.

당신은 단순히 컴파일해야합니다

gcc -o test test.cpp -lcrypto++ 

을가

+0

감사합니다. 홍옥. 그것은 작동합니다. – user1533464

3

해결 (이 라이브러리에 대한 기본 위치는 어쨌든입니다으로 -L/usr/lib 말 할 필요도 없다)! 내가이 명령을 사용 후 때문에

g++ -o test test.cpp -L/usr/lib/ -lcryptopp -lpthread 

내가 -lpthread 추가 :

g++ -o test test.cpp -L/usr/lib/ -lcryptopp 

을 나는 이러한 오류를 얻을 :이 명령에

g++ -o test test.cpp -L/usr/lib/crypto++ -lcrypto++ 

: 이 난에서 내 명령을 변경

./libcryptopp.so: undefined reference to `pthread_getspecific' 
./libcryptopp.so: undefined reference to `pthread_key_delete' 
./libcryptopp.so: undefined reference to `pthread_key_create' 
./libcryptopp.so: undefined reference to `pthread_setspecific' 

-L/usr/lib/crypto ++ arg에 대해 오해했습니다. 컴파일러가/usr/lib/dir에서 crypto ++을 검색 할 것입니다. 컴파일러는 -L/usr/lib/crypto ++ dir에서 crypto ++을 검색합니다. 패키지는 -L/usr/lib/dir에 설치됩니다.

감사합니다. @jonathan wakely.

0

이 문제도 있습니다. 컴파일러는 프로그램에 라이브러리 파일을 바인드해야하므로 decleration의 구현을 찾을 수 없기 때문에!

나는 여전히 내 문제를 해결하지 못합니다. 그러나 당신은 다른 길을 가지고있다! !! 대신 라이브러리 파일이 포함 된 .cpp 원본 파일을 사용할 수 있습니다.

당신은 아래 링크에서 원래 Cryptopp을 다운로드 할 수 있습니다

https://www.cryptopp.com/cryptopp563.zip

관련 문제