RC4 compile error!! Please little help

This is a discussion on RC4 compile error!! Please little help within the C Programming forums, part of the General Programming Boards category; Hi all, I'm trying to encrypt some data using the openssl RC4, but it doesn't seem to work and i ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    9

    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.

    Code:
    #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

    Code:
    #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.
    #endif
    
    #ifdef  __cplusplus
    extern "C" {
    #endif
    
    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
    }
    #endif
    
    #endif
    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
    Location
    Umeň, Sweden
    Posts
    555
    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
    Location
    Canada
    Posts
    8,046
    Code:
    breno@lcpi5:~/cmuf/webserver/teste$ gcc cripto.c -Wall -o cripto
    Compile all your source files one by one, and then link them:
    Code:
    $ gcc -W -Wall -c cripto.c
    
    $ gcc -W -Wall -c setkey.c
    
    $ gcc -O2 -o cripto cripto.o setkey.o
    
    $ ./cripto
    
    $
    dwk

    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: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    9
    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 Cprogramming.com
    Replies: 3
    Last Post: 01-02-2007, 01:37 PM
  2. Compile as you type
    By Rocketmagnet in forum A Brief History of Cprogramming.com
    Replies: 33
    Last Post: 12-07-2006, 12:36 PM
  3. How to compile mfc libs from platform sdk
    By tjcbs in forum Windows Programming
    Replies: 6
    Last Post: 11-19-2006, 07:20 AM
  4. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 08: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, 01:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21