delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/11/04/05:39:23

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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
From: "Rene Nyffenegger" <rene DOT nyffenegger AT adp-gmbh DOT ch>
To: cygwin AT cygwin DOT com
Reply-To: rene DOT nyffenegger AT adp-gmbh DOT ch
Subject: Re: creating shared object (.so) with gcc under cygwin
Date: Thu, 4 Nov 2004 12:38:33 +0200
Message-Id: <20041104103812.M72091@adp-gmbh.ch>
In-Reply-To: <Pine.GSO.4.61.0411031622560.27136@slinky.cs.nyu.edu>
References: <20041103171139 DOT M29773 AT adp-gmbh DOT ch> <Pine DOT GSO DOT 4 DOT 61 DOT 0411031622560 DOT 27136 AT slinky DOT cs DOT nyu DOT edu>
X-OriginatingIP: 212.215.1.67 (rnyff)
MIME-Version: 1.0

Igor,

Thanks a lot for the clarification

Cheers,
Rene


> On Wed, 3 Nov 2004, Rene Nyffenegger wrote:
> 
> > Hello
> >
> > I am trying to create a shared object and use it in a program under
> > cygwin with gcc. I seem to miss a point. If some kind soul could help
> > me on that, I'd be very grateful.
> >
> > Here's the code for the shared object (calc_mean.c):
> >
> >   #include "calc_mean.h"
> >   double mean(double a, double b) {
> >     return (a+b) / 2;
> >   }
> >
> > Here's its header file (calc_mean.h):
> >
> >   double mean(double, double);
> >
> >
> > So, I compile that to a .so like so:
> >
> > $ gcc -shared -o libmean.so calc_mean.c
> >
> > Then, there's main.c that wants to use the shared object:
> >
> >   #include <stdio.h>
> >   #include "calc_mean.h"
> >
> >   int main(int argc, char* argv[]) {
> >     double v1, v2, m;
> >     v1 = 5.2;
> >     v2 = 7.9;
> >
> >     m  = mean(v1, v2);
> >
> >     printf("The mean of %3.2f and %3.2f is %3.2f\n", v1, v2, m);
> >     return 0;
> >   }
> >
> > I try to compile main.c like so:
> >
> > $ gcc main.c -o main -L. -lmean
> >
> > However, the following error is returned:
> > /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/../../../../i686-pc-cygwin/bin/ld:
> > cannot find -lmean
> > collect2: ld returned 1 exit status
> >
> > Obviously, I do something wrong here, but I have no idea what that could
> > be.
> 
> As Chris recommended, use the ".dll" extension for your shared libs, 
> or you can also build an import lib using
> 
> $ gcc -shared -o libmean.so -Wl,--out-implib,libmean.dll.a calc_mean.c
> 
> and your link step should work.
> 	Igor
> -- 
> 				http://cs.nyu.edu/~pechtcha/
>       |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
> ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
>      |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
>     '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!
> 
> "The Sun will pass between the Earth and the Moon tonight for a total
> Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT


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