X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:date:message-id:subject:from:to :content-type; q=dns; s=default; b=TxsEns8R+HyWiLeVmyHhNGTioCXJw /S03PGz/nQ6Yg2vywEu3sqKHhlHKr0FVR2oteKVkcdEoK+OVJ1CCaC1+vZ8UKEuG kE56Fh0XueJSqe5v9OP4iW6m7zS8z9XXTEnZm15l7+y3/XlIAGIGJgCHvaj8wcQP Z70haCBA1kaZ24= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:date:message-id:subject:from:to :content-type; s=default; bh=1r9vZtTwrz27lfZFroUvks4B+mI=; b=Zkd 8ThVWAVVcESdBCfVNlbRw5NRUoerxrKtXMrzGEp8gFTsBriKtL63DaqqF7rcc8Xz mepDGy8p+EiZ8Z3zveXtHbrCwURc8cH5Cg+donrR0G3rpA5MCCHkDi3adTvDveUT LzzTK2HnnGSLrhQk5bRLyLwtKRA8RglY7xCr0AvI= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-ie0-f171.google.com MIME-Version: 1.0 X-Received: by 10.42.233.75 with SMTP id jx11mr9130080icb.22.1410524484568; Fri, 12 Sep 2014 05:21:24 -0700 (PDT) Date: Fri, 12 Sep 2014 15:21:24 +0300 Message-ID: Subject: Using DLL compiled with Cygwin inside Visual Studio 2010 From: =?UTF-8?B?15DXmdem15nXpyDXkden?= To: cygwin AT cygwin DOT com Content-Type: text/plain; charset=UTF-8 I've read already tremendous amount of articles, tutorials, and instructions about how to solve my problem - but still - no gain. I just can't put it into work. My goal is pretty simple: I want to compile a DLL file using Cygwin gcc tool, and then use it within MSVC2010. I'm actually want to do it with my own DLL code, but as for simplicity - I've tried the very basic example on Cygwin's site - and failed with that too.. What I've done so far: (Most is taken from Cygwin User's Guide, DLL section: https://cygwin.com/cygwin-ug-net/dll.html#dll-build) 1. Created mydll.c file as following: ***** mydll.c ******* #include int hello() { printf ("Hello World!\n"); } ************************ 2. Compiled mydll.c into mydll.dll using gcc -c mydll.c and gcc -shared -o mydll.dll mydll.o 3. Opened an empty Win32 Console project in Visual Studio, with the following code as test.c (code taken from Oleg's code in here, and based on this) : ******** CygwinDLLTest.c ******** #include typedef int (*PFN_HELLO)(); typedef void (*PFN_CYGWIN_DLL_INIT)(); int main() { PFN_HELLO fnHello; HMODULE hLib, h = LoadLibrary(TEXT("cygwin1.dll")); PFN_CYGWIN_DLL_INIT init = (PFN_CYGWIN_DLL_INIT)GetProcAddress(h,"cygwin_dll_init"); init(); hLib = LoadLibrary (TEXT("D:\\test\\mydll.dll")); fnHello = (PFN_HELLO) GetProcAddress (hLib, "hello"); return fnHello(); } ******************************************** 4. Set the path variable on Windows system to include "Cygwin\bin\" directory. 5. Build & Run. I ended up with the following exception: 0xc0000005: Access violation reading location 0x003a0048. Here is the full MSVC2010 Debug Output: ********************************* 'CygwinDLLTest.exe': Loaded 'C:\Users\xxxx\Documents\Visual Studio 2010\Projects\CygwinDLLTest\Debug\CygwinDLLTest.exe', Symbol loaded. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\kernelBase.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'D:\Cygwin\bin\cygwin1.dll', Binary was not built with debug information. cYgFFFFFFFF 6119F510 0cYgstd 0x27a70b d 3'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', cannot find or open the PDB file. 'CygwinDLLTest.exe': Loaded 'D:\test\mydll.dll', Binary was not built with debug information. First-chance exception at 0x611075a8 in CygwinDLLTest.exe: 0xc0000005: Access violation reading location 0x003a0048 Unhandled exception at 0x611075a8 in CygwinDLLTest.exe: 0xc0000005: Access violation reading location 0x003a0048 The program '[784] CygwinDLLTest.exe: Native' has exited with code 0 (0x0). ********************************* Now, it's important to notice that the problem wasn't loading those DLL's, as their handlers all got an address different from NULL. The line in the code that cause the exception, was the call to the hello func, inside the DLL file. And before you go and say anything about extern "C" or __declspec(dllimport/dllexport) - won't help. I've tried all of them and it didn't help. (although, AFAIK - I'm using Explicit Linking in terms of MS, orDynamic Loading in terms of UNIX, so __declspec(dllimport/dllexport) is not necessary). I'm really hope the problem is not at the stack definition, as lying over here: "Make sure you have 4K of scratch space at the bottom of your stack" Because I've no clue how to make this happen on MSVC2010 (and apparently, neither do Oleg...:) Now, I know there's a direct reference to my problem in Hans Passant's words over here - still - I couldn't understand how to solve my problem. PS - for whomever wants, this my DLL Dumpbin.exe output: ********************************* Microsoft (R) COFF/PE Dumper Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file D:\test\mydll.dll File Type: DLL Section contains the following exports for mydll.dll 00000000 characteristics 0 time date stamp Thu Jan 01 02:00:00 1970 0.00 version 1 ordinal base 1 number of functions 1 number of names ordinal hint RVA name 1 0 00001120 hello Summary 1000 .bss 1000 .data 1000 .debug_abbrev 1000 .debug_aranges 6000 .debug_info 1000 .debug_line 1000 .debug_loc 1000 .debug_ranges 1000 .debug_str 1000 .edata 1000 .eh_frame 1000 .idata 1000 .rdata 1000 .reloc 1000 .text ********************************* Thank you in advance! -- 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