- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm using the 30-day trial of the Intel Visual Studio 2015 with C++ and FORTRAN compilers. I'm evaluating for purchase and need some help please.
When trying to build a simple mixed language project with a C++ main calling a FORTRAN subroutine I get LNK2019, unresolved external symbol for "_sqrtf in function _G6". The code is as follows:
--- C++ code ---
#included <cstdlib>
extern "C" void _cdecl G6();
using namespace std;
int main( void )
{
G6();
return 0;
}
--- FORTRAN code ---
SUBROUTINE G6
IMPLICIT NONE
REAL SUM
REAL ROOTSUM
SUM = 1 + 2.5
ROOTSUM = SQRT(SUM)
END
---------------------------------------------
The FORTRAN code is compiled as a static library and linked into the C++ project.
Relevant information:
1. When compiled as a Release version the code compiles and executes properly. When compiled as a Debug version the unresolved error occurs.
2. I think I'm linking in the Intel libraries correctly in the project settings - the ones in the compiler\lib\ia32 and intel64 directories.
3. The above applies to a 32 bit project. When I switch to a 64 bit project I get error #10310: "Failed to enable trusted storage check for licensing." I will also need to correct this because we will need to compile 64 bit code. If possible, please let me know how to resolve this when responding to the above problem - If necessary I can make this a separate question.
Thanks
Ken W.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ken,
Welcome to the forum.
First, please configure Visual C++ to link with Fortran.
Second, to fix the license problem, select Start > All Programs > Intel Parallel Studio XE 2015 > Compiler and Performance Libraries > Command Prompt with Intel Compiler XE 15.0. Right click on any of the shortcuts shown starting with "Intel 64" and select "Run as administrator. In the command window that opens, type "ifort". Close the window. This should then eliminate the license error.
Let me know what happens.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your prompt reply.
1. Your solution resolved the licensing problem – Thanks.
2. The unresolved external problem still exists (I had completed this step already. I did re-check to make sure it was implemented correctly):
a. For a 32 bit project: Compiles and runs fine for release version but still get the unresolved external for the SQRT function in the debug version.
b. For a 64 bit project: Get a different unresolved external, this time the G6 function is now unresolved in the main.
Any help is appreciated.
This only the beginning of a task to integrate C++ code with a large FORTRAN legacy code. We will require the 64 bit project to work in both debug and release
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please do the following in Visual Studio:
Tools > Options > Projects and Solutions > VC++ Project Settings > General. Set "Show Environment in Log" to Yes.
In your C++ project, set the property Linker > General > Show Progress to "Show some progress messages".
Do a build. Attach a ZIP of the Debug (or Release) folders (both Fortran and C++ projects) to a reply here so I can see the log files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ken W.:
Here is an explanation of why the build went to completion in release mode but not in debug mode. The subroutine G6 has no arguments and does not reference any module or common variables. Therefore, an optimizing compiler can compile the "do nothing useful" lines of code in the subroutine to a single RET instruction, and the _sqrtf function is never referenced in the code, so no linker error occurs.
However, when you compiled in debug mode, the "do nothing useful" lines of code got compiled into the OBJ file, which then contained a reference to the Fortran intrinsic _sqrtf. Since you linked the C main using the C compiler and without having configured the build system to include the Fortran runtime libraries, an "unresolved external" linker error resulted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks to your help and the help of my co-worker, I think the problem is resolved. The first issue was with the project settings which was resolved with your help. The second issue was "operator error" which was resolved with the help of my co-worker. It turns out that during the confusion of getting the correct project settings correct, I was also mixing project types (debug, release, 32bit, 64bit) between the C++ and FORTRAN projects. When I realized this and compiled matching projects with correct settings, the problems were resolved.
Thanks again for all your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Glad to hear it!
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page