Thread: using external libraries: undefined reference

  1. #1

    using external libraries: undefined reference

    It seems these "undefined reverence" things are really plaguing me. Now, i am writing a cryotographic prgram, and i am going to be implementing an MD5 hash, so i downloaded OpenSSH and installed it to ~/usr/local/ssl. Here is the command that is being executed, the errors, the filenames, and the makefile.

    Errors:
    Code:
    $ g++ -I/home/ethereal/usr/local/ssl/include -L/home/et
    hereal/usr/local/ssl/lib -a ~/usr/local/ssl/lib/libcrypto.a -lcrypto efcrypt.o -
    o efcrypt
    efcrypt.o: In function `main':
    efcrypt.o(.text+0x2f): undefined reference to `MD5'
    collect2: ld returned 1 exit status
    the files: (you'll have to trust me about whats in ./include)
    Code:
    $ ls -lA ~/usr/local/ssl/include ~/usr/local/ssl/lib
    /home/ethereal/usr/local/ssl/include:
    total 4
    drwxrwxr-x    2 ethereal ethereal     4096 May  9 22:55 openssl
    
    /home/ethereal/usr/local/ssl/lib:
    total 1868
    -rw-r--r--    1 ethereal ethereal  1641636 May  9 22:55 libcrypto.a
    -rw-r--r--    1 ethereal ethereal   255532 May  9 22:55 libssl.a
    drwxrwxr-x    2 ethereal ethereal     4096 May  9 22:55 pkgconfig
    makefile:
    Code:
    # Makefile for EFcrypt
    
    CC = g++
    CFLAGS = -I/home/ethereal/usr/local/ssl/include -L/home/ethereal/usr/local/ssl/lib -lcrypto
    
    efcrypt : efcrypt.o
            $(CC) $(CFLAGS) efcrypt.o -o efcrypt
    
    efcrypt.o : efcrypt.cpp
            $(CC) $(CFLAGS) -c efcrypt.cpp
    
    clean :
            rm -f *.o
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  2. #2
    Wow. So simple. Thanks! i'll have to remember that.

    ~Inquirer
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    2
    Hello
    i have identical problem - but i can't see a solution here
    I have also: "undefined reference to `MD5'", i'm also using g++.
    I thought, that it is an old openssl, so i downloaded the newest version 0.9.8a (i've removed the old) - doesn't work
    So i even updated the gcc to version 3.3.2 - also doesn't work.
    When i look inside the .o file i can see that name MD5 is inside, also i can see the same name in /usr/local/lib/libcrypto.a
    Besides - it compiles successfully on other linux box, but not on my debian.
    please help - i am really helpless

    regards

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Maybe you need something like
    Code:
    g++ file.cpp -o file -l/usr/local/lib/libcrypto.a
    I don't know the exact syntax.
    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.

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    2
    The problem was: i need to pass a library name just after the .o files - not before like it did. Static libraries need that - when using shared - it shouldn't matter.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Gnarly Linking Error HELP!!!!
    By brooksbp in forum C++ Programming
    Replies: 8
    Last Post: 05-04-2007, 01:00 AM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Strange/false errors
    By Ganoosh in forum Windows Programming
    Replies: 8
    Last Post: 10-20-2005, 04:54 PM
  4. Textbox
    By maxorator in forum Windows Programming
    Replies: 20
    Last Post: 09-25-2005, 10:04 AM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM