This is the mail archive of the cygwin 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]
Other format: [Raw text]

Re: Calling g77 FORTRAN code from MSVC 7?


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


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