- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have some .c files in a fortran project. By adding "command line" in "custom build" of the file properties to compile the file, the command line is like "cl.exe /c /EHsc ...", and set the "output" property to proper folder.
The project complie and link well under VS2010/2012 with ivf2012/2015.
But after upgrade to VS2017/2015 and ivf2017, build reported error (fail to open include file: "stdio.h", no such file or directory...).
I have verified and tried the followings:
(1) OS is window 10
(2) C++ has been installed with VS2017 or VS2015, and a helloworld C project with stdio.h included goes well.
(3) Reinstalled VS2017 or VS2015 and Intel parallel studio for times, of couse it meant nothing.
(4) Add corresponding "ucrt" directory path where the header files are in to include path of fortran project and windows system environment. It doesn't work. And I change the c file's command line of custom build property to "set", so the environment variables can be seen in complie output. It seems the variables are not affected by system environment nor fortran include path setting.
My questions are:
How to make it work?
What is the recommanded way to compile and link .c/.cpp code in a fortran project?
How to modify the path environment of command line of c files in a fortran project?
Thanks!!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What you do is to add a C/C++ project to your Solution, with he project type being a static library, then make the Fortran project dependent upon it.
Right-Click on Solution in Solution Explorer, choose Add, Add Project, ...
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Jim, do you mean that any C/C++ code must be first compiled and packaged as a library? I routinely link in .obj files that were compiled from C code. I must be misunderstanding something. My case is a bit different, though, because I compile the C code outside the Fortran project.
Gib
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you want C code compiled as part of the VS solution, Jim is correct that you must put the C code in a separate C/C++ project and link it in with the Fortran project. It has been this way since VS2002. If the Fortran project has the main program, make the C/C++ project a static library and a dependent project. If the C/C++ project has the main program, make the Fortran project a static library and name the .lib as input to the C/C++ project (MSVC projects won't link in non-MSVC dependent projects.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My way is similar to Gib's. Build the solution by linking .obj files compiled from .c file and .for file together, rather than by a static library.
So, according to Jim and Steve's advice, static library is the only way to do things correct. Thanks, I got it.
Since I have only 2 C files, make a project is a little kind of "use a sledge hammer to crack a nut"~
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>Since I have only 2 C files, make a project is a little kind of "use a sledge hammer to crack a nut"~
This is a rather light weight sledge hammer (fly swatter size IMHO) because the extra time required to link the .lib might be in the 10s of milliseconds.
I do not think MS VS has a C/C++ target type as "none".
While you can insert a makefile as a pre-compile build step, it is much easier to use a separate project.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks all!
All advices can solve the problem~
And I have tried adding "$(UniversalCRTSdkDir)Include\$(UCRTVersion)\ucrt" to include path of 'intel compiler and tools->compilers' . It works too.
I wonder since "$(UniversalCRTSdkDir)Include\$(UCRTVersion)\um" is in the path after installation, why "$(UniversalCRTSdkDir)Include\$(UCRTVersion)\ucrt" is not here?
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page