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

I got the message error LINK: fatal error LNK1181 cannot open input file

Zang_Lee
Beginner
3,044 Views

I have Parallel Studio XE 2013 with Visual Studio 2013. .

  1. I start a new IVF Project (static Lbrary)
  2. In VS2013, I add a new  win32 console application to the IVF Project
  3. I set the fortran function dependent to the main cpp

Please see below

//


#include "stdafx.h"
#include <iostream>


using namespace std;

extern "C"
 {
  void __cdecl FR1(int *a, int *b);
  int __cdecl FF1(int *c);
 }



int main()
{
 int n = 10;
 int nSq;
 int nCube;

 FR1(&n, &nSq);

 cout << "The square is:" << nSq << endl;

 nCube = FF1(&n);


 cout << "The cube is:" << nCube << endl;
 getchar();
 return 0;
}

 

// fortran f90

subroutine FR1(N,M)
!DEC$ ATTRIBUTES DLLEXPORT :: FR1
    
 M = N*N
return 
end
    
integer function FF1(N)
!DEC$ ATTRIBUTES DLLEXPORT :: FF1
   
FF1 = N*N*N
    return 
    end

I am trying to call  a fortran function f90 from C++, but i got two time the error message  LNK2019

error LNK2019: unresolved external symbol referenced "_FR1" in function _main

error LNK2019: unresolved external symbol referenced "_FF1" in function _main

 With Dumpbin /symbols I got the error message LINK: fatal error LNK1181 cannot open input file

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC> cd c:\visual studio 2013
\Projekt2\Fortfunc\Debug

c:\visual studio 2013\Projekt2\Fortfunc\Debug>dumpbin/symbols Fortfunc.dll
Microsoft (R) COFF/PE Dumper Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file Fortfunc.dll
LINK : fatal error LNK1181: Eingabedatei "Fortfunc.dll" kann nicht geöffnet werden.

Thanks in Advance

0 Kudos
1 Solution
Steven_L_Intel1
Employee
3,044 Views

The article mecej4 links to explains how to do this in newer VS versions - keep reading. But for your problem, the following note in that article is also important:

NOTE: In Microsoft Visual Studio 2010 and later, a C++ project will not link in a non-C++ dependent project library. If you are using a C/C++ main program with a Fortran static or dynamic library as a dependent project, you must explicitly provide the path to the Fortran library, (the .lib export library in the case of a DLL project), in the C/C++ project's Linker > Additional Dependencies property, or as a "source file" in the project.

Is there a particular reason you're building the Fortran code as a DLL? Would a static library do?

View solution in original post

0 Kudos
6 Replies
mecej4
Honored Contributor III
3,044 Views

In more recent versions of Visual Studio, there are some impediments (set up by Microsoft?) to building projects in which the user wishes to mix sources in C/C++ and another language. See https://software.intel.com/en-us/articles/configuring-visual-studio-for-mixed-language-applications , where the procedure for accomplishing your goals is explained. Alternatively, you can build your sample easily at the command line. Compile the Fortran routine into a .OBJ file, and then do icl cmain.cpp fsub.obj .

0 Kudos
Zang_Lee
Beginner
3,044 Views

 

I can't find the VC++-Directories from Tools->Options->Projects and Solutions ..it is outdated. Can you give me some Details about second Option of your alternativ ? Where and How can I do icl cmain.cpp fsub.obj ? please

0 Kudos
Steven_L_Intel1
Employee
3,045 Views

The article mecej4 links to explains how to do this in newer VS versions - keep reading. But for your problem, the following note in that article is also important:

NOTE: In Microsoft Visual Studio 2010 and later, a C++ project will not link in a non-C++ dependent project library. If you are using a C/C++ main program with a Fortran static or dynamic library as a dependent project, you must explicitly provide the path to the Fortran library, (the .lib export library in the case of a DLL project), in the C/C++ project's Linker > Additional Dependencies property, or as a "source file" in the project.

Is there a particular reason you're building the Fortran code as a DLL? Would a static library do?

0 Kudos
mecej4
Honored Contributor III
3,044 Views

Zang Lee wrote:

I can't find the VC++-Directories from Tools->Options->Projects and Solutions ..it is outdated. Can you give me some Details about second Option of your alternativ ? Where and How can I do icl cmain.cpp fsub.obj

I assumed that you have either the Microsoft VC or Intel C compiler installed.

You open an Intel Fortran command window (from the Start Menu or a suitable shortcut), and type the commands there. If you already have fsub.fxx compiled, the command that I gave (use cl instead of icl, if you do not have Intel C) will work if you have placed fsub.obj in the same directory as cmain.cpp.

0 Kudos
Zang_Lee
Beginner
3,044 Views

Thank you Steve, I provide the path to the Fortran library as a source file in the Project and it works.

 

 

0 Kudos
Zang_Lee
Beginner
3,044 Views

Thank you mecej4 for the article and thank you for Details about the second Option

0 Kudos
Reply