Silverfrost Forums

Welcome to our forums

Help

29 Feb 2008 2:34 #2841

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 :roll:

i'm new in Fortan. PS:sorry for my bad english.

29 Feb 2008 3:19 #2845

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.

29 Feb 2008 3:37 #2847

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; }

; double x = 0.1; x = BZ_Y(bz,x); delete[] bz; }

[quote:d93f72fe74="PaulLaidler"]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.

29 Feb 2008 8:49 (Edited: 29 Feb 2008 8:52) #2849

here is my code: first file:

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:

	double precision function Bz_Y(bz, x)
    	use  Bezier
    	....
	end function
29 Feb 2008 9:38 #2850

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

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:

(http://www.thescripts.com/forum/thread280324.html) with compaq fortran, so i corrected my C++ code like that

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:f5593af1c5]Inter29.obj : error LNK2001: unresolved external symbol __imp__BZ_Y@12

i tried to put

	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 😢

it seems that the problem is in how to make the function [color=red:f5593af1c5]Bz_Y[/color:f5593af1c5] exported as [color=red:f5593af1c5]BZ_Y@12[/color:f5593af1c5]

29 Feb 2008 10:42 #2851

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

1 Mar 2008 3:30 #2854

Quoted from PaulLaidler 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.

1 Mar 2008 8:41 #2858

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.

3 Mar 2008 2:52 #2873

thanks for your help.

Quoted from PaulLaidler 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

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

c++ part:

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[color=red:2d7529c5df]@0[/color:2d7529c5df]

3 Mar 2008 4:49 #2876

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

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

but the problem is still there

4 Mar 2008 2:10 #2883

Quoted from PaulLaidler 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 :roll:

4 Mar 2008 5:46 #2884

i found a solution, with calling to LoadLibrary and GetProcAddress in VC.

6 Mar 2008 11:42 #2891

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.

6 Mar 2008 7:15 #2896

Quoted from Andrew 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

7 Mar 2008 5:53 #2899

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).

Please login to reply.