Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 03-29-2004, 06:42 PM   #1
LQ Newbie
Registered: Sep 2003
Posts: 12

Rep: Reputation: 0
Problem with linking libraries using gcc

I'm doing a project for my CS2204 Unix class, and I'm having problems with the -L and -l options that go with gcc. I have this file structure set up in my home directory


There's a function in myutil.c called encrypt(). I call this function from main() which is in myshell.c. The function's prototype is in myutil.h.

The problem comes when I try to build the program. I cd to ~/p4/src/ and call make. In the makefile, it executes the command

gcc -I ../include -L ../libsrc -l util myshell.c -o myshell

The output I get from the command is this...

/tmp/cceOFU2Y.o(.text+0x18): In function `main':
: undefined reference to `encrypt'
collect2: ld returned 1 exit status
make: *** [all] Error 1

I'm positive that it is all syntactically correct. I've tested it in Visual Studios .NET 2003. I don't know why I can't get it to link. Oh, also, before I run make, I cd to ~/p4/libsrc/ and run these two commands

gcc -c myutil.c
ar rv libutil.a myutil.o

in order to build the library. Please help.
Old 03-29-2004, 08:13 PM   #2
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927Reputation: 927
I'm not sure which steps you're supposed
to be taking, but the easy way is to first
compile myutils.c into an object file:

gcc myutil.c -c -o myutil.o

And then inlcude it into myshell like

gcc myshell.c myutil.o -o myshell



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
linking problem with gcc tokernizer Programming 1 11-19-2005 12:56 PM
Linking old libraries to new one? winterhunter Linux - Software 7 10-24-2005 04:37 AM
problem on linking Xm Xt X11 libraries yaotz Linux - Newbie 9 03-07-2005 11:03 AM
Linking Libraries, Dependencies Killbot_5000 Linux - Software 4 09-28-2004 08:59 AM
Finding and Linking Static Libraries with gcc neorich Programming 15 08-10-2003 04:03 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:04 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration