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

Link C static library (.lib) into Fortran Application

mftech
Beginner
1,791 Views
Hello,

i have problems integrating C-static libs into a Fortran
Application. In the Fortran Code are several functions referenced.
For example:
...
integer, external :: pfopen
...
File%unit = pfopen(n_name, File%name, File%mode)
...

These functions are located in the C-static library (PACT-PDB, http://pact.llnl.gov ). I have compiled the PACT-PDB and got several .lib files:
panacea.lib pdb.lib pgs.lib pml.lib ppc.lib scheme.lib scorelib sx.lib

If i specify these libs under "Linker->Additional Dependencies" i still get the following link errors:

-----------------------<
------ Build started: Project: flmnav, Configuration: Debug|Win32 ------

Linking...
Link /OUT:"Debug/flmnav.exe" /INCREMENTAL /NOLOGO /LIBPATH:"C:�1_UserchristianTUMDAvs_flmnavpactpactworkpactdevwinnt4.0lib" /NODEFAULTLIB:"libcmtd.lib" /DEBUG /PDB:"Debug/flmnav.pdb" /SUBSYSTEM:CONSOLE panacea.lib pdb.lib pgs.lib pml.lib ppc.lib scheme.lib score.lib sx.lib /C90
Debug/error.obj Debug/get_cpu_time.obj Debug/halt.obj Debug/hp_cpu_time.obj Debug/ijk_l123.obj Debug/l123_ijk.obj Debug/asics.obj Debug/filemod.obj
...
...
Debug/write_body.obj Debug/write_coeff.obj Debug/write_coeff_n.obj Debug/write_conv2.obj Debug/write_surf.obj Debug/wrparam.obj Debug/wrqnf_flow.obj Debug/wrqntecu_time.obj Debug/wrseglog.obj Debug/wrsurf_pdb.obj
Link: executing 'link'
LINK : warning LNK4044: unrecognized option '/C90'; ignored
filemod.obj : error LNK2019: unresolved external symbol _PFOPEN referenced in function _FILEMOD..OPEN_FILE
filemod.obj : error LNK2019: unresolved external symbol _PFCLOS referenced in function _FILEMOD..CLOSE_FILE
wrsurf_pdb.obj : error LNK2001: unresolved external symbol _PFGERR
filemod.obj : error LNK2019: unresolved external symbol _PFGERR referenced in function _FILEMOD..CLOSE_FILE
dbmmod.obj : error LNK2019: unresolved external symbol _PFGERR referenced in function _DBMMOD..WRPDB_DBM
...
...
Debug/flmnav.exe : fatal error LNK1120: 19 unresolved externals

flmnav build failed.
-----------------------<

I am using Visual Studio.Net 2003, Intel C++ 7.1 and Intel Fortran 7.1 (all for Windows).
Can anyone help me get out of this problem ?

Thanks in advantage,
Christian
0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,791 Views
I can't find the description of these routines on the PACT web site. I'm wondering if the library assumes that C and Fortran use the same calling conventions. If these are C routines, Fortran is upcasing the names whereas C would leave the case alone.

Steve
0 Kudos
mftech
Beginner
1,791 Views
Hi Steve,
the libraries do work together with fortran. We have them already compiled on UNIX,Linux and VPP(Hitachi). They're simply named in the linker's parameter list. Here's the documentation for PACT usage withing Fortran under Linux:

-->
Usage of PACT on the IA32 Linux Cluster
The PACT root directory (denoted as $PACTROOT in the following) is /usr/local/sys/lib/pact. You will need to set the following environment variables.
export PATH=/usr/local/sys/lib/pact/bin:$PATH
export SCHEME=/usr/local/sys/lib/pact/scheme
export ULTRA=/usr/local/sys/lib/pact/scheme

For building applications please add the include path

icc -c ... -I$PACTROOT/include foo.c

to the C Compiler call, and for linkage (some or all of) the PACT libraries are required:

icc -o myprog ... -L$PACTROOT/lib -lpanacea -lpdb -lpgs -lpml -lppc -lpsmm -lscheme -lscore -lsx

If you need to link in PACT libraries with the Fortran Compiler, please use the command line
efc -Vaxlib -o myprog ... -L$PACTROOT/lib -lpanacea -lpdb -lpgs -lpml -lppc -lpsmm -lscheme -lscore -lsx
--<

In the file "PDFIA.C", the Fortran interface functions are defined.

Under Windows (XP), i've tried alot of compiler-settings within Visual Studio.Net, but it's still stating that link error.

Christian
0 Kudos
Steven_L_Intel1
Employee
1,791 Views
My guess is a name mismatch. Do a:

dumpbin -symbols

on each of the libraries and look for the routine names you want. Are they uppercase or lowercase?

Steve
0 Kudos
mftech
Beginner
1,791 Views
Finally, i got it working.

I had to change the "External Procedure" settings to:
External Name Interpretation: Lower Case
Append Underscore to External Names: Yes.

Thanks
Christian
0 Kudos
Steven_L_Intel1
Employee
1,791 Views
Pretty much what I thought. The C library was built assuming typical UNIX Fortran name decoration. Often there's a symbol you can define in a header to change the name construction (upcase/downcase, append underscore or no, etc.)

Steve
0 Kudos
mftech
Beginner
1,791 Views
Correct,
i can now build the solution without any changes to the source code.

Thank you
Christian
0 Kudos
Reply