delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/08/02/21:30:05

X-Spam-Check-By: sourceware.org
Date: Wed, 2 Aug 2006 21:29:54 -0400
From: Christopher Faylor <cgf-no-personal-reply-please AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: what is the difference of these two compile methods ?
Message-ID: <20060803012954.GC31994@trixie.casa.cgf.cx>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <bc95423d0608021734q67b5bc52x3651774154a50043 AT mail DOT gmail DOT com>
Mime-Version: 1.0
In-Reply-To: <bc95423d0608021734q67b5bc52x3651774154a50043@mail.gmail.com>
User-Agent: Mutt/1.5.11
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Thu, Aug 03, 2006 at 08:34:46AM +0800, ???? wrote:
>source file is a very simple cpp file like "hello world" whose name is 
>main.cpp
>when i compile it with:
>g++ -o test.exe main.cpp
>it works fine
>
>but when i compile it with:
> g++  -c -o main.o main.cpp
> ld -o test.exe main.o
>it will report "undefined reference" error at step 2, it looks like ld
>can not locate any library, if i replace ld with g++, it works fine.

That is absolutely correct.  ld isn't meant to be used by itself unless
you really know what you're doing and you don't really know what you're
doing.

So, use g++ for linking.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019