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

C calling Fortran example, can't configure visual studio

Brian_Murphy
New Contributor II
2,959 Views

https://software.intel.com/content/www/us/en/develop/articles/configuring-visual-studio-for-mixed-language-applications.html

The above instructions for one-time-configuration of visual studio have not been updated for the latest versions of visual studio (2019) or for Intel fortran Version 2020 (in folder C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2020.1.216).

In the Property Manager I managed to find the include and library folders (under an item called Upgrade from VC such and such), and added the intel items using $(IFORT_COMPILER20)\compiler....   But after doing control-S to save, exiting visual studio triggered error messages that the property changes could not be saved.

So I tried launching visual studio with admin rights, and tried again (the changes just made were gone).  I still got error messages about things not being saved when closing the C Calls Fortran solution, and also when closing visual studio.  

Image 41.pngImage 42.png

When restarting visual studio normally, C Calls Fortran has evidently been corrupted and will no longer load.

Image 44.pngImage 43.png

C:\Users\Cheers\Documents\Visual Studio 2019\Projects\Samples compiler_f\MixedLanguage\C_calls_Fortran\USEDLL\msvs\USEDLL.vcxproj : error  : The imported project file "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CPP.UpgradeFromVC71.props" could not be loaded. Root element is missing.  C:\Users\Cheers\Documents\Visual Studio 2019\Projects\Samples compiler_f\MixedLanguage\C_calls_Fortran\USEDLL\msvs\USEDLL.vcxproj


C:\Users\Cheers\Documents\Visual Studio 2019\Projects\Samples compiler_f\MixedLanguage\C_calls_Fortran\USELIB\msvs\USELIB.vcxproj : error  : The imported project file "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CPP.UpgradeFromVC71.props" could not be loaded. Root element is missing.  C:\Users\Cheers\Documents\Visual Studio 2019\Projects\Samples compiler_f\MixedLanguage\C_calls_Fortran\USELIB\msvs\USELIB.vcxproj

 How do I fix this?

0 Kudos
29 Replies
Brian_Murphy
New Contributor II
2,197 Views

I am trying to restore the C Calls Fortran sample project, but I don't remember where I got it from, and I cannot find it anywhere on my system.  Where can I get/find this?

0 Kudos
Ron_Green
Moderator
2,189 Views

It is quite difficult now to find the samples!  Sorry about that, I'll see why the web folks are making things harder to find.  Here is a link to the Windows PSXE 2020 Samples bundle including the Fortran samples, which include the mixed language sample:

https://software.intel.com/content/www/us/en/develop/download/776976.html

 

0 Kudos
Steve_Lionel
Honored Contributor III
2,179 Views

Great - the FAQ link https://software.intel.com/en-us/product-code-samples is broken. My opinion of this ongoing attempt to frustrate users is unprintable. (Oh, and users here can't find the FAQ anymore since the link to it was removed when the new forum went live.)

0 Kudos
Brian_Murphy
New Contributor II
2,171 Views

Thanks for the link to the samples.  I actually had that file already downloaded but didn't know the name of it.

However, more important than just downloading the samples is being able to configure visual studio 2019 & intel fortran 2020 to work with the samples. 

Please tell me how to do that.

One thing I observed during my failed attempt at that was the LIB directories for ia32 and intel64 could not both be assigned independently.  Assigning one would overwrite the setting of the other.

 

0 Kudos
Steve_Lionel
Honored Contributor III
2,165 Views

The instructions in the article, other than not referencing VS2019 and COMPILER20, are correct. I'm wondering if you somehow prevented VS from loading the C++ projects when you opened the solution, triggering the other errors. I just went through these steps myself and it worked fine.

I suggest you start over and pay attention to messages that pop up.

0 Kudos
Brian_Murphy
New Contributor II
2,141 Views

I got stuck where step 3 says Double click on Microsoft.Cpp.Win32.user because it's not there.

I am unable to start over.  I tried by deleting the C Calls Fortran Project folder, and restored it from the zip file download.  When I open the .sln project, visual studio has trouble with it.  See attached screen shot.

0 Kudos
Brian_Murphy
New Contributor II
2,133 Views

I managed to fix visual studio.  I found C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.Cpp.UpgradeFromVC71.props and it was empty.  I replaced it with a copy of Microsoft.Cpp.UpgradeFromVC70.props with all the occurrences of 70 replaced with 71.  

Now C Calls Fortran sln opens normally, but I still can't follow the visual studio configuration instructions.  The screen shot below shows that Microsoft.Cpp.Win32.user is missing.  There must be something different about my visual studio and/or computer.  

Image 51.png

If I double click Upgrade from VC 7.1 (a strange name for a property page), there are Include and Library directories which I can edit, but the changes fail to save, as well as there is an obvious incompatibility between 32 bit and 64 bit property settings for the Library directory.

I have managed to work around the problem by adding the intel compiler Include and Library directories at the sln project level.

Steve - if you want to do a screen share and see the errors, email me at bmurphy at xlrotor.com and the Windows 10 Quick Assist tool should make that easy.

0 Kudos
Steve_Lionel
Honored Contributor III
2,120 Views

That isn't the correct property page. I suggest that you reinstall Visual Studio, including Visual C++ for Desktop Applications. Something is wrong with your VS (not Intel Parallel Studio) install.

0 Kudos
Brian_Murphy
New Contributor II
2,113 Views

Ok.  Thanks. 

When I installed VS (that was in March), I don't remember making any selections regarding Visual C++ for Desktop Applications.  I'll be on the lookout for it.

0 Kudos
Brian_Murphy
New Contributor II
2,070 Views

The visual studio community installer says I already have Visual C++ for Desktop Applications installed. 

Maybe the Community version of visual studio can't be configured to include the Intel folders.

Image 60.png

0 Kudos
Steve_Lionel
Honored Contributor III
2,066 Views

I am using the Community Edition - works fine for me. I just tested it - created a C++ Console project, brought up the Property Manager (had to go to View > Other Windows > Property Manager), and there it was.

Screenshot 2020-09-26 111342.png

Screenshot 2020-09-26 111608.png

0 Kudos
JohnNichols
Valued Contributor III
2,054 Views

There is an obvious mistake I think in the sample Intel Code

Fortran Calling Sequence Example
use, intrinsic :: ISO_C_BINDING, only: C_INT, C_FLOAT, C_LOC 
use ftn_C_2 
...
real (C_FLOAT), target :: send(100) 
integer (C_INT) :: sendcount 
integer (C_INT), ALLOCATABLE, target :: recvcounts(100) 
... 
ALLOCATE( recvcounts(100) ) 
... 
call C_Library_Function(C_LOC(send), sendcount, & 
C_LOC(recvcounts)) 
...
0 Kudos
Steve_Lionel
Honored Contributor III
2,046 Views

@JohnNichols which sample is that? It isn't either C_Calls_Fortran nor Fortran_Calls_C.

0 Kudos
Brian_Murphy
New Contributor II
2,030 Views

I searched all files in the compiler_f collection for use ftn_C_2 and it was not found.

0 Kudos
JohnNichols
Valued Contributor III
2,025 Views

Steve:  I am a bit lost, there are quite a few posts. 

That sample of code I put up is from your manual on the Intel website for C to Fortran programming, i tried it but it did not work , they missed a : for the 100 in the first allocate statement. 

To say the Intel Web site is an interesting mess is to disparage the people who live in messes because they are forced to - Garbage scavengers springs to mind, Intel chooses to be this bad.

0 Kudos
Steve_Lionel
Honored Contributor III
1,946 Views

It's not my manual. Nie mój cyrk, nie moje małpy.

Got a link? I have seen some documentation pages with errors, and I report them. That code you showed is not in the samples bundle. If you can point to where it is, I might offer Intel a correction.

0 Kudos
JohnNichols
Valued Contributor III
1,940 Views

I am well aware it is not your manual, I am well aware of how much time and effort you put into this site and I am aware that you are a living legend in Fortran.  I really appreciate all of your assistance. 

This is the new online 19.1 Reference Manual -- the samples have a minor error, just interesting rather than anything else.  

https://software.intel.com/content/www/us/en/develop/documentation/fortran-compiler-developer-guide-and-reference/top/compiler-reference/mixed-language-programming/standard-fortran-and-c-interoperability.html

I am also slowly going under with three new online classes. -- 

0 Kudos
Steve_Lionel
Honored Contributor III
1,906 Views

Thanks for the pointer to the manual example. There are two and a half errors, none of which are in the ALLOCATE statement.

1. I think what you meant to say was that the declaration of the allocatable variable recvcounts should say (:) instead of (100).

2. The C function, declared as a function in Fortran, is called as a subroutine.

2.5 - The BIND (C, NAME=) uses a character other than apostrophe for the end delimiter.

I'll report this to Intel.

0 Kudos
JohnNichols
Valued Contributor III
1,889 Views

yes that was the allocate error, after fixing that it compiled ok. 

Thanks for reaching out 

0 Kudos
Reply