public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* linking multiple function from .lib to CYGWIN
@ 2023-07-14  8:51 Mümin A.
  2023-07-17 22:53 ` Takashi Yano
  0 siblings, 1 reply; 3+ messages in thread
From: Mümin A. @ 2023-07-14  8:51 UTC (permalink / raw)
  To: cygwin; +Cc: Beytorun25


[-- Attachment #1.1: Type: text/plain, Size: 673 bytes --]

Hi,

I can only link one function at a time in a *msvc *built library but when I
use multiple functions in the CYGWIN
compiler,  I got that error message.

int main()
{
helloWorld2();
return 0;
}

That is compiled and linked successfully.

int main()
{
helloWorld2();
helloWorld3();
return 0;
}

That is  compiled but linking throws  a bug report.

[ 50%] Linking CXX executable a.exe
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld:
internal error: aborting at
/mnt/share/cygpkgs/binutils/binutils.x86_64/src/binutils-2.40/ld/ldlang.c:527
in compare_section
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld:
please report this bug

[-- Attachment #2: fooCls.h --]
[-- Type: text/plain, Size: 459 bytes --]

#ifndef FOOCLS_H
#define FOOCLS_H

#if defined(_WIN32) || defined(__CYGWIN__)
#ifdef DLL_EXPORT
#define _WIN_DLL __declspec(dllexport)
#else
#ifdef _MSC_VER
#define _WIN_DLL __declspec(dllimport)
#else
#define _WIN_DLL
#endif
#endif
#else
#define _WIN_DLL
#endif

#ifdef __cplusplus
extern "C"
{
#endif

     _WIN_DLL  void helloWorld2(void);
     _WIN_DLL  void helloWorld3(void);

#ifdef __cplusplus
}
#endif

#endif // FOOCLS_H

[-- Attachment #3: main.cpp --]
[-- Type: text/plain, Size: 91 bytes --]

#include <fooCls.h>

int main()
{
	helloWorld2();
	
	helloWorld3();	

	return 0;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: linking multiple function from .lib to CYGWIN
  2023-07-14  8:51 linking multiple function from .lib to CYGWIN Mümin A.
@ 2023-07-17 22:53 ` Takashi Yano
       [not found]   ` <CAPxKPA6Rc2AQ6=zS2HKDr3i7LM7hziTR6NMz5MYqxvzmuZu9ag@mail.gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Yano @ 2023-07-17 22:53 UTC (permalink / raw)
  To: cygwin; +Cc: Mümin A.

On Fri, 14 Jul 2023 11:51:59 +0300
Mümin A. wrote:
> Hi,
> 
> I can only link one function at a time in a *msvc *built library but when I
> use multiple functions in the CYGWIN
> compiler,  I got that error message.
> 
> int main()
> {
> helloWorld2();
> return 0;
> }
> 
> That is compiled and linked successfully.
> 
> int main()
> {
> helloWorld2();
> helloWorld3();
> return 0;
> }
> 
> That is  compiled but linking throws  a bug report.
> 
> [ 50%] Linking CXX executable a.exe
> /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld:
> internal error: aborting at
> /mnt/share/cygpkgs/binutils/binutils.x86_64/src/binutils-2.40/ld/ldlang.c:527
> in compare_section
> /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld:
> please report this bug

Perhaps, this is a bug of gcc 11 which has been already fixed in
gcc 12.

Workaround is:
Link .dll directly instead of linking .lib if your .lib is
associated with a DLL.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: linking multiple function from .lib to CYGWIN
       [not found]   ` <CAPxKPA6Rc2AQ6=zS2HKDr3i7LM7hziTR6NMz5MYqxvzmuZu9ag@mail.gmail.com>
@ 2023-07-18 10:02     ` Takashi Yano
  0 siblings, 0 replies; 3+ messages in thread
From: Takashi Yano @ 2023-07-18 10:02 UTC (permalink / raw)
  To: cygwin; +Cc: Mümin A.

On Tue, 18 Jul 2023 11:32:53 +0300
Mümin A. wrote:
> Hi,
> 
> Thank you for prompt reply,
> 
> I couldn't find gcc 12 in the cygwin installer. How can I find it?
> 
> And, We are already linking the library dynamically. We have fooCls.dll and
> fooCls.lib files in the project.
> Is there another workaround for this problem?
> 
> Takashi Yano <takashi.yano@nifty.ne.jp>, 18 Tem 2023 Sal, 01:53 tarihinde
> şunu yazdı:
> > Perhaps, this is a bug of gcc 11 which has been already fixed in
> > gcc 12.
> >
> > Workaround is:
> > Link .dll directly instead of linking .lib if your .lib is
> > associated with a DLL.
> >
> > --
> > Takashi Yano <takashi.yano@nifty.ne.jp>

gcc 12 is not ready for cygwin.

I mean, the workaround is:
x86_64-w64-mingw32-g++ main.cpp fooCls.dll
instead of
x86_64-w64-mingw32-g++ main.cpp fooCls.lib

If you use cmake, replace fooCls.lib in your CMakelits.txt
with fooCls.dll.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-18 10:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-14  8:51 linking multiple function from .lib to CYGWIN Mümin A.
2023-07-17 22:53 ` Takashi Yano
     [not found]   ` <CAPxKPA6Rc2AQ6=zS2HKDr3i7LM7hziTR6NMz5MYqxvzmuZu9ag@mail.gmail.com>
2023-07-18 10:02     ` Takashi Yano

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).