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 

Creating Executable file from DLL and OBJ files
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
anand3162



Joined: 17 Oct 2014
Posts: 26

PostPosted: Thu May 28, 2015 7:42 pm    Post subject: Reply with quote

Mecej4,

Thanks again.
In Ex1.for I have

winapp 300000,600000
Program Ex1
implicit none
real * 8 a, b, c
a = 11.0d0
b = 15.0d0
c = a + b
write (6,*) "I am from Ex1 - going to call Ex2"
call ex2 (a, b, c)
stop
end

In Ex2.for I have,

subroutine Ex2 (a, b, c)
implicit none
real * 8 a, b, c
call Ex3(a, b, c)
write (6,*) "I am from Ex2 - Called from Ex1"
write (6,*) "a =", a
write (6,*) "b =", b
write (6,*) "c =", c
return
end

In Ex3.for I have simple code to do c = a*b

subroutine Ex3 (a, b, c)
implicit none
real * 8 a, b, c
write (6,*) "I am from Ex3 - Called from Ex2"
c = a*b
write (6,*) "c is now a product", c
return
end

I used the following statements to create a DLL out of Ex2.for and Ex3.for
Ftn95 D:\...Ex2_Real.For /link D:\.....\Ex2.dll
Ftn95 D:\.....\Ex3.for /link D:\.....\Ex3.dll

Next I linked the main program Ex1.for with the two DLLs
Ftn95 D:\....\Ex1.for
slink D:\....\Ex1.obj D:\....\Ex2.dll D:\.....\Ex3.dll

I do not get any errors while compiling. Once the exe file, Ex1.exe has been created, and I open it, I crash in Ex2 with an error 29. Also, in the call stack, i see a [recur=1] . Is this an indication of something being called recursively?
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Thu May 28, 2015 8:02 pm    Post subject: Reply with quote

What is in Ex2_real.for?

This works for me:

Code:

ftn95 ex2.f90
ftn95 ex3.f90
slink /dll ex2.obj ex3.obj /export:EX2
ftn95 ex1.f90
slink ex1.obj ex2.dll
ex1
Back to top
View user's profile Send private message
anand3162



Joined: 17 Oct 2014
Posts: 26

PostPosted: Thu May 28, 2015 8:26 pm    Post subject: Reply with quote

the subroutine named as Ex2 is saved with file name Ex2_real.for

However, after doing the changes as you suggested, I still crash in the same location, that Ex3 is missing. I see no errors during compilation of the ex2 and ex3 into a DLL. I am missing something then with creating the executable?
Back to top
View user's profile Send private message
anand3162



Joined: 17 Oct 2014
Posts: 26

PostPosted: Thu May 28, 2015 8:36 pm    Post subject: Reply with quote

This is exactly what I have

Ftn95 D:\...\Ex3.for D:\...\Ex3.obj
Ftn95 D:\...\Ex2_Real.for D:\...\Ex2_Real.obj
slink /dll D:\...\Ex2_Real.obj D:\...\Ex3.obj /export:EX2
Ftn95 D:\...\Ex1.for
slink D:\...\Ex1.obj D:\...\Ex2.dll

I see no errors when I compile this.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Thu May 28, 2015 10:48 pm    Post subject: Reply with quote

What do you actually have in place of the "\...\" in your post? Secondly, are you compiling in a working directory different from the directory containing the source files? Are you placing the resulting OBJ files in a third directory?

By default, when you name only the source file, the corresponding object file is placed in the current working directory.

Unless there is a need to use more than one directory, and until you become familiar with the process, I suggest that you keep all the files related to the project in a single directory, and that you delete all old versions of .OBJ, .DLL and .EXE files before rebuilding. Otherwise, there will be much scope for confusion, mistakenly using old versions of objects and DLLs, etc.
Back to top
View user's profile Send private message
anand3162



Joined: 17 Oct 2014
Posts: 26

PostPosted: Fri May 29, 2015 2:56 pm    Post subject: Reply with quote

Mecej4,

I was successful in compiling and executing, when I renamed my Ex2_real to Ex2. I am surprised at that, because when I was using Ex2_real I made sure all of the compilation code used Ex2_real.

I am compiling and working in the same directory. My source files are all in the same directory as the directory I am trying to compile in. I am not using a third directory to place the object/dll or exe files.

I used the \...\ for the sake of brevity in my posts. I have removed all the directory path names now.

My compilation code is now
Ftn95 Ex2.for
Ftn95 Ex3.for
slink /DLL Ex2.obj Ex3.obj /export:EX2
Ftn95 Ex1.for
slink Ex1.obj Ex2.dll
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Fri May 29, 2015 3:11 pm    Post subject: Reply with quote

All right, now that you have explained what you did, I see why your earlier attempt failed. When you link a number of object files, the name of the resulting EXE or DLL file is obtained from the first listed object file, unless you use the /OUT:xxxx option. Specifically, the command
Code:
slink /dll Ex2_Real.obj Ex3.obj /export:EX2

would have produced EX2_REAL.DLL, so an attempt to use EX2.DLL in a subsequent link would fail because EX2.DLL did not exist or was an older and probably incompatible version.
Back to top
View user's profile Send private message
anand3162



Joined: 17 Oct 2014
Posts: 26

PostPosted: Fri May 29, 2015 3:14 pm    Post subject: Reply with quote

I did use Ex2_Real.DLL, which is why I am not sure what I missed. If Ex2.Dll was in my compile program but not found in the directory, then I would have received an error during compilation. I did not receive any error during compilation. Not sure what I did wrong. However, I think for now I have a working solution. Thank you so much for your patience with a rookie.
Back to top
View user's profile Send private message
anand3162



Joined: 17 Oct 2014
Posts: 26

PostPosted: Fri May 29, 2015 7:54 pm    Post subject: Reply with quote

As I continued to work, I realize there is something very specific about the names of the routines and the DLLs or the way they interact.

I have 3 routines now. 1 program called DriverProgram and 2 routines called GetK.for and Ex3.for. I want to combine GetK and Ex3 into 1 DLL and then link with the DriverProgram to create DriverProgram.exe

When I compile this, with
Ftn95 D:\Development\GetK.for
Ftn95 D:\Development\Ex3.for
slink /DLL D:\Development\GetK.obj D:\Development\Ex3.obj /export:GetK
Ftn95 D:\Development\DriverProgram.for
slink D:\Development\DriverProgram.obj D:\Development\GetK.dll

I get an error Warning: the following symbols are missing: GetK

I am not sure why GetK is missing.
Back to top
View user's profile Send private message
anand3162



Joined: 17 Oct 2014
Posts: 26

PostPosted: Fri May 29, 2015 8:39 pm    Post subject: Reply with quote

I figured this out, and it is quite amazing what I figured.

in the line

slink /DLL D:\Development\GetK.obj D:\Development\Ex3.obj /export:GetK

if you replace export:GetK with export:GETK

no more compiler warnings. The name after export must be UPPER CASE. I am very sure based on my trials today. Irrespective of the name in the directory. Strangely in the directory, it shows up as GetK.dll

It was providential I found this.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri May 29, 2015 10:15 pm    Post subject: Reply with quote

In instructions for using SLINK you will find /exportall and this is usually preferred.
Back to top
View user's profile Send private message AIM Address
anand3162



Joined: 17 Oct 2014
Posts: 26

PostPosted: Mon Jun 01, 2015 3:52 pm    Post subject: Reply with quote

Thank you Paul. Is there a restriction on the number of obj files that can be exported into 1 DLL? I seem to have trouble converting more than 2 obj files into 1 DLL.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Jun 01, 2015 4:48 pm    Post subject: Reply with quote

No. There is no significant restriction.
Back to top
View user's profile Send private message AIM Address
mecej4



Joined: 31 Oct 2006
Posts: 1885

PostPosted: Mon Jun 01, 2015 7:54 pm    Post subject: Reply with quote

Quote:
I seem to have trouble converting more than 2 obj files into 1 DLL
Please state what "trouble" you had. I have one DLL which was built out of more than 500 OBJ files with no problems at all, and many other similar DLLs built out of fewer OBJ files (such as 5 to 10).
Back to top
View user's profile Send private message
anand3162



Joined: 17 Oct 2014
Posts: 26

PostPosted: Mon Jun 01, 2015 8:48 pm    Post subject: Reply with quote

To give you an example,

I have 1 DriverProgram (this is a program) and 3 subroutines (.for)

Program DriverProgram.for has a call to the following
GetK.for that calls Ex3.for
Dummycall.for that calls Ex3.for

So if I understand correct, I have to create one DLL out of GetK.obj and Ex3.obj as well as a second DLL out of Dummycall.obj and Ex3.obj

Next, I can link the program DriverProgram.obj with both the individual DLLs.
Correct?

Will I be better off trying to create 3 DLLs, 1 each with GetK.for, Ex3.for and Dummycall.for and then linking all three DLLs with the main DriverProgram? I have tried this and failed.
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
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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