The "undefined references" are defined in a header file called "aes.h". It seems to me that the header is linking but I still get the errors. Any ideas? Here is the complete compiler log and the complete file "aes.h":
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\projects\project1\Makefile.win"
Finding dependencies for file: C:\Dev-Cpp\projects\project1\aesxam.c
Executing make...
make.exe -f "C:\Dev-Cpp\projects\project1\Makefile.win" all
g++.exe ../Dev-Cpp/aesxam.o -o "..\Dev-Cpp\nospaces.exe" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/lib"
../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x199): undefined reference to `aes_encrypt'
../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x297): undefined reference to aes_encrypt'
../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x323): undefined reference toaes_encrypt'
../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x414): undefined reference to aes_decrypt'
../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x4e0): undefined reference toaes_decrypt'
../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x5a2): undefined reference to aes_decrypt'
../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x707): undefined reference togen_tabs'
../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x8f5): undefined reference to aes_encrypt_key'
../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x94a): undefined reference toaes_decrypt_key'
collect2: ld returned 1 exit status
make.exe: *** [../Dev-Cpp/nospaces.exe] Error 1
Execution terminated
/*
Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.
LICENSE TERMS
The free distribution and use of this software in both source and binary
form is allowed (with or without changes) provided that:
distributions of this source code include the above copyright
notice, this list of conditions and the following disclaimer;
distributions in binary form include the above copyright
notice, this list of conditions and the following disclaimer
in the documentation and/or other associated materials;
the copyright holder's name is not used to endorse products
built using this software without specific written permission.
ALTERNATIVELY, provided that this notice is retained in full, this product
may be distributed under the terms of the GNU General Public License (GPL),
in which case the provisions of the GPL apply INSTEAD OF those given above.
DISCLAIMER
This software is provided 'as is' with no explicit or implied warranties
in respect of its properties, including, but not limited to, correctness
and/or fitness for purpose.
Issue 1/08/2005
This file contains the definitions required to use AES in C. See aesopt.h
for optimisation details.
*/
ifndef _AES_H
define _AES_H
include <stdlib.h>
/ This include is used to find 8 & 32 bit unsigned integer types /
include "tdefs.h"
if defined(__cplusplus)
extern "C"
{
endif
define AES_128 / define if AES with 128 bit keys is needed /
define AES_192 / define if AES with 192 bit keys is needed /
define AES_256 / define if AES with 256 bit keys is needed /
define AES_VAR / define if a variable key size is needed /
define AES_MODES / define if support is needed for modes /
/ The following must also be set in assembler files if being used /
define AES_ENCRYPT / if support for encryption is needed /
define AES_DECRYPT / if support for decryption is needed /
define AES_REV_DKS / define to reverse decryption key schedule /
define AES_BLOCK_SIZE 16 / the AES block size in bytes /
define N_COLS 4 / the number of columns in the state /
/ The key schedule length is 11, 13 or 15 16-byte blocks for 128, /
/ 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes /
/ or 44, 52 or 60 32-bit words. /
if defined( AES_VAR ) || defined( AES_256 )
define KS_LENGTH 60
elif defined( AES_192 )
define KS_LENGTH 52
else
define KS_LENGTH 44
endif
if defined( AES_ERR_CHK )
define aes_rval int_ret
else
define aes_rval void_ret
endif
/ the character array 'inf' in the following structures is used /
/ to hold AES context information. This AES code uses cx->inf.b[0]/
/ to hold the number of rounds multiplied by 16. The other three /
/ elements can be used by code that implements additional modes /
typedef union
{ uint_32t l;
uint_8t b[4];
} aes_inf;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2005-09-03
Headers are not linked, they are included and compiled. They also do not contain the code you need to link, only declarations that satisfy the compiler. The compiler leaves blank unresolved references in the object code that at=re later resolved by the linker. The linker searches for the references in all the linked object code and libraries.
The line :
g++.exe ../Dev-Cpp/aesxam.o -o "..\Dev-Cpp\nospaces.exe" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/lib"
is what does the linking, there is only one object file, and no libraries. You need to add the library associated with aes.h to your project.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks a lot, Clifford. It's been a while since I tried anything with C. I had read the FAQ but I guess the concept of libraries had escaped memory. I kept trying to find .a or .lib then finally figured out there were files without those extensions that comprised the library and got the program to compile. Yee haw!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I originally wrote that section in the FAQ thread because we would (and still do) see a lot of questions of the form:
"Where do I get a header to do ..."
I understand some of the confusion. When we first start writing stuff, and start including iostream and the like, we don't have to worry about linking the standard library, its done for us automatically. So, we start to think of the magic as being in the header. It happened to me that way anyway. I had hoped that that section of the FAQ would keep others from my foolishness.
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Take a moment and check out the thread "FAQ - Please Read Before Asking A Question" - in particular the section on the compile log, including headers and linking libraries. It may help get the concepts of headers and libraries a little more clear.
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The "undefined references" are defined in a header file called "aes.h". It seems to me that the header is linking but I still get the errors. Any ideas? Here is the complete compiler log and the complete file "aes.h":
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\projects\project1\Makefile.win"
Finding dependencies for file: C:\Dev-Cpp\projects\project1\aesxam.c
Executing make...
make.exe -f "C:\Dev-Cpp\projects\project1\Makefile.win" all
g++.exe ../Dev-Cpp/aesxam.o -o "..\Dev-Cpp\nospaces.exe" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/lib"
../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x199): undefined reference to `aes_encrypt'
../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x297): undefined reference to
aes_encrypt' ../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x323): undefined reference toaes_encrypt'../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x414): undefined reference to
aes_decrypt' ../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x4e0): undefined reference toaes_decrypt'../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x5a2): undefined reference to
aes_decrypt' ../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x707): undefined reference togen_tabs'../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x8f5): undefined reference to
aes_encrypt_key' ../Dev-Cpp/aesxam.o:aesxam.c:(.text+0x94a): undefined reference toaes_decrypt_key'collect2: ld returned 1 exit status
make.exe: *** [../Dev-Cpp/nospaces.exe] Error 1
Execution terminated
/*
Copyright (c) 2003, Dr Brian Gladman, Worcester, UK. All rights reserved.
LICENSE TERMS
The free distribution and use of this software in both source and binary
form is allowed (with or without changes) provided that:
distributions of this source code include the above copyright
notice, this list of conditions and the following disclaimer;
distributions in binary form include the above copyright
notice, this list of conditions and the following disclaimer
in the documentation and/or other associated materials;
the copyright holder's name is not used to endorse products
built using this software without specific written permission.
ALTERNATIVELY, provided that this notice is retained in full, this product
may be distributed under the terms of the GNU General Public License (GPL),
in which case the provisions of the GPL apply INSTEAD OF those given above.
DISCLAIMER
This software is provided 'as is' with no explicit or implied warranties
in respect of its properties, including, but not limited to, correctness
and/or fitness for purpose.
Issue 1/08/2005
This file contains the definitions required to use AES in C. See aesopt.h
for optimisation details.
*/
ifndef _AES_H
define _AES_H
include <stdlib.h>
/ This include is used to find 8 & 32 bit unsigned integer types /
include "tdefs.h"
if defined(__cplusplus)
extern "C"
{
endif
define AES_128 / define if AES with 128 bit keys is needed /
define AES_192 / define if AES with 192 bit keys is needed /
define AES_256 / define if AES with 256 bit keys is needed /
define AES_VAR / define if a variable key size is needed /
define AES_MODES / define if support is needed for modes /
/ The following must also be set in assembler files if being used /
define AES_ENCRYPT / if support for encryption is needed /
define AES_DECRYPT / if support for decryption is needed /
define AES_ERR_CHK / for parameter checks & error return codes /
define AES_REV_DKS / define to reverse decryption key schedule /
define AES_BLOCK_SIZE 16 / the AES block size in bytes /
define N_COLS 4 / the number of columns in the state /
/ The key schedule length is 11, 13 or 15 16-byte blocks for 128, /
/ 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes /
/ or 44, 52 or 60 32-bit words. /
if defined( AES_VAR ) || defined( AES_256 )
define KS_LENGTH 60
elif defined( AES_192 )
define KS_LENGTH 52
else
define KS_LENGTH 44
endif
if defined( AES_ERR_CHK )
define aes_rval int_ret
else
define aes_rval void_ret
endif
/ the character array 'inf' in the following structures is used /
/ to hold AES context information. This AES code uses cx->inf.b[0] /
/ to hold the number of rounds multiplied by 16. The other three /
/ elements can be used by code that implements additional modes /
typedef union
{ uint_32t l;
uint_8t b[4];
} aes_inf;
typedef struct
{ uint_32t ks[KS_LENGTH];
aes_inf inf;
} aes_encrypt_ctx;
typedef struct
{ uint_32t ks[KS_LENGTH];
aes_inf inf;
} aes_decrypt_ctx;
/ This routine must be called before first use if non-static /
/ tables are being used /
aes_rval gen_tabs(void);
/ Key lengths in the range 16 <= key_len <= 32 are given in bytes, /
/ those in the range 128 <= key_len <= 256 are given in bits /
if defined( AES_ENCRYPT )
if defined(AES_128) || defined(AES_VAR)
aes_rval aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]);
endif
if defined(AES_192) || defined(AES_VAR)
aes_rval aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]);
endif
if defined(AES_256) || defined(AES_VAR)
aes_rval aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]);
endif
if defined(AES_VAR)
aes_rval aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1]);
endif
aes_rval aes_encrypt(const unsigned char in, unsigned char out, const aes_encrypt_ctx cx[1]);
endif
if defined( AES_DECRYPT )
if defined(AES_128) || defined(AES_VAR)
aes_rval aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]);
endif
if defined(AES_192) || defined(AES_VAR)
aes_rval aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]);
endif
if defined(AES_256) || defined(AES_VAR)
aes_rval aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]);
endif
if defined(AES_VAR)
aes_rval aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]);
endif
aes_rval aes_decrypt(const unsigned char in, unsigned char out, const aes_decrypt_ctx cx[1]);
endif
if defined(AES_MODES)
aes_rval aes_ecb_encrypt(const unsigned char ibuf, unsigned char obuf,
int len, const aes_encrypt_ctx cx[1]);
aes_rval aes_ecb_decrypt(const unsigned char ibuf, unsigned char obuf,
int len, const aes_decrypt_ctx cx[1]);
aes_rval aes_cbc_encrypt(const unsigned char ibuf, unsigned char obuf,
int len, unsigned char *iv, const aes_encrypt_ctx cx[1]);
aes_rval aes_cbc_decrypt(const unsigned char ibuf, unsigned char obuf,
int len, unsigned char *iv, const aes_decrypt_ctx cx[1]);
aes_rval aes_mode_reset(aes_encrypt_ctx cx[1]);
aes_rval aes_cfb_encrypt(const unsigned char ibuf, unsigned char obuf,
int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
aes_rval aes_cfb_decrypt(const unsigned char ibuf, unsigned char obuf,
int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
define aes_ofb_encrypt aes_ofb_crypt
define aes_ofb_decrypt aes_ofb_crypt
aes_rval aes_ofb_crypt(const unsigned char ibuf, unsigned char obuf,
int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
typedef void cbuf_inc(unsigned char *cbuf);
define aes_ctr_encrypt aes_ctr_crypt
define aes_ctr_decrypt aes_ctr_crypt
aes_rval aes_ctr_crypt(const unsigned char ibuf, unsigned char obuf,
int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1]);
endif
if defined(__cplusplus)
}
endif
endif
Headers are not linked, they are included and compiled. They also do not contain the code you need to link, only declarations that satisfy the compiler. The compiler leaves blank unresolved references in the object code that at=re later resolved by the linker. The linker searches for the references in all the linked object code and libraries.
The line :
g++.exe ../Dev-Cpp/aesxam.o -o "..\Dev-Cpp\nospaces.exe" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/lib"
is what does the linking, there is only one object file, and no libraries. You need to add the library associated with aes.h to your project.
Clifford
Thanks a lot, Clifford. It's been a while since I tried anything with C. I had read the FAQ but I guess the concept of libraries had escaped memory. I kept trying to find .a or .lib then finally figured out there were files without those extensions that comprised the library and got the program to compile. Yee haw!
I originally wrote that section in the FAQ thread because we would (and still do) see a lot of questions of the form:
"Where do I get a header to do ..."
I understand some of the confusion. When we first start writing stuff, and start including iostream and the like, we don't have to worry about linking the standard library, its done for us automatically. So, we start to think of the magic as being in the header. It happened to me that way anyway. I had hoped that that section of the FAQ would keep others from my foolishness.
Wayne
Take a moment and check out the thread "FAQ - Please Read Before Asking A Question" - in particular the section on the compile log, including headers and linking libraries. It may help get the concepts of headers and libraries a little more clear.
Wayne