This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: library compilation undefined reference to extern function


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]