replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - C_EXTERNAL with Checkmate Win32 and Debug Win32
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 

C_EXTERNAL with Checkmate Win32 and Debug Win32

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



Joined: 24 Aug 2009
Posts: 6

PostPosted: Tue Sep 15, 2009 4:39 pm    Post subject: C_EXTERNAL with Checkmate Win32 and Debug Win32 Reply with quote

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: ', iCool

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
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Sep 18, 2009 8:41 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Mon Sep 21, 2009 10:29 am    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Sep 21, 2009 2:28 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Mon Sep 21, 2009 2:42 pm    Post subject: Reply with quote

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 Very Happy of Silverfrost and Plato.
Back to top
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Tue Sep 22, 2009 9:35 am    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Tue Sep 22, 2009 1:01 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
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