forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Linking 3rd pary dlls via export libraries

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
GMMitchell



Joined: 26 Aug 2005
Posts: 3

PostPosted: Thu Sep 08, 2005 7:25 am    Post subject: Linking 3rd pary dlls via export libraries Reply with quote

referring to my previous notes on this subject in which I am [still] endeavouring to link a 3rd party dll [using an export lib] to a fotran applicaiton. Success with a previous version not withstanding, I am loading the lib associated with the 3d party dll, also having to load user32.lib. With compaq visual fotran set for win32 release all is resolved, in debug mode the linker suggests that the supplied dll is corrupt. Using Salford ftn v 4.60 via plato 3 for either release or debug configuration there is no difference and the same messages appear....

Linking...
WARNING the following symbols are missing:
solveroptimize E:SPLATLink_testReleaseWin32Solver_testsmall_sdk.obj
(E:SPLATLINK_TESTSOLVER_TESTSMALL_SDK.F90)
_imp__LoadLibraryA E:SPLATSoftwarefpsdk.lib (/0 )
(.ReleaseSolverSDK.obj)
*** Imported common not satisfied: LoadLibraryA@4
_imp__GetProcAddress E:SPLATSoftwarefpsdk.lib (/0 )
(.ReleaseSolverSDK.obj)
*** Imported common not satisfied: GetProcAddress@8
_fltused E:SPLATSoftwarefpsdk.lib (/0 )
(.ReleaseSolverSDK.obj)
*** Imported common references not satisfied or Imported data missing

Why is there a difference between the compaq and Salford compilers??? Any one got any suggestions. Understandably the client is not far off pulling the plug on this project...so any solution would be very very gratefully recieved...


George Mitchell
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7926
Location: Salford, UK

PostPosted: Fri Sep 09, 2005 12:03 am    Post subject: Linking 3rd pary dlls via export libraries Reply with quote

You can use the DLL (not the LIB) when linking with SLINK.
You should also use the DLL in the /IMPORT_LIB command line option.
I thought the relevant Microsoft API was kernel32.dll but I could be wrong.

If you can reduce the problem to a few lines of Fortran (i.e. a complete program) and can send it (with the DLL) to me then I will try to find time to look at it.
Back to top
View user's profile Send private message AIM Address
mac-es



Joined: 20 May 2008
Posts: 4

PostPosted: Wed May 21, 2008 3:29 pm    Post subject: FTN95 ext.dll + Visual C++ 6.0 code Reply with quote

Not sure wheter my problem fits here...

Have to generate an FTN95 ext.dll to be called by an external program, which only can call FTN95 generated / (s)linked .dlls (no idea why). The ext.dll fortran code has C_EXTERN declarations refering to functions written in c programming language. The following steps are done:

1. Compile c code:
cl /c prog1.c
cl /c prog2.c


2. Compile ftn95 code:
ftn95 ext.f90

3. Link with slink:
slink -dll -exportall -out:ext.dll prog1.obj prog2.obj ext.obj

ext.dll is generated and slink outputs:

Code:
WARNING - Default LibMain being provided
WARNING the following symbols are missing:
_fltused                                 c:\mycode\prog1.obj
                                              (prog1.c)
_vsnprintf                               c:\mycode\prog2.obj
                                              (control.c)
_iob                                     c:\mycode\prog2.obj
                                              (prog2.c)
_imp__CreateNamedPipeA           c:\mycode\prog2.obj
                     (prog2.c)
_imp__CreateEventA           c:\mycode\prog2.obj
                     (prog2.c)
_imp__SetHandleInformation        c:\mycode\prog2.obj
                     (prog2.c)
_imp__CreatePipe           c:\mycode\prog2.obj
                     (prog2.c)
_imp__CloseHandle           c:\mycode\prog2.obj
                     (prog2.c)


The external program calls ext.dll and runs until the first unreferenced symbol / function is hit (where it exits).

So, how to include the missing references?

I tried:

1. see above

2. see above

3. Use Visual C++ link
link /DLL /NOENTRY C:\PROGRA~1\MICROS~2\VC98\Lib\KERNEL32.LIB /OUT:cprog.dll /MACHINE:X86 /EXPORT:_imp__CreateNamedPipeA /EXPORT:_imp__CreateEventA /EXPORT:_imp__SetHandleInformation /EXPORT:_imp__CreatePipe /EXPORT:_imp__CloseHandle

which produces cprog.dll cprog.exp and cprog.lib

4. slink
slink -dll -exportall -out:ext.dll cprog.dll cprog.lib cprog.exp ext.obj

Now all references exept of _fltused, _iob and _vsnprintf are satisfied (no idea where to find these) but my external programs outputs "Cannot find procedure entry point EXTERN in ext.dll" and (of course exits).

Please give me some directions where to look, since I'm completely lost now!

Thanks, Chris.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7926
Location: Salford, UK

PostPosted: Wed May 21, 2008 4:46 pm    Post subject: Reply with quote

You should only need cprog.dll (not cprog.lib and cprog.exp) when
slinking ext.dll.

It may be simpler to use SLINK (and SCC) to create cprog.dll.

In any case you need to look up the information about STDCALL
and c_decl when calling C functions from FTN95. See FTN95.chm
for further information.
Back to top
View user's profile Send private message AIM Address
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Thu May 22, 2008 9:22 am    Post subject: Reply with quote

In my experience, if you are writing your own DLL using MSVC then the easiest thing to do is to mark all of your routines as follows:

Code:

#define DllExport __declspec(dllexport)

extern "C" DllExport void _FunctionSimple()
{
   printf("%s\n",
      "_FunctionSimple called");
}


Compile the C into a DLL - and as Paul states, only use the DLL for linking, no .lib is required for SLINK.

and then in the Fortran do the following:

Code:

C_EXTERNAL FunctionSimple "_FunctionSimple"

CALL FunctionSimple()


There is an example of how to achieve this in the personal edition that is available for download (including batch file usage to demonstrate from the command line) - look for the example called 'Visual C Interoperability 2'.
Back to top
View user's profile Send private message
mac-es



Joined: 20 May 2008
Posts: 4

PostPosted: Fri May 23, 2008 10:05 am    Post subject: Reply with quote

Paul, Andrew,

thanks for the quick reply!

Using scc I get the errors listed below.

Using slink instead of link yields the same missing references (if compiled with Visual C++), so I guess I have to use scc instead of cl to compile the c code. So, any idea how to resolve the scc compiler issues?

Code:
C:\Documents and Settings\Projects\>scc prog1.c /INCLUDE C:\PROGRA~1\MICROS~2\VC98\Include

[Silverfrost SCC/WIN32 Ver 3.65 Copyright (c) Silverfrost Ltd 2008]
 3/0023   #error ERROR: Only Mac or Win32 targets supported!
*** ERROR :Only Mac or Win32 targets supported! (In include file C:\PROGRA~1\MICROS~2\VC98\Include\excpt.h)
 3/0023   #error ERROR: Only Mac or Win32 targets supported!
*** ERROR :Only Mac or Win32 targets supported! (In include file


Last edited by mac-es on Fri May 23, 2008 2:20 pm; edited 1 time in total
Back to top
View user's profile Send private message
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Fri May 23, 2008 10:35 am    Post subject: Reply with quote

I think we are getting confused here. The C code I supplied was for MSVC and the corresponding Microsoft linker, LINK. That would create a DLL - which you would then link with your Fortran code using SLINK.

If you can compile everything using our compilers then you do not need the export statements in my sample code and can link the *objects* directly with SLINK.
Back to top
View user's profile Send private message
mac-es



Joined: 20 May 2008
Posts: 4

PostPosted: Fri May 23, 2008 2:26 pm    Post subject: Reply with quote

Andrew,

thanks again for the quick reply. Applying your proposal yields no "undefined references", so compiling and linking seems to be fine ("cl" and "link" for C code, "ftn95" for Fortran code and "slink" to build the two .dlls).

However, I'm wondering whether my Fortran code really calls the C functions (printf from C doesn't output anything). Maybe it's because I have two .dlls now: ext.dll and cprog.dll. Is there any possibility to merge these two files into one working .dll?
Back to top
View user's profile Send private message
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Fri May 23, 2008 4:08 pm    Post subject: Reply with quote

If you are really making the call then is could be possible that due to the IO subsystem the printf is not making it out. You could call fflush to make sure.

Regardless, if you can write both your C and Fortran using our tools then yes, you should be able to create them as one DLL, compile everything to object file and then link with SLINK.

For example, some C code:

Code:

#include <stdio.h>
extern "C" int print_something(int i) {
  printf("print something %d\n", i);
  return ++i;
}


and some Fortran code (you still need to define the C_EXTERNAL):

Code:

C_EXTERNAL PRINT_SOMETHING "print_something" (VAL) : INTEGER*4
INTEGER RET
RET = PRINT_SOMETHING(3)
PRINT *, RET
END


These can be compiled with SCC, FTN95 and linked with SLINK. C_EXTERNAL is described in the help as you will need to create statements for all C routines you call.
Back to top
View user's profile Send private message
mac-es



Joined: 20 May 2008
Posts: 4

PostPosted: Mon May 26, 2008 9:40 am    Post subject: Reply with quote

I'm using a lot of functions related to named pipes in my C code. scc cannot use the .h files needed for these functions (provided by Visual C++). Do I have to declare these functions as external (in Fortran where I'm not using them)?

So, if I use cl (Visual C++) and ftn95, it is not possible to create one .dll?

I used fflush which, unfortunately, has no effect.
Back to top
View user's profile Send private message
Andrew



Joined: 09 Sep 2004
Posts: 232
Location: Frankfurt, Germany

PostPosted: Mon May 26, 2008 11:44 am    Post subject: Reply with quote

If the functions are not declared in the C headers we provide (the pipe functions are declared in winbase.h, which is included by windows.h - so are they not in the SCC headers?) and you cannot use the Microsoft one (it might be a case of just defining the correct symbols before you compile in order to make them usable by SCC) then you can extract the relevant declarations and put them in your own header. You could then compile with SCC, FTN95 and link with SLINK, and you will need to make sure you link with the Microsoft DLLs (not the libs).

You do not need to declare the functions in the Fortran if you are not calling them from there.

As for creating a DLL from mixed code, this may be possible somehow, but will be very tricky - a mixture of different libraries may be required and it could get very problematic and as such is not recommended.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group