View previous topic :: View next topic |
Author |
Message |
simply
Joined: 21 Feb 2008 Posts: 10
|
Posted: Fri Feb 29, 2008 3:34 pm Post subject: Help |
|
|
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
i'm new in Fortan.
PS:sorry for my bad english. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Fri Feb 29, 2008 4:19 pm Post subject: |
|
|
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 |
|
|
simply
Joined: 21 Feb 2008 Posts: 10
|
Posted: Fri Feb 29, 2008 4:37 pm Post subject: Re: |
|
|
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 |
|
|
simply
Joined: 21 Feb 2008 Posts: 10
|
Posted: Fri Feb 29, 2008 9:49 pm Post subject: |
|
|
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 |
|
|
simply
Joined: 21 Feb 2008 Posts: 10
|
Posted: Fri Feb 29, 2008 10:38 pm Post subject: |
|
|
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
it seems that the problem is in how to make the function Bz_Y exported as BZ_Y@12 |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Fri Feb 29, 2008 11:42 pm Post subject: |
|
|
As I said, the simplest way forward is to compile your C++ with SCC.
Have you tried this? |
|
Back to top |
|
|
simply
Joined: 21 Feb 2008 Posts: 10
|
Posted: Sat Mar 01, 2008 4:30 am Post subject: Re: |
|
|
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 |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Sat Mar 01, 2008 9:41 am Post subject: |
|
|
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 |
|
|
simply
Joined: 21 Feb 2008 Posts: 10
|
Posted: Mon Mar 03, 2008 3:52 pm Post subject: Re: |
|
|
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 |
|
|
simply
Joined: 21 Feb 2008 Posts: 10
|
Posted: Mon Mar 03, 2008 5:49 pm Post subject: |
|
|
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 |
|
|
simply
Joined: 21 Feb 2008 Posts: 10
|
Posted: Tue Mar 04, 2008 3:10 pm Post subject: Re: |
|
|
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 |
|
Back to top |
|
|
simply
Joined: 21 Feb 2008 Posts: 10
|
Posted: Tue Mar 04, 2008 6:46 pm Post subject: |
|
|
i found a solution, with calling to LoadLibrary and GetProcAddress in VC. |
|
Back to top |
|
|
Andrew
Joined: 09 Sep 2004 Posts: 232 Location: Frankfurt, Germany
|
Posted: Thu Mar 06, 2008 12:42 pm Post subject: |
|
|
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 |
|
|
simply
Joined: 21 Feb 2008 Posts: 10
|
Posted: Thu Mar 06, 2008 8:15 pm Post subject: Re: |
|
|
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 |
|
|
Andrew
Joined: 09 Sep 2004 Posts: 232 Location: Frankfurt, Germany
|
Posted: Fri Mar 07, 2008 6:53 pm Post subject: |
|
|
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 |
|
|
|