- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've been trying, in vain, to build and debug a very simple mixed-language programming example.
contents of subs.c file:
#include
void f()
{
printf("hi from cn mega test");
}
contents of source1.for file:
PROGRAM HelloWorld
use, intrinsic :: iso_c_binding
implicit none
interface
subroutine f( ) bind( C, NAME='f' )
use, intrinsic :: iso_c_binding
implicit none
end subroutine f
end interface
call f
END PROGRAM HelloWorld
The project is a fortran project, and only contains two files: a C source file, and a fortran source file.
I've noticed that when I attempt to build the app, the C source file isn't compiled. The IDE doesn't even try to compile the file. Why? Is this something I must perform separately (command-line?)
This is a simple process that, under (don't laugh now if anybody is listening) Visual Studio 6 and Compac Visual Fortran 6 was very easy.
I'm working under the trial timeframe, so being able to build and debug a mixed language application is critial for adoption (read purchase).
Respectfully,
Jeff.
contents of subs.c file:
#include
void f()
{
printf("hi from cn mega test");
}
contents of source1.for file:
PROGRAM HelloWorld
use, intrinsic :: iso_c_binding
implicit none
interface
subroutine f( ) bind( C, NAME='f' )
use, intrinsic :: iso_c_binding
implicit none
end subroutine f
end interface
call f
END PROGRAM HelloWorld
The project is a fortran project, and only contains two files: a C source file, and a fortran source file.
I've noticed that when I attempt to build the app, the C source file isn't compiled. The IDE doesn't even try to compile the file. Why? Is this something I must perform separately (command-line?)
This is a simple process that, under (don't laugh now if anybody is listening) Visual Studio 6 and Compac Visual Fortran 6 was very easy.
I'm working under the trial timeframe, so being able to build and debug a mixed language application is critial for adoption (read purchase).
Respectfully,
Jeff.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to have the C file in a separate C (C++ really) project, perhaps one that generates a static library which is then linked in with the Fortran program.
(Are you using the included Visual Studio shell or have you aquired the full Visual Studio edition (perhaps also on a trial basis from Microsoft?) The included shell edition doesn't have support for C++ projects, or a C++ compiler, for that matter.)
Aside from the requirement for a C++ compiler, this change is due to a change in the model that Visual Studio has for mixed languages. It was made several Visual Studio versions ago.
(Are you using the included Visual Studio shell or have you aquired the full Visual Studio edition (perhaps also on a trial basis from Microsoft?) The included shell edition doesn't have support for C++ projects, or a C++ compiler, for that matter.)
Aside from the requirement for a C++ compiler, this change is due to a change in the model that Visual Studio has for mixed languages. It was made several Visual Studio versions ago.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was afraid it might be something like that.
I've been trying the trial Visual Studio 2010 Professional (the next rev of the standard Visual Studio that I've been forever), and this problem seems to be prevelent in Visual Studio 2008 as well.
I'll call it a problem because it seems to add additional potential failure points preventing the objective of simply calling FORTRAN from C and vice versa in order to demonstrate/protoype simple code.
So do I understand correctly that it's no longer possible tocombine different languages within the same project like we can (could?) in Developer Studio (Visual Studio) 6? Even for a simple two file case (1 C file, 1 FORTRAN file)?
If we must do mixed-language programming, we must create another project within a solution, create a library, and then call those functions by linking in the lib/obj files?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Microsoft made the change in VS2002 that eliminated the possibility of mixed-language projects. Yes, you do one project as a static library and the other as an executable, then link them together. Yes, it's a pain for small projects but...
Prior to VS2010, you could use project dependencies to have a Fortran library be a dependent of a C++ main and it would link them automatically. VS2010 broke that, so if the main is in C/C++, you have to explicitly name the Fortran library in the linker properties under "Additional dependencies".
You'll also want to read Configuring for Mixed-Language Applications.
Prior to VS2010, you could use project dependencies to have a Fortran library be a dependent of a C++ main and it would link them automatically. VS2010 broke that, so if the main is in C/C++, you have to explicitly name the Fortran library in the linker properties under "Additional dependencies".
You'll also want to read Configuring for Mixed-Language Applications.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I see...
I also just found:
which confirmed this.
Unfortunate. Disappointing. Confirmed.
Thanks.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page