Thread: RC4 compile error!! Please little help

  1. #1
    Registered User
    Join Date
    Jan 2006

    RC4 compile error!! Please little help

    Hi all,

    I'm trying to encrypt some data using the openssl RC4, but it doesn't seem to work and i have no clue why.
    This is what is happening: I wrote this little and easy program to test the RC4 methods.

    #include <openssl/rc4.h>
    int main()
    	const unsigned char chave[] = {0x34, 0x35, 0x36, 0x37};
    	RC4_KEY key;
    	int len = 4;
    	RC4_set_key(&key, len, chave);
    	return 0;
    But this is what I get when trying to compile:

    breno@lcpi5:~/cmuf/webserver/teste$ gcc cripto.c -Wall -o cripto
    /tmp/ccOCNi48.o: In function `main':cripto.c.text+0x39): undefined reference to `RC4_set_key'
    collect2: ld returned 1 exit status

    I can't understand why i'm getting this error, since this is the code for /openssl/rc4.h

    #ifndef HEADER_RC4_H
    #define HEADER_RC4_H
    #include <openssl/opensslconf.h> /* OPENSSL_NO_RC4, RC4_INT */
    #ifdef OPENSSL_NO_RC4
    #error RC4 is disabled.
    #ifdef  __cplusplus
    extern "C" {
    typedef struct rc4_key_st
    	RC4_INT x,y;
    	RC4_INT data[256];
    	} RC4_KEY;
    const char *RC4_options(void);
    void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
    void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
    		unsigned char *outdata);
    #ifdef  __cplusplus
    Can anyone give me a hint of what might be happening!?!
    Thanks a lot
    Breno Kastrup

  2. #2
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Umeň, Sweden
    The linker can't find the function RC4_set_key, you probably forgot to compile it with the library.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    breno@lcpi5:~/cmuf/webserver/teste$ gcc cripto.c -Wall -o cripto
    Compile all your source files one by one, and then link them:
    $ gcc -W -Wall -c cripto.c
    $ gcc -W -Wall -c setkey.c
    $ gcc -O2 -o cripto cripto.o setkey.o
    $ ./cripto

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Jan 2006
    YEAH, I forgot to link the lib with -lssl.

    It works now, Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C and C++ compile speed
    By swgh in forum A Brief History of
    Replies: 3
    Last Post: 01-02-2007, 02:37 PM
  2. Compile as you type
    By Rocketmagnet in forum A Brief History of
    Replies: 33
    Last Post: 12-07-2006, 01:36 PM
  3. How to compile mfc libs from platform sdk
    By tjcbs in forum Windows Programming
    Replies: 6
    Last Post: 11-19-2006, 08:20 AM
  4. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 09:05 PM
  5. How can I compile C or C++ with Visual Studio .NET?
    By Dakkon in forum C Programming
    Replies: 8
    Last Post: 02-11-2003, 02:58 PM