This is the mail archive of the cygwin@sourceware.cygnus.com 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]

Using Cygwin created DLL in MSVC++?


Dongho Kim - Experimental Account writes:
 > - Is it possible to uses DLLs that are created using Cygwin
 >   from a program created using MS VC++?

Yes, but only if the DLL are created using (tools running under)
cygwin, but not use the cygwin dll itself. I.e. they should be
"mingw32" DLLs, created using gcc -mno-cygwin. If you share data
structures with the MSVC-compiled code, use -fnative-stuct also. (This
is available only in gcc-2.95 and later.)

It probably also is necessary to use the same MS C runtime in the DLL
and program, ie if the program uses msvcrt.dll, you should set up your
gcc to produce bnaries that use it, too, and not crtdll.dll, which is
the default. This might be a bit convoluted. I think it was enough to
edit the specs file. My specs file included here:
*asm:


*asm_final:


*cpp:
-remap %(cpp_cpu) %{posix:-D_POSIX_SOURCE} %{!mno-cygwin:-D__CYGWIN32__ -D__CYGWIN__} %{mno-cygwin:-iwithprefixbefore ../../../../%(mingw_include_path)/include/mingw32 -D__MSVCRT__ -D__MINGW32__=0.2}

*cc1:
%(cc1_spec) 

*cc1plus:


*endfile:


*link:
%{mwindows:--subsystem windows} %{mconsole:--subsystem console} %{mdll:--dll -e _DllMainCRTStartup@12}

*lib:
%{pg:-lgmon} %{!mno-cygwin:-lcygwin} %{mno-cygwin:-lmingw32 -lmoldname-msvc -lmsvcrt} %{mwindows:-lgdi32 -lcomdlg32} -luser32 -lkernel32 -ladvapi32 -lshell32

*libgcc:
-lgcc

*startfile:
%{mdll: %{mno-cygwin:dllcrt2%O%s}} %{!mdll: %{!mno-cygwin:crt0%O%s} %{mno-cygwin:crt2%O%s} %{pg:gcrt0%O%s}}

*switches_need_spaces:


*signed_char:
%{funsigned-char:-D__CHAR_UNSIGNED__}

*predefines:
-Di386 -D_WIN32 -DWINNT -D_X86_=1 -D__STDC__=1 -D__stdcall=__attribute__((__stdcall__)) -D__cdecl=__attribute__((__cdecl__)) -D__declspec(x)=__attribute__((x)) -Asystem(winnt) -Acpu(i386) -Amachine(i386)

*cross_compile:
0

*version:
2.95

*multilib:
. !mno-cygwin;mingw32 mno-cygwin;

*multilib_defaults:


*multilib_extra:


*multilib_matches:
mno-cygwin mno-cygwin;

*linker:
collect2

*cpp_486:
%{!ansi:-Di486} -D__i486 -D__i486__

*cpp_586:
%{!ansi:-Di586 -Dpentium} -D__i586 -D__i586__ -D__pentium -D__pentium__

*cpp_k6:
%{!ansi:-Di586 -Dk6} -D__i586 -D__i586__ -D__k6 -D__k6__

*cpp_686:
%{!ansi:-Di686 -Dpentiumpro} -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__

*cpp_cpu_default:
%(cpp_586)

*cpp_cpu:
-Acpu(i386) -Amachine(i386) %{!ansi:-Di386} -D__i386 -D__i386__ %{mcpu=i486:%(cpp_486)} %{m486:%(cpp_486)} %{mpentium:%(cpp_586)} %{mcpu=pentium:%(cpp_586)} %{mpentiumpro:%(cpp_686)} %{mcpu=pentiumpro:%(cpp_686)} %{mcpu=k6:%(cpp_k6)} %{!mcpu*:%{!m486:%{!mpentium*:%(cpp_cpu_default)}}}

*cc1_cpu:
%{!mcpu*: %{m386:-mcpu=i386 -march=i386} %{m486:-mcpu=i486 -march=i486} %{mpentium:-mcpu=pentium} %{mpentiumpro:-mcpu=pentiumpro}}

*mingw_include_path:
i586-cygwin32

*link_command:
%{!fsyntax-only: %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t} %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}} %{static:} %{L*} %D %o %{!nostdlib:%{!nodefaultlibs:%G %L %G}} %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*}
 }}}}}}

 > - Is there any way that I can debug this?

Not really, I guess.

 > - Is there any document that explains about DLL in detail?

Sorry, I don't think there is any really good one.

 >   There must be many people who tried this.
 >   (Use Cygwin created DLLs in MS VC++.)

"Use in MS VC++" is a bit vague (as I said, you can't debug them in
the MS VC++ debugger), but I certainly have used gcc-compiled DLLs
from MSVC-compiled code, and vice versa.

--tml

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

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