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

Error LNK2019 when using Fortran Intrinsic Functions

lls121
Beginner
4,461 Views

I just started using Intel Visual Fortran Compiler for Windows, and I am trying to set up a solution in Visual Studio 2010 that contains a Fortran Static Library project and a C++ project. I can access my Fortran subroutines and functions through the C++ project without any issues, but when I include any Fortran intrinsic functions in my Fortran code, I get a LNK2019 error.

For example, I created a Fortran function, FR,that calls the SQRT function. The Fortran project builds fine, but when I callFRin my C++ code, I get an error LNK2019: unresolved external symbol _SQRT referenced in function _FR. What do I need to include in my project so that I can use these functions?

Thanks for the help.

0 Kudos
1 Solution
Steven_L_Intel1
Employee
4,461 Views
So you didn't see this warning?

FortranTest\FortranTest\test.f(11): warning #7319: This argument's data type is incompatible with this intrinsic procedure; procedure assumed EXTERNAL. [SQRT]

In subroutine FSROOT, you have a call to SQRT(N). N is not declared, so, by the rules of Fortran, it is implicitly INTEGER. (Variables starting with I through N are integer, all others are real. Hence the Fortran joke: "God is real, unless declared integer.")

SQRT is not defined for the integer type, so you get the warning. The compiler then assumes you mean some external routine SQRT which you didn't provide.

Assuming that you want to take the square root of the value of N, you will have to write it as:

FSROOT = SQRT(REAL(N))

The REAL() intrinsic converts the argument to the REAL datatype.

By the way, at least in this example, you don't need the ATTRIBUTES DLLEXPORT as you are building a static library. It does no harm.

View solution in original post

0 Kudos
10 Replies
mecej4
Honored Contributor III
4,461 Views
The C/C++ compiler driver is treating the .OBJ files that the Fortran produced as if they were also C/C++ compiler-produced.

You may specify the appropriate Fortran library that contains the intrinsic functions to be used when linking.
0 Kudos
lls121
Beginner
4,461 Views
Thanks for the response, mecej4. Could you be a little more specific regarding how to do this? Where would I specify the appropriate Fortran library within Visual Studio 2010?
0 Kudos
lls121
Beginner
4,461 Views
Hi Steve,

I have followed these instructions, but I still get this error. Any ideas?
0 Kudos
Steven_L_Intel1
Employee
4,461 Views
Are you getting any warnings during the Fortran compilation? That you get a reference to _SQRT suggests to me that you're also seeing a warning that the arguments to an intrinsic don't match a supported signature and hence an external reference is used.
0 Kudos
lls121
Beginner
4,461 Views
I am not getting any warnings when I compile the Fortran static library. I just get these two errors in the C++ project:

error LNK2019: unresolved external symbol _SQRT referenced in function

error LNK1120: 1 unresolved externals

However, if I make a Fortran dynamic-link library, I receive these errors during the Fortran compilation instead of the C++ compilation.

0 Kudos
Steven_L_Intel1
Employee
4,461 Views
Would you please attach the Fortran project, including sources, as a ZIP file? Or at least a sample project that shows this error?
0 Kudos
lls121
Beginner
4,461 Views
I have attached my project. Thanks again for the help. I really appreciate it.

I am completely new to Fortran, so it could easily be a programming issue.
0 Kudos
Steven_L_Intel1
Employee
4,462 Views
So you didn't see this warning?

FortranTest\FortranTest\test.f(11): warning #7319: This argument's data type is incompatible with this intrinsic procedure; procedure assumed EXTERNAL. [SQRT]

In subroutine FSROOT, you have a call to SQRT(N). N is not declared, so, by the rules of Fortran, it is implicitly INTEGER. (Variables starting with I through N are integer, all others are real. Hence the Fortran joke: "God is real, unless declared integer.")

SQRT is not defined for the integer type, so you get the warning. The compiler then assumes you mean some external routine SQRT which you didn't provide.

Assuming that you want to take the square root of the value of N, you will have to write it as:

FSROOT = SQRT(REAL(N))

The REAL() intrinsic converts the argument to the REAL datatype.

By the way, at least in this example, you don't need the ATTRIBUTES DLLEXPORT as you are building a static library. It does no harm.
0 Kudos
lls121
Beginner
4,461 Views
Thanks for the help Steve!
0 Kudos
Reply