gfxgfx
 
Please login or register.

Login with username, password and session length
 
gfx gfx
gfx
1617 Posts in 535 Topics by 779 Members - Latest Member: rhoronjeff@comcast.net December 05, 2022, 01:15:55 PM
*
gfx* Home | Help | Search | Login | Register | gfx
gfx
Absoft User Forum  |  Support  |  Windows  |  Fortran linking, DLLs, Visual Basic and more
gfx
gfxgfx
 

Author Topic: Fortran linking, DLLs, Visual Basic and more  (Read 16337 times)

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Fortran linking, DLLs, Visual Basic and more
« on: May 17, 2007, 07:31:27 PM »
We've lost the old Forum, but we haven't lost all the useful hints. I saved some about DLLs and Absoft Windows Fortran glitches at www.winsteps.com/absoft.htm. And how to access huge files at www.winsteps.com/g4.htm
The most frequent difficulty on the old Forum was name mis-matches in the linking stage. And the answer is to use a ".als" alias file to equate different manifestations of the same name. Example:

Unreferenced external symbols
# link error: undefined symbol - _GetSystemInfo

Add references to your link alias .als file, and "add" your .als to the linker options
from: to:
_GetSystemMenu _GetSystemMenu@8
unicode.als in the LIB directory tells you what "to:" should be or do a search through your .lib and .obj files and then look at them with a NotePad to see the correct form of the name.

Diego

  • Newbie
  • *
  • Posts: 1
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #1 on: June 06, 2007, 06:39:21 PM »
Hi, I am using Absoft on a PC/ WinXP platform working right now
with the Absoft editor. I would like to know how do I link the
math libraries BLAS and LAPACK (I use two lin.alg. subroutines) ?

The default compile line is: f95 -q 
I've tried: f95 -q -blas=lapack -w unix.lib lapack.lib

I get the compiler mesages:
error LNK2001: unresolved external symbol _DGETRF
error LNK2001: unresolved external symbol _DGETRS
unix.exe: fatal error LNK1120: 2 unresolved externals

If anyone knows how to link these libs correctly, please let
me know.

Thanks a lot !
Diego.

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #2 on: June 07, 2007, 07:03:38 PM »
Diego, this sounds to be the most common problem encountered with Absoft Fortran - mismatched external names. Use NotePad to create a .als file (a text file). This file has the format:
Unmatched-name    What-the-name-should-be

For instance, _DGETRF - look in your lapack.lib file (using NotePad or whatever) to find the correct name, perhaps it is dgetrf or DGETRF, then in file diego.als
_DGETRF dgetrf

add "diego.als" to your compile line.

Doug

  • Newbie
  • *
  • Posts: 8
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #3 on: November 01, 2007, 09:36:04 PM »
I have downloaded the Microsoft Visual Studio 2005 express C/C++ and am having difficulty linking C++ code with my Fortran 95 code using version 10.0.8 of the f95 compiler.  The problem is the "decoration" added to external names by the C++ compiler. I have tried using the -Gz option with the C++ compiler but the decoration remains unchanged.  The Absoft f95 compiler using STDCALL adds much less decoration (an @ followed by the stack size). Is there some way to align the names?

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #4 on: November 01, 2007, 09:47:19 PM »
Yup! There are fancy ways to solve this problem, but the easiest is our old friend the .als alias file. It is a simple text file, "doug.als" with the format:
wrong-link-name right-link-name
The "wrong-link-name" is the one that your linker can't resolve.
The "right-link-name" is the name in the .obj, .lib, .dll or whatever file produced by C++. You can look at the file with NotePad to see the exactly correct name.
Then include the doug.als file in your link step, just like a .lib or .obj file. where there are probably already some .als such as "unicode.als" or "mrwe.als"
If this doesn't work, try this (because "wrong" and "right" depend on your perspective):
right-link-name wrong-link-name
« Last Edit: November 01, 2007, 09:49:38 PM by Mike Linacre »

Doug

  • Newbie
  • *
  • Posts: 8
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #5 on: November 01, 2007, 11:33:19 PM »
Thank you Mike, but I did try that based on your response to Diego. I tried from both perspectives, with the same result.  The error message from the linker was:

doug.als : fatal error LNK1107: invalid or corrupt file: cannot read at 0x80

The als file from the second perspective was:

?get_parameters@@YAXPAHPAN0@Z  _GET_PARAMETERS
?integrate@@YAXPAN000@Z  _INTEGRATE
?send_parameters@@YAXPAN0@Z  _SEND_PARAMETER

You suggested there are "...fancy ways..." but would version 10.1 solve my problem?

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #6 on: November 02, 2007, 03:31:09 AM »
Oops, Doug. These error messages are new to me. They look bug-like. No idea if they are fixed ....

Looks like you need to try a prettier approach: use the "Compiler Directives":
Put this in your Fortran source code (see around p. 142 of the F90/F95 Manual)
!dir$ or Cdir$
name (name="external-name") mapping between internal (Fortran) names and external (e.g., C) names

Doug

  • Newbie
  • *
  • Posts: 8
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #7 on: November 02, 2007, 02:16:20 PM »
Thank you Mike for the swift reply.  I am impressed! The compiler directives gave an error message suggesting that name changes could only be supplied to external procedures so that did not seem to work. So I had a closer look at
MSDN, using the Visual Studio 2005 Express help system, and navigating to "Format of a C++
Decorated Name", to find that the following:

int a(char){int i=3;return i;};

would result in a name like:

?a@@YAHD@Z

where this decoration is a code with meaning only for the compiler and linker!
Digging a little further, evidently C code will emit either __cdecl or __stdcall decoration. So, I
guess that means rewriting my C++ code as C code and trying again.

So, the Microsoft name decoration looks more like a feature rather than a bug. That does raise a worrying question about the  interoperability between C++ and fortran.

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #8 on: November 02, 2007, 06:41:31 PM »
Doug: I use Absoft Fortran in F77 mode with no problem interfacing with C++. So there is something strange going on here.
How about looking at the "doug.als" file with NotePad? Does it look correct? Make sure that the file has a blank line at the end. Absoft has trouble with text lines that don't complete properly.

Doug

  • Newbie
  • *
  • Posts: 8
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #9 on: November 02, 2007, 07:22:25 PM »
Mike: Yes, I looked at the doug.als file again and I deliberately had made sure there was a blank line, having run into problems when the carriage return / Line feed pair were missing. I have also added  __cdecl to the prototypes but this does nothing to change the decoration nor does the use of the /Gz compiler option.  However, in C the __cdecl does what it is supposed to do.

Now, I am doing my experimenting directly with the link command in a command window, but I have tried this using the Absoft IDE with the same results. In the Microsoft MSDN library I have yet to find any mention of a .als file but perhaps I should look a little harder. My experiments do show that C code will work so I guess I will have to rework my C++ code.

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #10 on: November 02, 2007, 10:21:38 PM »
Don't think .als is for the Microsoft "link" linker. It is for the Absoft "lnk" linker. Which linker are you using?

When compiling my C++ subroutines, here's the whole C++ command string:
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c

add example C++ code for uint64.cpp
   void U64 (LONGLONG & LL, unsigned long int & x, unsigned long int & y)
   {
         LL = UInt32x32To64(x , y);
   }

producing uint64.obj
and here is the line in my .als file (after looking at uint64.obj with NotePad):
_uint64 ?U64@@YAXAA_JAAK1@Z
since my link already includes MRWE.als, I put this line at the start of MRWE.als, rather than a separate .als file.
and the Absoft Fortran is:
CALL uint64 (LL, X, Y)

« Last Edit: November 02, 2007, 10:52:49 PM by Mike Linacre »

Doug

  • Newbie
  • *
  • Posts: 8
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #11 on: November 03, 2007, 02:56:59 PM »
Mike: Your are absolutely right. I have been using the Microsoft linker. I should have twigged to that when reviewing the options.  The Microsoft options to "link" are very different from those for the Absoft linker as identified on pages 103 - 108 of the Absoft Windows Users Guide. No wonder the linker knew nothing about aliases and .als files. I did have difficulty finding a reference to .als files in the printed version of the Guide that came in the Absoft box with the compiler. But a search in the PDF version showed references to creating a .als file in Appendix F on Visual Basic DLLs. Since I was not even thinking VB DLLs, I had skipped that appendix.

Thank you very much for being so helpful solving my problem.

Doug

  • Newbie
  • *
  • Posts: 8
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #12 on: November 03, 2007, 04:15:46 PM »
Mike: I think I have been looking at too many options lists lately. Taking a closer look at the Microsoft and Absoft linkers, I think they are the same.  The Absoft linker looks to be a 1 year earlier version of the Microsoft linker. They both are called "link.exe" and have the same list of options. In my Absoft10\bin\ subdirectory there is no lnk.exe just link.exe. The instructions given in the Absoft Windows User Guide, on page 190, for VB DLLs shows the use of "lnk" with an -aliases option pointing to an .als file. When I run the command prompt, with the absvars.bat file setting the environment variables to the Absoft directories, lnk is not recognized as a command and "link" does not have an -aliases option.

I have solved my linking problem by rewriting in C rather than C++.  This is an adequate solution for me but it would be nice to be able to use C++ over C, at least some of the time.

Mike Linacre

  • Sr. Member
  • ****
  • Posts: 259
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #13 on: November 03, 2007, 04:58:47 PM »
Thanks for the input, Doug. Then I have "lnk" installed from an earlier Absoft release. "Lnk.exe" includes Absoft copyrights, not Microsoft. So, at some point Absoft switched linker and I didn't notice .... It was still there in Absoft 9.0, so looks like the changed is in Absoft 10.0. The 10.0 documentation says "uses a platform's standard linker". What support is there in 10.0 for converting from lnk to link?


Doug

  • Newbie
  • *
  • Posts: 8
Re: Fortran linking, DLLs, Visual Basic and more
« Reply #14 on: November 04, 2007, 03:55:27 PM »
What support is there in 10.0 for converting from lnk to link?

None that I can find.The documentation simply addresses the link options on page 102 though lnk is mentioned in Appendix F. I have not seen anything to support migration from lnk to link. As an aside: I did use a HEX editor to search link.exe in the Absoft10\bin directory and found no reference to an Absoft notice but many references to microsoft and Microsoft (R) so I am pretty sure it must be the Microsoft linker.

Absoft User Forum  |  Support  |  Windows  |  Fortran linking, DLLs, Visual Basic and more
 

gfxgfx
gfx gfx
Powered by MySQL Powered by PHP Valid XHTML 1.0! Valid CSS!