Home > Archive > Fortran > June 2004 > Include C/C++ compiled file in a Fortran project (Windows)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Include C/C++ compiled file in a Fortran project (Windows)
|
|
|
| Hi,
I need to include a C/C++ file (compiled) in my Fortran project. I use MS
Visual Studio (Compaq Visual Fortran and MS Visual C++) and must create a
DLL file of my Fortran project.
I have a thought that it would be possible to include my C/C++ file as an
'obj' file (include this object file as a 'Resuource file' in the project).
Is this correct?
Anyone who can give me some help on how I create an object file from my
C/C++ file?
Many thanks,
MM
| |
| Jugoslav Dujic 2004-06-04, 3:58 pm |
| MM wrote:
| Hi,
|
| I need to include a C/C++ file (compiled) in my Fortran project. I use MS
| Visual Studio (Compaq Visual Fortran and MS Visual C++) and must create a
| DLL file of my Fortran project.
|
| I have a thought that it would be possible to include my C/C++ file as an
| 'obj' file
Yes, it's as simple as that -- just do a Project/Add to Project/Files and
browse for the .obj file...
| (include this object file as a 'Resuource file' in the project).
....don't mix that with "Resource file" though -- "resource files" are
icons, bitmaps, cursors etc. However, the IDE will do the right thing
based on file extension.
| Anyone who can give me some help on how I create an object file from my
| C/C++ file?
By compiling it :-).
Even more simpler, you can insert the .cpp file in your [Fortran] project
(instead of .obj) and -- again, based on extension -- C++ compiler will
compile the .c/.cpp file and Fortran compiler .for/.f90 files.
Note that CVF has somewhat unusual compiler defaults (calling convention),
which means that you cannot call C/C++ functions "just like that"; usually,
you have to spell out an INTERFACE block with CVF extensions and/or fiddle
with compiler settings. Here's a simple sample:
#include <stdio.h>
void Foo(int i, float f, char* s)
{
sprintf(s, "%5d %7.3f", i, (double)f);
}
program p
interface
subroutine Foo(i, f, s)
!DEC$ATTRIBUTES C, DECORATE, ALIAS: "Foo":: Foo
integer i
real f
!DEC$ATTRIBUTES REFERENCE:: s
character(*) s
end subroutine Foo
end interface
character(20):: s
call Foo(7, 42, s)
write(*,*) s
end program p
Make sure to read "Mixed-language programming" chapter in CVF Programmer's
Guide first.
CVF/IVF Users Forum is better suited for programming questions specific
to these compilers:
http://softwareforums.intel.com/ids/board?board.id=5
--
Jugoslav
___________
www.geocities.com/jdujic
Please reply to the newsgroup.
You can find my real e-mail on my home page above.
|
|
|
|
|