public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* -lm and -lm64 problems
@ 2011-12-18 13:30 Xianwen Chen
  2011-12-18 14:17 ` Miles Bader
  0 siblings, 1 reply; 3+ messages in thread
From: Xianwen Chen @ 2011-12-18 13:30 UTC (permalink / raw)
  To: gcc-help

Hi,

I wrote a simple C script in which sqrt() is used. The program
compiles fine on Debian i686; however, on Ubuntu 11.10 AMD64, it can't
be compiled:

1) if I compile it as 'gcc -Wall -g -m64 -lm64 -o foo foo.c', it complains:
/usr/bin/ld: cannot find -lm64
collect2: ld returned 1 exit status

2) if I compile it as 'gcc -Wall -g -m64  -o foo foo.c', or 'gcc -Wall
-g -m32 -lm -o foo foo.c', it complains:
/dir/to/foo.c:15: undefined reference to `sqrt'
collect2: ld returned 1 exit status

Can someone offer me a hint? Thanks.

Kind regards,

Xianwen

--
Please notice that my previous email address v9@dr.com is no longer accessible.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: -lm and -lm64 problems
  2011-12-18 13:30 -lm and -lm64 problems Xianwen Chen
@ 2011-12-18 14:17 ` Miles Bader
  2011-12-18 14:21   ` Xianwen Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Miles Bader @ 2011-12-18 14:17 UTC (permalink / raw)
  To: Xianwen Chen; +Cc: gcc-help

Xianwen Chen <xianwen.chen@gmail.com> writes:
> 1) if I compile it as 'gcc -Wall -g -m64 -lm64 -o foo foo.c', it complains:
> /usr/bin/ld: cannot find -lm64
> collect2: ld returned 1 exit status

You should use "-lm" (not "-lm64"), regardless of -m64 or -m32
... and:

> 2) if I compile it as 'gcc -Wall -g -m64  -o foo foo.c', or 'gcc -Wall
> -g -m32 -lm -o foo foo.c', it complains:
> /dir/to/foo.c:15: undefined reference to `sqrt'
> collect2: ld returned 1 exit status

"-lm" should go _after_ anything that uses it.

So:  gcc -Wall -g -m64 -o foo foo.c -lm
or:  gcc -Wall -g -m32 -o foo foo.c -lm

-Miles

-- 
Year, n. A period of three hundred and sixty-five disappointments.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: -lm and -lm64 problems
  2011-12-18 14:17 ` Miles Bader
@ 2011-12-18 14:21   ` Xianwen Chen
  0 siblings, 0 replies; 3+ messages in thread
From: Xianwen Chen @ 2011-12-18 14:21 UTC (permalink / raw)
  To: Miles Bader; +Cc: gcc-help

Now it compiles just fine. Thank you very much Miles.

Xianwen

On Sun, Dec 18, 2011 at 7:17 AM, Miles Bader <miles@gnu.org> wrote:
>
> Xianwen Chen <xianwen.chen@gmail.com> writes:
> > 1) if I compile it as 'gcc -Wall -g -m64 -lm64 -o foo foo.c', it complains:
> > /usr/bin/ld: cannot find -lm64
> > collect2: ld returned 1 exit status
>
> You should use "-lm" (not "-lm64"), regardless of -m64 or -m32
> ... and:
>
> > 2) if I compile it as 'gcc -Wall -g -m64  -o foo foo.c', or 'gcc -Wall
> > -g -m32 -lm -o foo foo.c', it complains:
> > /dir/to/foo.c:15: undefined reference to `sqrt'
> > collect2: ld returned 1 exit status
>
> "-lm" should go _after_ anything that uses it.
>
> So:  gcc -Wall -g -m64 -o foo foo.c -lm
> or:  gcc -Wall -g -m32 -o foo foo.c -lm
>
> -Miles
>
> --
> Year, n. A period of three hundred and sixty-five disappointments.




--
Please notice that my previous email address v9@dr.com is no longer accessible.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-12-18 14:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-18 13:30 -lm and -lm64 problems Xianwen Chen
2011-12-18 14:17 ` Miles Bader
2011-12-18 14:21   ` Xianwen Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).