* library compilation undefined reference to extern function
@ 2016-03-06 22:27 Azatyan, Anushavan
2016-03-06 23:27 ` René Berber
0 siblings, 1 reply; 2+ messages in thread
From: Azatyan, Anushavan @ 2016-03-06 22:27 UTC (permalink / raw)
To: cygwin
Hi,
I am compiling a huge library, which is written and compiled under Ubuntu, I have fixed some problems to get it compiled in cygwin.
The main() function is inside library. I stopped in some point which goes different in cygwin.
I have some functions which are declared as - extern void func(void); Linker gives error - undefined reference to `func()'
then I tried with this to compare differences..
#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
commands.
I could not find solution of this anywhere.
Thank you,
Best regards, Anushavan
--
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: library compilation undefined reference to extern function
2016-03-06 22:27 library compilation undefined reference to extern function Azatyan, Anushavan
@ 2016-03-06 23:27 ` René Berber
0 siblings, 0 replies; 2+ messages in thread
From: René Berber @ 2016-03-06 23:27 UTC (permalink / raw)
To: cygwin
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-03-06 23:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-06 22:27 library compilation undefined reference to extern function Azatyan, Anushavan
2016-03-06 23:27 ` René Berber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).