X-Recipient: archive-cygwin@delorie.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@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.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@cygwin.com
From: =?UTF-8?Q?Ren=c3=a9_Berber?= <rene.berber@gmail.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.10528386.1457303233509.JavaMail.zimbra@desy.de>
Reply-To: Do not reply <rene.berber@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
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

