View previous topic :: View next topic |
Author |
Message |
sbyates
Joined: 24 Aug 2009 Posts: 6
|
Posted: Tue Sep 15, 2009 4:39 pm Post subject: C_EXTERNAL with Checkmate Win32 and Debug Win32 |
|
|
I have the following fortran program:
program test
C_EXTERNAL CTEST 'ctest' (REF) : INTEGER*4
character*11 string
integer*4 returnval
data string /'test phrase'/
write(*, 102) string
returnval = CTEST(string)
write(*, 103) returnval
102 format('here is the string written from fortan code: ', a11)
103 format('here is the returned valued from c code: ', i
end
And the following C program:
#include <stdio.h>
#include<stdlib.h>
extern "C" long int ctest (char *temp, long int ctestLength)
{
printf("Here is the string written from c code: %s\n", temp);
return 1;
}
In Plato, when building with the Checkmate Win32 option, I get the link warning:
WARNING the following symbols are missing:
ctest C:\forttest\CheckMate\Win32\fortcode.obj
(C:\FORTTEST\FORTCODE.FOR)
With the Debug Win32 option, no warnings are issued, and the program runs fine. What differences between Checkmate Win32 and just Debug Win32 could cause this problem?
Thanks |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8211 Location: Salford, UK
|
Posted: Fri Sep 18, 2009 8:41 am Post subject: |
|
|
When using /check etc extra arguments are passed so you can get problems if the linker wants to match the argument list as well as the function name. I don't know what the problem is here because you are using extern "C" as required. You can use the MAP option with SLINK in order locate the mismatch.
Another thing to try is to use the same /check option when compiling the Fortran and the C but again this should not cause a problem. |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Mon Sep 21, 2009 10:29 am Post subject: |
|
|
I do not know wheter I should start a new topic or perhaps continue here. The principle of the problem here is mixed programming with a very simple getting started example.
Both sample programms complie. My question is as follows:
I cannot figure out how to actually "mix" the languages. Must I add something to the fortran project source files, include files or references. Or must I add something to to linking process? |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8211 Location: Salford, UK
|
Posted: Mon Sep 21, 2009 2:28 pm Post subject: |
|
|
Typically in mixed language programming you will have a Fortran main program that accesses a function written in C in a separate file.
You need to link everything together using SLINK. There are various ways to do this. One way would take the following form of SLINK commands...
SLINK
lo main
lo func
file
Here main.f90 has been compiled to main.obj usinf FTN95 and func.c has been compiled to func.obj using SCC.
However, if you add your main.f90 and func.c to a Plato project then there is a reasonable chance that this will all be done for you when you click on Build. |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Mon Sep 21, 2009 2:42 pm Post subject: |
|
|
I tried to include both the .f90 and .c file into my project. It worked out fine. This confirms your comment that Plato does in fact take care of the linking automatically.
I must admit that this is a very cool capability of Silverfrost and Plato. |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Tue Sep 22, 2009 9:35 am Post subject: |
|
|
According to the Plato online help C_EXTERNAL in the Fortran program can be replaced by STDCALL (see example above). I tried it and got the following error message: Quote: | Compiling file: test_F.f90
Linking...
WARNING the following symbols are missing:
ctest H:\FTN95\scratch\Debug\Win32\test_F.obj
(H:\FTN95\SCRATCH\TEST_F.F90)
Creating executable: Debug\Win32\test_F.exe |
What is the reason for the missing symbol. How should I change the code to use STDCALL ("stdcall" convension) instead of C_EXTERNAL ("cdecl" convension)? |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8211 Location: Salford, UK
|
Posted: Tue Sep 22, 2009 1:01 pm Post subject: |
|
|
You can use STDCALL provided that the function that you are calling is defined using the same calling convention, i.e. you will also need to use STDCALL in the definition of the function. |
|
Back to top |
|
 |
|