Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Help with using gcrypt in eclipse CDT
Help with using gcrypt in eclipse CDT [message #829935] Tue, 27 March 2012 01:21 Go to next message
Geoff K is currently offline Geoff KFriend
Messages: 2
Registered: March 2012
Junior Member
I am trying to implement an AES 128 encryption algorithm using gcrypt in Eclipse; however, I am getting nowhere fast. I am stuck on an error message titled "ld: symbol(s) not found for architecture x86_64." Below is the code I am using, which I got from another thread.

#include <stdio.h>
#include <stdlib.h>
#include <gcrypt.h>

static void aesTest(int gcry_mode, char * iniVector)
{
    #define GCRY_CIPHER GCRY_CIPHER_AES128   // Pick the cipher here

    gcry_error_t     gcryError;
    gcry_cipher_hd_t gcryCipherHd;
    size_t           index;

    size_t keyLength = gcry_cipher_get_algo_keylen(GCRY_CIPHER);
    size_t blkLength = gcry_cipher_get_algo_blklen(GCRY_CIPHER);
    char * txtBuffer = "123456789 abcdefghijklmnopqrstuvwzyz ABCDEFGHIJKLMNOPQRSTUVWZYZ";
    size_t txtLength = strlen(txtBuffer)+1; // string plus termination
    char * encBuffer = malloc(txtLength);
    char * outBuffer = malloc(txtLength);
    char * aesSymKey = "one test AES key"; // 16 bytes

    gcryError = gcry_cipher_open(
        &gcryCipherHd, // gcry_cipher_hd_t *
        GCRY_CIPHER,   // int
        gcry_mode,     // int
        0);            // unsigned int
    if (gcryError)
    {
        printf("gcry_cipher_open failed:  %s/%s\n",
               gcry_strsource(gcryError),
               gcry_strerror(gcryError));
        return;
    }

    gcryError = gcry_cipher_setkey(gcryCipherHd, aesSymKey, keyLength);
    if (gcryError)
    {
        printf("gcry_cipher_setkey failed:  %s/%s\n",
               gcry_strsource(gcryError),
               gcry_strerror(gcryError));
        return;
    }

    gcryError = gcry_cipher_setiv(gcryCipherHd, iniVector, blkLength);
    if (gcryError)
    {
        printf("gcry_cipher_setiv failed:  %s/%s\n",
               gcry_strsource(gcryError),
               gcry_strerror(gcryError));
        return;
    }

    gcryError = gcry_cipher_encrypt(
        gcryCipherHd, // gcry_cipher_hd_t
        encBuffer,    // void *
        txtLength,    // size_t
        txtBuffer,    // const void *
        txtLength);   // size_t
    if (gcryError)
    {
        printf("gcry_cipher_encrypt failed:  %s/%s\n",
               gcry_strsource(gcryError),
               gcry_strerror(gcryError));
        return;
    }

    gcryError = gcry_cipher_setiv(gcryCipherHd, iniVector, blkLength);
    if (gcryError)
    {
        printf("gcry_cipher_setiv failed:  %s/%s\n",
               gcry_strsource(gcryError),
               gcry_strerror(gcryError));
        return;
    }

    gcryError = gcry_cipher_decrypt(
        gcryCipherHd, // gcry_cipher_hd_t
        outBuffer,    // void *
        txtLength,    // size_t
        encBuffer,    // const void *
        txtLength);   // size_t
    if (gcryError)
    {
        printf("gcry_cipher_decrypt failed:  %s/%s\n",
               gcry_strsource(gcryError),
               gcry_strerror(gcryError));
        return;
    }

    printf("gcry_mode = %s\n", gcry_mode == GCRY_CIPHER_MODE_ECB ? "ECB" : "CBC");
    printf("keyLength = %d\n", keyLength);
    printf("blkLength = %d\n", blkLength);
    printf("txtLength = %d\n", txtLength);
    printf("aesSymKey = %s\n", aesSymKey);
    printf("iniVector = %s\n", iniVector);
    printf("txtBuffer = %s\n", txtBuffer);

    printf("encBuffer = ");
    for (index = 0; index<txtLength; index++)
        printf("%02X", (unsigned char)encBuffer[index]);
    printf("\n");

    printf("outBuffer = %s\n", outBuffer);

    // clean up after ourselves
    gcry_cipher_close(gcryCipherHd);
    free(encBuffer);
    free(outBuffer);
}

int main(void) {
    aesTest(GCRY_CIPHER_MODE_ECB, "a test ini value");
    aesTest(GCRY_CIPHER_MODE_ECB, "different value!");
    aesTest(GCRY_CIPHER_MODE_CBC, "a test ini value");
    aesTest(GCRY_CIPHER_MODE_CBC, "different value!");
	return EXIT_SUCCESS;
}


When I try to build the above, I get the below error - mainly ld: symbol(s) not found for architecture x86_64. I have a feeling I might not being including the gcrypt library correctly - I added the libgcrypt directory to "Project Properties"/"C/C++ General"/"Paths and Symbols"/"Includes" - but after playing around with different ways to include the library, I kept getting similar results. Although it shouldn't matter, I'm running A MacBook with OS Lion.

Here is my console after building:


**** Build of configuration Debug for project aesTest ****

make all 
Building target: aesTest
Invoking: MacOS X C Linker
gcc -L"/Applications/eclipse CDT/Includes/libgcrypt-1.5.0/src" -L"/Applications/eclipse CDT/Includes/libgcrypt-1.5.0/cipher" -L"/Applications/eclipse CDT/Includes/libgpg-error-1.10/src" -o "aesTest"  ./src/aesTest.o   
Undefined symbols for architecture x86_64:
  "_gcry_cipher_get_algo_keylen", referenced from:
      _aesTest in aesTest.o
  "_gcry_cipher_get_algo_blklen", referenced from:
      _aesTest in aesTest.o
  "_gcry_cipher_open", referenced from:
      _aesTest in aesTest.o
  "_gcry_strerror", referenced from:
      _aesTest in aesTest.o
  "_gcry_strsource", referenced from:
      _aesTest in aesTest.o
  "_gcry_cipher_setkey", referenced from:
      _aesTest in aesTest.o
  "_gcry_cipher_setiv", referenced from:
      _aesTest in aesTest.o
  "_gcry_cipher_encrypt", referenced from:
      _aesTest in aesTest.o
  "_gcry_cipher_decrypt", referenced from:
      _aesTest in aesTest.o
  "_gcry_cipher_close", referenced from:
      _aesTest in aesTest.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [aesTest] Error 1

**** Build Finished ****
Re: Help with using gcrypt in eclipse CDT [message #829950 is a reply to message #829935] Tue, 27 March 2012 01:46 Go to previous message
Geoff K is currently offline Geoff KFriend
Messages: 2
Registered: March 2012
Junior Member
Okay, I didn't make any changes (that I can tell) but my error message changed to the following. Note that I have verified that directory '/Applications/eclipse CDT/Includes/libgcrypt-1.5.0/src' exists. Again, this appears to be a linking problem, but I just cannot figure it out.


**** Build of configuration Debug for project aesTest ****

make all 
Building target: aesTest
Invoking: MacOS X C Linker
L"/Applications/eclipse CDT/Includes/libgcrypt-1.5.0/src" -L"/Applications/eclipse CDT/Includes/libgcrypt-1.5.0/cipher" -L"/Applications/eclipse CDT/Includes/libgpg-error-1.10/src" -o "aesTest"  ./src/aesTest.o   
Finished building target: aesTest
 
/bin/sh: L/Applications/eclipse CDT/Includes/libgcrypt-1.5.0/src: No such file or directory
make: [aesTest] Error 127 (ignored)

**** Build Finished ****
Previous Topic:Compiler headers for multiple targets
Next Topic:CDT developer - How do I set the buildPath on a Standard Make Project
Goto Forum:
  


Current Time: Wed Sep 25 14:08:07 GMT 2024

Powered by FUDForum. Page generated in 0.03163 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top