Problem with Visual Studio for Interoperate Fortran code and C code

Problem with Visual Studio for Interoperate Fortran code and C code

Hello to everybody,

I have to interoperate a C code with  a Fortran Code, under Visual Studio 2010 with Intel Fortran 

and Intel C/C++.

As suggested inside this forum I create 2 projects; 1 for Fortran and another

for C.

Furthermore I create a static library with the C project.

In the Fotran code I made all is nedded like ISO BIND(C) , subroutine, interface ....

and I add the C static librairy.

Everyting is compiled rigth (see the trouble I had in my last posted),

suppress all Fortran compiled trouble; but at the end it's work if there is only the C code.

Normally the Fortran code should "drive" the whole programm.

 

Thanks in advance for any help.

Sheers.

Best Regards.

       

 

 

 

24 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Did you create your Fortran project as a Console or QuickWin application?

Do you have a main program in your Fortran project?

Hello FortranFan,

I created my Fortran project as a Console application and I had also a main programm

inside my project.

So what happens when you try to link your Fortran project?  If you post your linker output on this forum, experts such as Steve at Intel or other forum readers might be able to guide you.

Hello again,

 I am at my home, i leave my office; I'm living in Europe.

I will post early tomorrow.

Sheers

Best Regards

 

 

Did you set the fortran project as "startup project" of the solution?

 

Hello,

 

after compiling i have :

--------------------------------------------------------------------------------------------------------------------------

 ...........

  ............

1>Release\ms_dfluxdg.obj
1>Release\mem_nc.obj
1>Release\jacbrt.obj
1>Release\initcpvs.obj
1>Release\iajabl.obj
1>Release\gasdiff2_s.obj
1>Release\draoult.obj
1>Release\alpha.obj
1>Release\xyzcoord.obj
1>Release\updtrootdensity.obj
1>Release\storvs.obj
1>Release\readsorb.obj
1>Release\ratemin.obj
1>Release\opngfls.obj
1>Release\mem_rt.obj
1>Release\initsatw.obj
1>Release\infcvs_cp.obj
1>Release\giups_brt.obj
1>Release\diff_grad.obj
1>Release\clstpfls.obj
1>D:\PROJET--COUPLAGE-VISUAL-SOURCES\ASM3P--RLD-1D-V1_\ASM3P-RLD-1D-V.1.4\ARCHI-LIB.lib
1>D:\PROJET--COUPLAGE-VISUAL-SOURCES\ASM3P--RLD-1D-V1_\ASM3P-RLD-1D-V.1.4\ASM3P-Rld-1D-V.1.4\Asm3P-Rld-1D-V.1.4\Asm3P-Rld-1D-V.1.4\Release\Asm3P-Rld-1D-V.1.4.exe.embed.manifest.res
1>Embedding manifest...
1>
1>Build log written to  "file://D:\PROJET--COUPLAGE-VISUAL-SOURCES\ASM3P--RLD-1D-V1_\ASM3P-RLD-1D-V.1.4\ASM3P-Rld-1D-V.1.4\Asm3P-Rld-1D-V.1.4\Asm3P-Rld-1D-V.1.4\Release\BuildLog.htm"
1>Asm3P-Rld-1D-V.1.4 - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

 

 

Thanks in advance

Best Regards

 

Hello,

 Now I set the Fortran Project as "Startup Project", and it doesn't change

anything. Perhaps I don't turn well.

Best Regards

So do you see an executable file created in your Release folder?  From your build log, it appears the name might be Asm3P-Rld-1D-V.1.4.exe.  What happens when you try to execute this file?

Hello FortranFan,

 

When I execute  Asm3P-Rld-1D-V.1.4.exe. , it's like CTR + FR;

it's working like there were "only" the C code.

Sheers.

Best Regard

Laurent,

Can you build the Debug version of your code, place a breakpoint at the first execution statement in your main Fortran program, then step through the code and see where it stops?  Perhaps an exception is getting raised when executions enters the code from the C static library.  You should be able to get some diagnostics using the debugger.

You need to right click on the Fortran project and select Dependencies. Check the box for the C library project. This will cause it to be linked in to the Fortran project.

If the main program is in C, it's more complicated due to C projects not linking in non-C dependent projects.

Steve - Intel Developer Support

Hello Steve,

First I would like to thank you for try to help me.

 

But can you be more precise, and be more verbose ?

Thank you in advance.

Sheers

Best Regards

This assumes you have a single solution with two projects, your Fortran main program and the C static library.

Right click on the Fortran project in Solution Explorer, select Project Dependencies...  A new dialog will come up that looks like this.

Under "Depends on", check the box for the static library project then click OK.

This will cause the library project to be built first, then when the Fortran project links, the C library will be linked in automatically.

If you are using VS2012 or later, when you right click on the project, select Build Dependencies... > Project Dependencies. Then it's the same.

Caveat - if the dependent project is a C DLL project, it won't link in the library and you'll have to add the name of the export library directly in the Fortran project's Linker > Additional Dependencies property.

For those going the other way around, a C project calling Fortran, it's even more complicated, thanks to Microsoft. A topic for another day.
 

Attachments: 

AttachmentSize
Download Capture_11.PNG12.73 KB
Steve - Intel Developer Support

Steve,

If you look at Laurent's comments in Quote #7 and #10, it appears he was able to successfully build his executable, Asm3P-Rld-1D-V.1.4.exe.  Doesn't that imply his project dependencies, etc. - the stuff he needs for building - are all ok?  Doesn't his comment in Quote #10 indicate some execution issue?  I'm guessing it is some argument or data mismatch/misalignment issue during Fortran/C interoperation - you may recall he has complex data structures that are going back and forth in his mixed language program.

 

Hard to say. Yes, the link seemed to be successful, but the description of the symptom isn't clear.

Steve - Intel Developer Support

 Steve, FortranFan,

 I had a conversation after having modification, with a neigthbour colleague

near my office.

 

The problem seems that "the master" is the Fortran project/programm,

who has a "main" programm,  and the C library as a "main" inside the same

file as functions,

so I think that I have to split my C programm with a "main file" alone.

That why it's need a librairy, is it no it ?

Sheers

Best Regards

 

 

If that's the case, I would have expected some linker errors but your link step seems to have completed ok.  So it's confusing.  Nonetheless, check that out and make sure your static C library only consists of functions that either return something back or which have void return.

 

Hello FortranFan,

I will look at this, on Monday ( 31 March).

Thanks

 

Sheers

Best Regards

Hello Steve,FortranFan,

 I would like to know, if the Fortran programm have a "main programm",

and "drive" the whole application; shall I am allowe to have a main programm in

the code/librairy ?

Sheers

Best Regards

Shall I am allowe to have a main programm in the C code/librairy ??

 

Sheers

Best Regards

Quote:

laurent L. wrote:

Shall I am allowe to have a main programm in the C code/librairy ??

 

Sheers

Best Regards

Don't know for sure, but I'd think it is ok if the C project is a static library.  But why do you need it?

Best Reply

You are allowed to have only one main program in an application.There's nothing wrong with that being in a static library, but in a Visual Studio solution, one project has to invoke the linker to create an executable. It's convention that you would choose the project that has the main program for this. (Doing so also may avoid some linker errors, depending on the structure of your program.)

Intel Visual Fortran provides several mixed-language samples, including C-Calls-Fortran and Forrtran-Calls-C.

Steve - Intel Developer Support

Thank you Steve and FortranFan,

Now everything is working good.

Sheers

Best Regards

Leave a Comment

Please sign in to add a comment. Not a member? Join today