From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 78429 invoked by alias); 6 Mar 2016 23:27:51 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 78409 invoked by uid 89); 6 Mar 2016 23:27:50 -0000 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 Received: from plane.gmane.org (HELO plane.gmane.org) (80.91.229.3) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Sun, 06 Mar 2016 23:27:49 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1aci5P-0005Du-Kv for cygwin@cygwin.com; Mon, 07 Mar 2016 00:27:43 +0100 Received: from 189.208.17.107 ([189.208.17.107]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 07 Mar 2016 00:27:43 +0100 Received: from rene.berber by 189.208.17.107 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 07 Mar 2016 00:27:43 +0100 To: cygwin@cygwin.com From: =?UTF-8?Q?Ren=c3=a9_Berber?= Subject: Re: library compilation undefined reference to extern function Date: Sun, 06 Mar 2016 23:27:00 -0000 Message-ID: References: <1129585202.10528386.1457303233509.JavaMail.zimbra@desy.de> Reply-To: Do not reply 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 X-SW-Source: 2016-03/txt/msg00060.txt.bz2 On 3/6/2016 4:27 PM, Azatyan, Anushavan wrote: [snip] > #include > 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