delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/05/15/01:56:20

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Reply-To: Cygwin List <cygwin AT cygwin DOT com>
Message-Id: <6.1.0.6.0.20040515005548.03207c80@127.0.0.1>
X-Sender:
Date: Sat, 15 May 2004 01:05:44 -0400
To: Richard Heintze <sieg_heintze AT yahoo DOT com>, cygwin AT cygwin DOT com
From: Larry Hall <cygwin-lh AT cygwin DOT com>
Subject: Re: Calling g77 FORTRAN code from MSVC 7?
In-Reply-To: <20040514210401.20178.qmail@web50307.mail.yahoo.com>
References: <20040514210401 DOT 20178 DOT qmail AT web50307 DOT mail DOT yahoo DOT com>
Mime-Version: 1.0

At 05:04 PM 5/14/2004, you wrote:
>I've searched the web, I've looked at the FAQ. I spent
>all day yesterday trying to figure this out myself and
>I am close.
>I just downloaded the complete cygwin about a month
>ago so everything should be pretty recent.
>
>I can call my g77 code (sum.f) from g++ by creating a
>dll and calling the dll from g++ code. Hurray! Now I
>want to do the same thing from MSVC7.
>
>>From the cygwin/bash command prompt I do:
>g77 -c  -mrtd -O2  -o sum.o sum.f
>dllwrap -s --export-all --output-def sum.def --def
>sum2.def --output-lib sum.lib  --driver-name g77 -o
>sum.dll sum.o 
>
>Both sum.def and sum2.def contain the same contents:
>; dlltool --base-file
>/cygdrive/c/DOCUME~1/ADMINI~1/LOCALS~1/Temp/cc001596.base
>--output-exp sum.exp --dllname sum.dll --output-def
>sum.def --exclude-symbol=_cygwin_dll_entry AT 12 --def
>sum2.def --output-lib sum.lib
>EXPORTS
>    avg_ @ 1
>    summer_ @ 2
>
>>From the dos (cmd.exe) command prompt, I use the
>following commands:
>
>
>cl main.cpp   /c /MLd /W3 /Gm /GX /ZI /Od /D WIN32 /D
>_DEBUG /D _CONSOLE /D _MBCS /FD /GZ /GR /D NOPROMPT
>cl main.obj sum.lib /link /out:sum.exe 
>/subsystem:console /incremental:yes 
>
>No errors until I run it and get an access violation
>when I can my fortran functions.
>
>So then I enhanced main.cpp with the following code:
>
>  HMODULE hLib=LoadLibraryA("c:\\Documents and
>Settings\\Administrator\\Desktop\\Examples\\sum\\sum.dll");
>  if(hLib){
>    cout << "load libary worked!" << endl;
>  } else {
>    cout << "load library failed!"<< endl;
>  }


Yeah, that won't work for Cygwin DLLs because cygwin1.dll cannot be 
explicitly/dynamically loaded by a non-cygwin program.


>This dies without an error message. This code works
>when I call a C DLL generated with MSVC7, however.
>
>Here is how I declare my functions: 
>extern "C"  float summer_(float*, int*);
>extern "C"  float avg_(float*, int*);
>
>I tried experiment with __stdcall with no luck.
>
>This should work, right? The whole point of inventing
>libtool and dllwrap is to create DLLs instead of unix
>style shared object files, correct?
>
>I found an example at the MinGW that demonstrated
>calling g77 code from Excel, but this example does not
>work with Excel 2002. This tells me that what someone
>has done what I am trying to to.


You may simply be getting tripped up by mismatches between
the Cygwin (C runtime) DLL and the MS one.  Assuming you 
don't need access to the POSIX functionality of Cygwin, you're
better off working with the MinGW versions.  But using MinGW
would put it off-topic for this list so I'd recommend following
up at their site instead if you still have problems.  If you 
need Cygwin's POSIX layer then you need to link against the
library you made (i.e. don't use LoadLibrary) and make sure 
that you're not mixing and matching your C runtime heap calls.
That's deadly.


--
Larry Hall                              http://www.rfk.com
RFK Partners, Inc.                      (508) 893-9779 - RFK Office
838 Washington Street                   (508) 893-9889 - FAX
Holliston, MA 01746                     


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019