Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

c code in fortran project

lklawrie
Beginner
2,297 Views

Apparently, in Linux and Mac versions of Intel Fortran, one can just include c code into the "make" files for the project. And it gets automatically compiled.

Is there anyway to do something similar in Windows from the IDE approach?

Linda

0 Kudos
21 Replies
Steven_L_Intel1
Employee
2,066 Views
Well, if you were using makefiles on Windows, you could do it there too. But as of Visual Studio 2002, Microsoft disallowed mixed-language projects. So the way you have to do it is to have two projects in a solution, one a static library and the other an executable, and make the executable project dependent on the library (right click on project, select Dependencies). Generally you should choose as the executable project the language that has the main program. If that is C, then you will also want to do the following:

1. In the Fortran library project, set Libraries > Disable default library search rules to No.
2. Make sure the Fortran and C projects have the same setting for run-time libraries (under Code Generation in C)
3. Add the path to the Intel Fortran run-time libraries LIB folder to Tools > Options > Projects > VC++ Directories > Library Files
0 Kudos
g_f_thomas
Beginner
2,066 Views

The procedure described is equivalent to writing a makefile script but VS obviates having to do so. Who wants to blend your own curry powder?VS.NET is designed to facilitate mixed-language programming within a solution, including native C/C+. Too bad for the Mac Linux folks.

Gerry

0 Kudos
lklawrie
Beginner
2,066 Views

main project (exe) is fortran.

static library does not seem to be an option for c projects. do i make a "net" class library?

i'm using VS 2003

0 Kudos
Steven_L_Intel1
Employee
2,066 Views
It's there, under Win32 Project, I think.
0 Kudos
lklawrie
Beginner
2,066 Views

I'm not at that computer right now but I think there were only two options:

Win32 project

Win32 console application

under Win32

0 Kudos
g_f_thomas
Beginner
2,066 Views

In VS 2005/8 it's under CLR. BTW, a Makefile project is under General.

Gerry

0 Kudos
lklawrie
Beginner
2,066 Views

no CLR grouping appears in VS2003. At least that I see.

i do see the makefile project.

0 Kudos
Steven_L_Intel1
Employee
2,066 Views
Now I am at my PC with VS2003. You want Win32 Project. When the Wizard comes up, click "Application Settings" and there will be an option for "Static Library".
0 Kudos
lklawrie
Beginner
2,066 Views

Thanks for taking the time to look, Steve.

0 Kudos
lklawrie
Beginner
2,066 Views

Thanks for those hints -- they allowed me to make static libraries out of the c code and include the libraries into the Fortran project (rather than including in the solution space). And I think that was the way to go for my project.

0 Kudos
g_f_thomas
Beginner
2,066 Views

That's precisely what VS of any vintage does for you.This also applies toVS 98 for CVF which creates the illusion that you can have c and Fortran in the same project. The clearest way to see this is to compile, (load), and link from the command line. Most peoplesoon get fed up doing this, overcome whatever mental block they have in usingthe premierIDE on the market (aka VS, the one that puts the video in ifort), andsoon wonder how they survived without it. For all its warts, the jewel in the crown (sic debugger) sure beats littering code with print's and write's and with successive releases shines on like a crazy diamond.

Steve, any estimate ofthe %-age of IVF users that forgo VS in favor of the command line?

Gerry

0 Kudos
Steven_L_Intel1
Employee
2,066 Views
Gerry, we don't have hard data on that. Based on what I see coming in from customers, I'd say it's probably in the 15-20% range. For some people, it's just what they're used to.
0 Kudos
lklawrie
Beginner
2,066 Views

Speaking for my group of 10 or so developers that would be 0%. We'd rather have an IDE than try to compile the 200 odd files from the command line.

0 Kudos
makbar
Beginner
2,066 Views

Dear All,

I have almost similar problem as Linda. I spent the whole weekend to make my code compile without much luck. My main code is in FORTRAN with several subroutines. Some of those routines call a few more C routines. These work in LINUX ifort using Makefile. I am a new user of IVF (Microsoft Visual Studio 2008). This is what I have done:

Created a Project -> Intel Fortran -> Console Application -> (named the project)

Right click on the project name: Add -> Existing Item -> (Added all fortran codes)

Right click on the project name: Add -> New Project ->Visual C++ -> Win32 -> Win32 Project -> (named) -> (next) -> Application Settings -> Static Library -> (finish)

Followed the steps suggested by Steve:

1. In the Fortran library project, set Libraries > Disable default library search rules to No. (It was default)

2. Make sure the Fortran and C projects have the same setting for run-time libraries (under Code Generation in C) (Done. I have Multithread DLL (/libs:dll /threads) in fortran and Multi-threaded DLL (/MD) in C)

3. Add the path to the Intel Fortran run-time libraries LIB folder to Tools > Options > Projects > VC++ Directories > Library Files

I have given C:soluDebug, where I have Object File Library (single file) for all the C codes.

When I compile the C codes separately, they do compile. When I compile the whole project, the fortran codes cannot locate the C routines.

I must have misunderstood something.

I have tried many different things. Latest I have added C:soluDebug in the Linker under the Project Properties. This is the message I get while linking:

Linking...

1>ipo: error #11021: OBJREAD Error: Could not create mapping for C:soluccodeDebug

1>Link: error error_during_IPO_compilation: problem during multi-file optimization compilation (code 1)

Please help!

MA

0 Kudos
lklawrie
Beginner
2,066 Views

Here is what I found the easiest for me:

1) Keep my fortran project.

2) make a new project (don't add to solution) for the c codes.

Make the c compile into a Library (option off Win32 project when you get to "application settings")

3) after the c code is compiled into a library, just add it (as an existing file) to the fortran project.

0 Kudos
makbar
Beginner
2,066 Views

Hi Linda,

Is there anything I need to change in the Project Properties? I have added separately generated C library, "ccode.lib" for my case, in the fortran Project/Solution, but I still get the same errors:

1>Linking...

1>diskout.obj : error LNK2019: unresolved external symbol _DATAOUT referenced in function _DISKOUT

1>parseinput.obj : error LNK2019: unresolved external symbol _GETKEY referenced in function _PARSEINPUT

1>parseinput.obj : error LNK2019: unresolved external symbol _GETSTR referenced in function _PARSEINPUT

1>parseinput.obj : error LNK2019: unresolved external symbol _GETREAL referenced in function _PARSEINPUT

1>parseinput.obj : error LNK2019: unresolved external symbol _GETINT referenced in function _PARSEINPUT

1>parseinput.obj : error LNK2019: unresolved external symbol _GETSTRN referenced in function _PARSEINPUT

1>meshgen.obj : error LNK2019: unresolved external symbol _DATAIN referenced in function _READX

1>diskin.obj : error LNK2001: unresolved external symbol _DATAIN

1>Debugsolu.exe : fatal error LNK1120: 7 unresolved externals

What else am I missing? Advance thanks!

MA

0 Kudos
lklawrie
Beginner
2,066 Views

You may need to add something like this to your fortran routines/module that call the c routines:

MODULE ISO_C_FUNCTION_BINDING
USE, INTRINSIC :: ISO_C_BINDING
END MODULE ISO_C_FUNCTION_BINDING

MODULE FortranRoutinestoCallC

INTERFACE
INTEGER(C_INT) FUNCTION SQLiteOpenDatabase (dbNameBuffer, dbNameLength) BIND (C, NAME="SQLiteOpenDatabase")
USE ISO_C_FUNCTION_BINDING
IMPLICIT NONE
TYPE(C_PTR), VALUE :: dbNameBuffer
INTEGER(C_INT), VALUE :: dbNameLength
END FUNCTION SQLiteOpenDatabase

INTEGER(C_INT) FUNCTION SQLiteExecuteCommand (commandBuffer, commandLength) BIND (C, NAME="SQLiteExecuteCommand")
USE ISO_C_FUNCTION_BINDING
IMPLICIT NONE
TYPE(C_PTR), VALUE :: commandBuffer
INTEGER(C_INT), VALUE :: commandLength
END FUNCTION SQLiteExecuteCommand

END

0 Kudos
makbar
Beginner
2,066 Views

I'll look into it. Thanks.

In the meantime, has anybody else have anyother suggestions? Since the code runs as is in Linux, there must be a way to make it work without changing it much. Thanks!

0 Kudos
Steve_Nuchia
New Contributor I
2,066 Views

I didn't see the sample project mentioned above, apologies if I missed it. You may find it useful to compare your setup with the sample:

C:Program Files (x86)IntelCompilerFortran10.1.019samplesMixedLanguageFortran_Calls_C

0 Kudos
makbar
Beginner
1,978 Views

The sample code looks good and should lead me to a solution. Thanks guys.

However, for now my Boss wants me touse Linux :(

...Just one more question:what does theBYTESWAP8 do in C? Is it converting ASCII to Binary? Can it doBinary to ASCII as well, or there is another function?

Thanks! MA

0 Kudos
Reply