errors in linking Fortran lib from Visual C++

I’ve compiled a lib using PGI Fortran. I’m trying to link it to Visual C++ program but I get the followin error:

error LNK2019: unresolved external symbol y12maf referenced in function "

I’ve added the library path and also the lib file in the Project properties. Also, there is an extern C definition.

BTW, all of this was working with the older Visual C++ IDE although the fortran files were compiled with Intel Compiler. I’m simply trying to port it this new environment.

Perhaps some naming convention and/or arguments passing issue. Help appreciated. Thanks

Dee

Hi Dee,

Most likely your calling convention is mismatched between Fortran and C++. Given the name symbol name “y12maf” I think you’re compiling using cdecl and have appended an underscore to the function name.

Are you using Win32 or Win64? If you’re using Win32, try compiling your code with “-Miface=unix” (If you’re using PVF, this is set from the project property page “Fortran->External Procedure->Calling Convention->Unix”).

Note, full details on Inter-language calling and Win32 calling conventions can be found in Chapter 12 of the PGI User’s Guide.

Hope this helps,
Mat

Hi Mkcolg,

I found that the “-Miface=unix” only available in Win32 project. What should I do when build the x64 project?

Thanks,
Zhanghong Tang

Hi Zhanghong Tang,

Win64 has only one calling convention so -Miface is not needed. If you are getting similar errors, you are most likely encountering normal C++ calling Fortran issues having to do with name mangling and Fortran symbol names. Take a look at Chapter 12 in the PGI User’s Guide. It gives detailed information on C++ calling Fortran as well as Fortran calling C++.

Hope this helps,
Mat

Hi Mat,

Thank you very much for your kindly reply. My project works well under Win7 x64 + VS2008 + Intel Visual Fortran 11.1 + Intel MKL 10.3 (both Win32 project and x64 project).

I want to test whether it works under Win7 x64 + VS2008 + PGI Fortran + Intel MKL 10.3 (both Win32 project and x64 project).

The structure of the project is as follows:
VS2008 C++ main program
–5 VS2008 C++ static library
–1 Intel Visual Fortran static library

6 project will generate 6 static libraries and the C++ main program will include these static libraries.

Now I changed the Intel Visual Fortran static library to the PGI Fortran static library (also integrated into the VS2008) and rebuild the project, the errors appears.

In the C++ main program, except the 6 static libraries, I also linked the following libraries into the project:
mkl_pgi_thread.lib
mkl_intel_lp64.lib
mkl_core.lib
libpg.lib
libpgc.lib
libpgf90.lib
libpgf902.lib
libpgf90rtl.lib
libpgf90_rpm1.lib
libpgftnrtl.lib

Do you have any suggestion without modifying the code (there are too many code to be modified if need to do)?


Thanks,
Zhanghong Tang

Hi,

We would need more information about where and how y12maf is called and where it is defined and how it is compiled. Is y12maf a C++ routine called from Fortran?

Can you provide a small test case?

Hongyon

Hi Hongyon,

Just now I built a test case which is similar to my original case. How can I send the case to you?

Thanks,
Zhanghong Tang

Hi,

Please send to trs@pgroup.com.

Thanks,
Hongyon

Hi Hongyon,

I have sent the case to the email address.

Thanks,
Zhanghong Tang