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

Error LNK2019 when using Fortran Intrinsic Functions

lls121
초급자
5,731 조회수

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 포인트
1 솔루션
Steven_L_Intel1
5,731 조회수
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 포인트
10 응답
mecej4
명예로운 기여자 III
5,731 조회수
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 포인트
lls121
초급자
5,731 조회수
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 포인트
lls121
초급자
5,731 조회수
Hi Steve,

I have followed these instructions, but I still get this error. Any ideas?
0 포인트
Steven_L_Intel1
5,731 조회수
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 포인트
lls121
초급자
5,731 조회수
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 포인트
Steven_L_Intel1
5,731 조회수
Would you please attach the Fortran project, including sources, as a ZIP file? Or at least a sample project that shows this error?
0 포인트
lls121
초급자
5,731 조회수
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 포인트
Steven_L_Intel1
5,732 조회수
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 포인트
lls121
초급자
5,731 조회수
Thanks for the help Steve!
0 포인트
응답