delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/05/28/10:16:33

X-Spam-Check-By: sourceware.org
From: "Dave Korn" <dave DOT korn AT artimi DOT com>
To: <cygwin AT cygwin DOT com>
References: <f3elpi$hlg$1 AT sea DOT gmane DOT org>
Subject: RE: Problem of compiling and linking the C/C++ program using WIN32API with GCC
Date: Mon, 28 May 2007 15:14:53 +0100
Message-ID: <017001c7a132$90001630$2e08a8c0@CAM.ARTIMI.COM>
MIME-Version: 1.0
X-Mailer: Microsoft Office Outlook 11
In-Reply-To: <f3elpi$hlg$1@sea.gmane.org>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
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 28 May 2007 14:42, Alain Nguyen wrote:

> Hi,
> 
> I am a new CYGWIN user.
> 
> I actually tried to compile and link a C/C++ program using the 'w32api',
> more exactly, the '/lib/w32api/libws2_32.a' library, with the following
> command:
> 
>             $gcc   -o myprogram   -lws2_32    -c myprogram.c
> 
> But, I always got the error messages from the 'ld' linker dynamic, such as:

  No you don't, not with that command, because the -c tells gcc not to invoke
the linker.  You would in fact get the error message "gcc: -lws2_32: linker
input file unused because linking not done".

> 
>     -         "Undefined reference to 'WSAcleanup AT 0'"
>     -         "Undefined reference to 'WSAstartup AT 8'"
>     -         "Undefined reference to '_inet_addr AT 4'"
>     -         "Undefined reference to '_socket AT 12'"
>     -         "Undefined reference to '_connect AT 12'"
>     -         etc...
> 
>     "collect2: ld returned 1 exit status"
> 
> This means that the linker dynamic 'ld' is unable to find and open the
> corresponding 'libws2_32.a' library file.

  Nope, it means it opens it, reads any functions out of it that are already
required by earlier inputs, closes it, then opens your program file and fails
to link.  Ordering of linker inputs is significant, dependencies must come
after the things that depend on them and generally this means that libs should
always come last.  Try

gcc   -o myprogram   myprogram.c -lws2_32    



    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....


--
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