library compilation undefined reference to extern function

René Berber
Sun Mar 6 23:27:00 GMT 2016

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

> #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
> $ gcc -shared -o 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++ 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:
Unsubscribe info:

More information about the Cygwin mailing list