This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: library compilation undefined reference to extern function
- From: Renà Berber <rene dot berber at gmail dot com>
- To: cygwin at cygwin dot com
- Date: Sun, 6 Mar 2016 17:26:33 -0600
- Subject: Re: library compilation undefined reference to extern function
- Authentication-results: sourceware.org; auth=none
- 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>
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