LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 03-29-2004, 06:42 PM   #1
shortyzms
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

p4
libsrc
myutil.c
src
makefile
myshell.c
include
myutil.h

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
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
this:

gcc myshell.c myutil.o -o myshell


Cheers,
Tink
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:28 AM.

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