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

error LNK2019: Problem with mixed language programming in Visual Studio 2005

Tim_Tambach
Beginner
936 Views
Hi all,

I have been spending a day now trying to make my program run. I have Microsoft Visual Studio with the Intel Fortran Compiler installed. The majority of my program is Fortran, but it needs to be compiled with a C (or C++) file. My solution consists of two projects, one for Fortran and the other for C (defined asa Windows Static Library). The error message I keep on getting is:

2>t2f.obj : error LNK2019: unresolved external symbol _CPUCLK referenced in function _CPUINI

CPUCLK is defined in the C file, while CPUINI is the Fortran routine that refers to CPUCLK. The following line is present in the C-file:

double __stdcall CPUCLK()

The static library file is made and found (when not present its reports this), but still the two languages do need seem to talk. I got the code from someone else and there it worked, so I guess it is a linker problem.I tried a lot of things, as the LNK2019 problem is discussed on various forums.

I hope that anyone can give me advise. Thank you very much!

Tim

0 Kudos
3 Replies
Xiaoping_D_Intel
Employee
936 Views
On 32-bit Windows system __stdcall calling convention will make function "CPUCLK" have symbol name"_CPUCLK@0" -- http://msdn.microsoft.com/en-us/library/zxk0tw93%28VS.80%29.aspx

If you want to keep this calling convention in the C file its declaration in the Fortran code should have attributes STDCALL as:

cDEC$ ATTRIBUTES STDCALL

0 Kudos
Jugoslav_Dujic
Valued Contributor II
936 Views
Two problems here: one almost certain and the other possible.

  1. With Intel Fortran (and all other current compilers), the default calling convention is __cdecl, not __stdcall (as used to be in Compaq Visual Fortran days). Thus, you either need to change that in the C code (recommended) or change the Fortran compiler setting (/iface:cvf, adjustable in "External procedures" category of the project settings).
  2. You need to make sure that the function does not have C++ name decoration, either by enclosing it in an extern "C" block, or naming the source files .c (rather than .cpp).
You can see the listing of exported and imported symbols from a .lib or .obj file by going to the VS (or Ifort) command prompt and typing

[bash]dumpbin /symbols yourfile.obj > temp.txt[/bash]

The listing will end up in temp.txt. For examining dlls, use Dependency Walker.
0 Kudos
Tim_Tambach
Beginner
936 Views
Hi thank you both for your suggestions!

I replaced the command __stdcall by __cdecl and that worked!

Thank you very much for the solution!

Tim
0 Kudos
Reply