Article View: be.comp.programming
Article #9959Re: gcc probleemke
From: Bart.Vanhauwaert
Date: Mon, 01 Apr 2002 09:18
Date: Mon, 01 Apr 2002 09:18
53 lines
2351 bytes
2351 bytes
Bart Vandewoestyne <Bart.Vandewoestyne@pandora.be> wrote:
> Als ik main.c probeer te compileren krijg ik:
> mc303@forsythe:~/2cw/syst_prog/practicum2$ gcc main.c
> /tmp/cc96dmS6.o: In function `main':
> /tmp/cc96dmS6.o(.text+0x5d): undefined reference to `gcd'
> /tmp/cc96dmS6.o(.text+0x83): undefined reference to `lcm'
> collect2: ld returned 1 exit status
> Het is al een tijdje geleden dat ik nog in C gewerkt heb... wat zie ik
> hier over het hoofd?
> Ik snap niet waarom mijn main geen weet heeft van die gcd en lcm
> functies...
Je moet ook nog algorithms.c compileren en dan meelinken. De volledige
volgorde van compileren is (untested)
gcc -Wall -c algorithms.c -o algorithms.o
gcc -Wall -c main.c -o main.o
gcc algorithms.o main.o -o programma
Je steekt dat alles natuurlijk het best in een Makefile (untested)
algorithms.o: algorithms.h algorithms.c
main.o: algorithms.h main.c
programma: main.o algorithms.o
gcc algorithms.o main.o -o programma
(De white space op de laatste regel _moet_ een tab zijn)
PS. Je algorithms.c file is onduidelijk omdat je perse met zo'n
result unsigned int wil bijhouden. Schrijf liever
unsigned int gcd(unsigned int a, unsigned int b)
{
if (b == 0)
return a;
else
return gcd(b,a%b);
}
of nog korter
unsigned int gcd(unsigned int a, unsigned int b)
{
return b==0 ? a : gcd(b,a%b);
}
cu bart
--
http://www.irule.be/bvh/
Technical Details
Message-ID:
<kk898a.glg.ln@ns1.irule.be>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!supernews.com!news.cs.utwente.nl!newsgate.cistron.nl!news.tele.dk!small.news.tele.dk!193.251.151.101!opentransit.net!wanadoo.fr!proxad.net!proxad.net!skynet.be!skynet.be!louie!not-for-mailReferences:
<3CA743FA.F9B401AB@pandora.be>Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII-7-bit
X-Google-Thread: fcea4,445f663aa5c7931a
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2002-04-01 07:10:43 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!supernews.com!news.cs.utwente.nl!newsgate.cistron.nl!news.tele.dk!small.news.tele.dk!193.251.151.101!opentransit.net!wanadoo.fr!proxad.net!proxad.net!skynet.be!skynet.be!louie!not-for-mail
Sender: - <bvh@ns1.irule.be>
From: Bart.Vanhauwaert@nowhere.be
Subject: Re: gcc probleemke
Newsgroups: be.comp.programming
References: <3CA743FA.F9B401AB@pandora.be>
User-Agent: tin/1.4.4-20000803 ("Vet for the Insane") (UNIX) (Linux/2.2.17-21mdksecure (i686))
Date: Mon, 1 Apr 2002 11:18:12 +0200
Message-ID: <kk898a.glg.ln@ns1.irule.be>
Lines: 53
NNTP-Posting-Host: 194.78.202.248
X-Trace: 1017673823 reader1.news.skynet.be 29692 194.78.202.248
X-Complaints-To: abuse@skynet.be