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 

Help

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



Joined: 21 Feb 2008
Posts: 10

PostPosted: Fri Feb 29, 2008 3:34 pm    Post subject: Help Reply with quote

Hi,
I have a dll in C++, and i try to use fortran for some calculation to test if the speed could be improved. i wrote a DLL in fortran(using plato3 and ftn95) but i got a problem during building the project(in C++), i got messages like this one:
ustTest.lib(test.obj) : error LNK2001: unresolved external symbol ___CHECK95


i'm not sure that the probleme is in the dll!!!may be some one has any idea
Rolling Eyes

i'm new in Fortan.
PS:sorry for my bad english.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Feb 29, 2008 4:19 pm    Post subject: Reply with quote

FTN95 comes with a C++ compiler called SCC.

If your C++ code will compile with SCC then this is the simplest way to mix C++ and FTN95 Fortran. Then you can link using SLINK.

Otherwise it is not easy to mix the two languages.

When using a third party compiler you also have to consider which calling convention is being used. By default FTN95 does not use STDCALL.
Back to top
View user's profile Send private message AIM Address
simply



Joined: 21 Feb 2008
Posts: 10

PostPosted: Fri Feb 29, 2008 4:37 pm    Post subject: Re: Reply with quote

I'm using VC6(visual studio) like that:

extern "C" double BZ_Y(Points* bz,double x);

void test()
{
Points* bz = new Points[4];
double x = 0.1;
x = BZ_Y(bz,x);
delete[] bz;
}


PaulLaidler wrote:
FTN95 comes with a C++ compiler called SCC.

If your C++ code will compile with SCC then this is the simplest way to mix C++ and FTN95 Fortran. Then you can link using SLINK.

Otherwise it is not easy to mix the two languages.

When using a third party compiler you also have to consider which calling convention is being used. By default FTN95 does not use STDCALL.
Back to top
View user's profile Send private message
simply



Joined: 21 Feb 2008
Posts: 10

PostPosted: Fri Feb 29, 2008 9:49 pm    Post subject: Reply with quote

here is my code:
first file:

Code:
module Bezier
   type Point
      double precision x,y
   end type

   CONTAINS
         ......
   double precision function Get_t(bz,x)
   .....
        end function   
end module


the second file:

Code:
   double precision function Bz_Y(bz, x)
       use  Bezier
       ....
   end function


Last edited by simply on Fri Feb 29, 2008 9:52 pm; edited 1 time in total
Back to top
View user's profile Send private message
simply



Joined: 21 Feb 2008
Posts: 10

PostPosted: Fri Feb 29, 2008 10:38 pm    Post subject: Reply with quote

i found something similar here
with compaq fortran, so i corrected my C++ code like that

Code:
extern "C"
{
   double __declspec(dllimport) __stdcall BZ_Y(Points* bz,double x);
}
 
void test()
{
   Points* bz = new Points[4];
   double x = 0.1;
   x = BZ_Y(bz,x);
}


and now i have just one link error:

Quote:
Inter29.obj : error LNK2001: unresolved external symbol __imp__BZ_Y@12


i tried to put

Code:
   double precision function Bz_Y(bz, x)
           !DEC$ ATTRIBUTES DLLEXPORT::Bz_Y
       !DEC$ ATTRIBUTES C, ALIAS: 'BZ_Y@12':: Bz_Y
      use  Bezier
        end function


but it does not work Crying or Very sad

it seems that the problem is in how to make the function Bz_Y exported as BZ_Y@12
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Feb 29, 2008 11:42 pm    Post subject: Reply with quote

As I said, the simplest way forward is to compile your C++ with SCC.
Have you tried this?
Back to top
View user's profile Send private message AIM Address
simply



Joined: 21 Feb 2008
Posts: 10

PostPosted: Sat Mar 01, 2008 4:30 am    Post subject: Re: Reply with quote

PaulLaidler wrote:
As I said, the simplest way forward is to compile your C++ with SCC.
Have you tried this?

i didn't try this, but i'm afraid that, it will be more complicated to make changes in my C++ code, i'm not sure that codes are compatible between VC++6 and SCC???

i will try this, but i want to understand what is wrong or how to resolve the problem.
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Sat Mar 01, 2008 9:41 am    Post subject: Reply with quote

If you post very short but complete C++ and Fortran sample code then I may be able to help you with the details.

Use just a few lines of code.
Compile your C++ using a Microsoft C++ compiler.
Compile your Fortran using FTN95.
Use SLINK to link.
Provide details of all the compiler and linker command lines.
Back to top
View user's profile Send private message AIM Address
simply



Joined: 21 Feb 2008
Posts: 10

PostPosted: Mon Mar 03, 2008 3:52 pm    Post subject: Re: Reply with quote

thanks for your help.

PaulLaidler wrote:
If you post very short but complete C++ and Fortran sample code then I may be able to help you with the details.

Use just a few lines of code.
Compile your C++ using a Microsoft C++ compiler.
Compile your Fortran using FTN95.
Use SLINK to link.
Provide details of all the compiler and linker command lines.


code for test

Code:
INTEGER(KIND=3) FUNCTION FuncInteger()
FuncInteger = 347
END FUNCTION


c++ part:
Code:
extern "C" int __declspec(dllimport) __stdcall FUNCINTEGER();
void test()
{
   int x = FUNCINTEGER();
   x++;
}


with Slink i got:no main, WinMain or LibMain function

with the linker of VC6 i got Inter29.obj : error LNK2001: unresolved external symbol __imp__FUNCINTEGER@0
Back to top
View user's profile Send private message
simply



Joined: 21 Feb 2008
Posts: 10

PostPosted: Mon Mar 03, 2008 5:49 pm    Post subject: Reply with quote

In the Salford ftn95 user guide in page 167 "Generation of DLLs and exporting of functions" i found this:

The export command

The export command has the form:
export entryname [=internalname] [@ordinal [noname]] [data]

i added
Code:

F_STDCALL INTEGER(KIND=3) FUNCTION FuncInteger()  ALIAS 'FUNCINTEGER@0'
FuncInteger = 347
END FUNCTION


but the problem is still there
Back to top
View user's profile Send private message
simply



Joined: 21 Feb 2008
Posts: 10

PostPosted: Tue Mar 04, 2008 3:10 pm    Post subject: Re: Reply with quote

PaulLaidler wrote:
FTN95 comes with a C++ compiler called SCC.
If your C++ code will compile with SCC then this is the simplest way to mix C++ and FTN95 Fortran. Then you can link using SLINK.

my code didn't compile with SCC Rolling Eyes
Back to top
View user's profile Send private message
simply



Joined: 21 Feb 2008
Posts: 10

PostPosted: Tue Mar 04, 2008 6:46 pm    Post subject: Reply with quote

i found a solution, with calling to LoadLibrary and GetProcAddress in VC.
Back to top
View user's profile Send private message
Andrew



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

PostPosted: Thu Mar 06, 2008 12:42 pm    Post subject: Reply with quote

There is an example of how to call VC DLLs from FTN95 (and how to call FTN95 DLLs from VC) in the examples installed with FTN95.
Back to top
View user's profile Send private message
simply



Joined: 21 Feb 2008
Posts: 10

PostPosted: Thu Mar 06, 2008 8:15 pm    Post subject: Re: Reply with quote

Andrew wrote:
There is an example of how to call VC DLLs from FTN95 (and how to call FTN95 DLLs from VC) in the examples installed with FTN95.

i tried to use the same thing but it doesn't work
Back to top
View user's profile Send private message
Andrew



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

PostPosted: Fri Mar 07, 2008 6:53 pm    Post subject: Reply with quote

Have you specifically looked at the two example programs contained in:

c:\program files\silverfrost\ftn95\demo\win32\visualcinteroperability

and

c:\program files\silverfrost\ftn95\demo\win32\visualcinteroperability2

These are provided as Visual Studio projects and with batch files for compilation. These certainly do work (at least for Visual Studio 7.1 upwards).
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 -> Support 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