delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2016/03/06/18:28:08

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:to:from:subject:date:message-id:references
:reply-to:mime-version:content-type:content-transfer-encoding
:in-reply-to; q=dns; s=default; b=ggXUW4DGb25BAYCjCxH1jqLbv0pyuX
m53iAFe98Edaqv8SYDtf07zXS68QPu6mISaaGQLpwJcO2uS3uBd8fzlNHqWYnFdv
DEZU/q5AYee/4PwPtZQ6JhbMLPx4LxiD8WpSHqwIseQAfIZx50pgRy9cP74nO5UV
qnaEkCT0ad4PU=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:to:from:subject:date:message-id:references
:reply-to:mime-version:content-type:content-transfer-encoding
:in-reply-to; s=default; bh=SWCATsaKej9gla1JhVWbgdZ8PSM=; b=smqx
GyYOP7E7eXKCMAGtWGQ43yRieTxogF2HT4prkfyJR7A7+wGlT5ShWp/l3YeApQFm
7awYCAoGAlschl18ZvfKR6u1IxtPH6ckEhfR/1JI7Lftoox94h7uy6olOzbZBtod
DHXkdL1hgiHYqFSi6MSxkFoOuUnbnzUM4iHEhtM=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.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
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=2.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM,FSL_HELO_BARE_IP_2,RCVD_IN_DNSWL_LOW,RCVD_NUMERIC_HELO,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=no version=3.3.2 spammy=wherever, filenamecc, filenameo, libfoo.so
X-HELO: plane.gmane.org
To: cygwin AT cygwin DOT com
From: =?UTF-8?Q?Ren=c3=a9_Berber?= <rene DOT berber AT gmail DOT com>
Subject: Re: library compilation undefined reference to extern function
Date: Sun, 6 Mar 2016 17:26:33 -0600
Lines: 33
Message-ID: <nbied2$hns$1@ger.gmane.org>
References: <1129585202 DOT 10528386 DOT 1457303233509 DOT JavaMail DOT zimbra AT desy DOT de>
Reply-To: Do not reply <rene DOT berber AT gmail DOT com>
Mime-Version: 1.0
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.19) Gecko/20081209 Lightning/0.9 Thunderbird/2.0.0.19 Mnenhy/0.7.6.0
In-Reply-To: <1129585202.10528386.1457303233509.JavaMail.zimbra@desy.de>
X-IsSubscribed: yes

On 3/6/2016 4:27 PM, Azatyan, Anushavan wrote:

[snip]
> #include <iostream>
> using namespace std;
> extern void foo(void);
> int main()
> {
>         cout<<" Print ";
>         foo();
>         return 0;
> }
> 
> a very simple example I can compile in linux (Ubuntu) without any
problem, but in cygwin it goes with linker errors - undefined reference,
in both systems I use
> 
> $ gcc -c -Wall -fpic filename.cc
> $ gcc -shared -o libfoo.so filename.o

Besides the obvious (dynamic libraries in Windows do not have a .so
extension, but a .dll ext.) the linker in Windows does not allow
undefined references, so your second command should look like:

$ gcc -shared -o libfoo.dll filename.o -lstdc++
filename.o:filename.cc:(.text+0x23): undefined reference to `foo()'
collect2: error: ld returned 1 exit status

obviously you still have an undefined foo().  You have to provide it,
wherever it may be.
-- 
René Berber



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

- Raw text -


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