delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/05/14/17:04:27

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
Message-ID: <20040514210401.20178.qmail@web50307.mail.yahoo.com>
Date: Fri, 14 May 2004 14:04:01 -0700 (PDT)
From: Richard Heintze <sieg_heintze AT yahoo DOT com>
Subject: Calling g77 FORTRAN code from MSVC 7?
To: cygwin AT cygwin DOT com
MIME-Version: 1.0
X-IsSubscribed: yes

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;
  }

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.

  Thanks,
      Siegfried


	
		
__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/

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