Cannot get rid of 2019 and 1120 errors

Cannot get rid of 2019 and 1120 errors

I'm having problem with these errors for weeks. I read every topic based on this problem but no advice worked for me.

Visual Studio 2010 Professional and Intel(R) Visual Fortran Composer XE 2011.

This is the output:

1>------ Rebuild All started: Project: Projekat, Configuration: Debug Win32 ------
1>Build started 15-Apr-14 4:00:28 PM.
1>_PrepareForClean:
1>  Deleting file "Debug\Projekat.lastbuildstate".
1>InitializeBuildStatus:
1>  Touching "Debug\Projekat.unsuccessfulbuild".
1>ClCompile:
1>  Glavni.cpp
1>Glavni.obj : error LNK2019: unresolved external symbol _K1 referenced in function _main
1>C:\Users\Stevic\Documents\Visual Studio 2010\Projects\Projekat\Debug\Projekat.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.09
2>------ Rebuild All started: Project: OtpRasp, Configuration: Debug Win32 ------
2>Deleting intermediate files and output files for project 'OtpRasp', configuration 'Debug|Win32'.
2>Compiling with Intel(R) Visual Fortran Compiler XE 12.0.5.221 [IA-32]...
2>Otpor.f90
2>Creating library...
2>
2>Build log written to  "file://C:\Users\Stevic\Documents\Visual Studio 2010\Projects\Projekat\OtpRasp\Debug\BuildLog.htm"
2>OtpRasp - 0 error(s), 0 warning(s)
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========

 

 

 

This is the Fortran code :

MODULE OTPOR_RASP

REAL FUNCTION k1 (x) BIND (C, NAME = "k1")
USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT, C_FLOAT
IMPLICIT NONE
!DEC$ ATTRIBUTES DLLEXPORT :: k1
REAL(C_FLOAT):: x
INTEGER(C_INT) :: x1, x2
!REAL(C_FLOAT) :: y(8) = (/1.37, 1.33, 1.28, 1.24, 1.2, 1.16, 1.13, 1.11/)
x1 = CEILING (x)
x2 = FLOOR (x)
!k1 = y(x1) + ((x - x1) * (y(x2) - y(x1))) / (x2 - x1)
k1=x1 + x2
RETURN
END FUNCTION k1

END MODULE OTPOR_RASP

 

This is a C++ code:

#include <iostream>
#include <math.h>
#include <fstream>
#include "Funkcije.h"
#include <string>

using namespace std;

extern "C"
{
    double K1 (double);
}

int main()
{

 ...

 ...

double v = 4;
double k = K1 (v);

system("pause");

return 0;
}

Please help me.

Thank you in advance!

15 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

In the Fortran program, you said the name of the routine was "k1" but in the C program you said the name of the program was K1.

The clause NAME='string' in the BIND(C) declaration sets the external name to be the same string you specified, in whatever case you specified, but then decorates it however the companion C compiler would.   Since you are on Windows 32, this means it prefixed an underscore to the lowercase "k1".

The C language is case sensitive, and when you specified the external name as K1, it too prefixed an underscore, but it prefixed the underscore to an uppercase "K1", and the resulting strings do not match.

         --Lorri

Make sure that the types match (DOUBLE/FLOAT), and note that BIND(C) does not imply pass-by-value, which is what C expects by default. Finally, names in C are case sensitive, so "k1" and "K1" are distinct.

Here is an attachment of a code. I was changing BIND-name from K1 to k1 but it didn't help. Also changed from double to float but still getting same errors.

.

Please use the Select Media button at the bottom of the page rather than the toolbar button for now.

Steve - Intel Developer Support

Hope it's OK now.

Attachments: 

AttachmentSize
Download 0 bytes

I'm terribly sorry for the spam. I have big problems with internet today.

Attachments: 

AttachmentSize
Download Projekat.7z2.77 MB

Hi Milos -

     I believe you had your project dependencies backwards.

     Right-click on the OtpRasp project, and remove the dependency.    Now right-click on the Projekat project, and set OtpRasp as a dependency.

     Now that will tell Visual Studio to build OtpRasp first, and to link it with Projekat.

            Good luck!

                          --Lorri

[editted]  Sorry, I thought I saw it working, but I was mistaken.  I'm still looking at this.  Even though the projects are being built in the correct order now, for some reason Projekat is not linking against the library built for OtpRasp.   I'll update when I know more.

Hi Lorri,

Thank you very much for responces and your time. I tried making C++ as Win32 Console App, tried as Empty project (as it is now), tried Fortran as DLL (as it is now) and as Static Library, but I saw no changes at all.

I thought the problem was with the linker but apparently that is not the case here considering you have the same problem.

Hi Milos -

    I'm confident we can make this work  now that the external names match :-)   I thought there was an article about how to configure Visual Studio for Fortran <-> C++ programming, but I haven't found it yet.

                       --Lorri

You mean this one  https://software.intel.com/en-us/articles/configuring-visual-studio-for-...

I tried it but I cannot get it to work. It gives me an error and the project becomes useless.

An error has occurred while saving the edited properties listed below:

                     Library Directories

One or more values are invalid. MSBuild returned the following error:

The expression " " ".get_Chairs(12)" cannot be evaluated. Index was outside the bounds of the array.

After that I cannot re-edit Library Directories. I get an error again saying:

Property value is not valid.

Details of error are following:

The expression """.get_Chars(12)" cannot be evaluated. Index was outside the bounds of the array.  C:\Users\Stevic\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props

I tried this at least 5 times. Tried changing the value in the $(IFORT_COMPILER[vv])\compiler\lib\ia32 that sholud stand instead of vv but no difference whatsoever. After every time I would have to start new project, remove old one and all that only to get 1120 and 2019 errors all over again :)

EDIT: I just configured VS successfully (turns out I forgot to remove the brackets), but sill getting same 1120 and 2019 errors.

I have VS2012, and I got Milos's project working.

The attached 7Z archive contains the project files after correction for dependencies, as discussed earlier in this thread, and the argument to function K1 declared with the attribute VALUE, as expected by C/C++. The project files in the archive, after I allow VS2012 to upgrade them from the earlier version and build the project, work in the sense that I can see the correct value returned by the function k1() when I put a breakpoint after its invocation.

I believe that the project should build under VS2010, but I cannot verify that since I have only the later version installed. 

Attachments: 

AttachmentSize
Download Projekat.7z2.99 MB

Thank you mecej4.

However I can't open the project because of the compatibility with the newer version of VS. Still I'm not sure I see any difference in the code itself, and after copy-paste your code error remains.

Do you have a theory what is the problem? Code, linker, debugger, something else? I'm really frustrated with this program as I can't make it work for weeks. You gave me hope it can work at least in debugger :)

Best Reply

Milos, as projects go yours is a rather simple mixed-language project. In fact, to build it at the command line is trivial:

cd OtpRasp
ifort /c Otpor.f90
cd ..\Projekat
icl Glavni.cpp ..\OtpRasp\Otpor.obj

The problem with VS and its various versions is that the project and solution files are simple text files that could be edited with a text editor if the structure of the files had been properly documented. Unfortunately, we have to use the huge VS package and wade through innumerable GUI tabs and panels even to make a simple change.

I'll see if I have VS2010 installed on another computer. Perhaps someone else with VS2010 will respond.

Added later: Attached is a modified version of Milos's archive that worked in the Debug 32-bit configuration on a Windows 7- X64 PC running VS2010 Pro and IFort 13.1.3.198.

Attachments: 

AttachmentSize
Download Projekat.7z2.99 MB

Leave a Comment

Please sign in to add a comment. Not a member? Join today