Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29284 Discussions

How to build a Fortran static library of AMD64?

Zhanghong_T_
Novice
1,150 Views
Hi all,
I am trying to build a Fortran static library of AMD64 to be called by a C++ project. I use the following command line:
ifort *.f /libs /link /machine:amd64 /subsystem:windows /out:test.lib
However, it displayed that no '_MAIN_' entry exist? How can I generate a static library like this?
Another way is the following two command lines:
ifort *.f /compile_only
lib *.obj /machine:amd64 /subsystem:windows /out:test.lib
Then it generated the static library I wanted. However, when I linked it into the C++ project by a .mak file which has the following linker setting (only listedpart of its settings):
LINK32=test.lib bufferoverflowu.lib ifconsol.lib libifcore.lib libifport.lib libirc.lib libm.lib /machine:amd64 /subsystem:windows
The following error information displayed:
libifcore.lib(for_init.obj) : error LNK2019: unresolved external symbol __argc referenced in function for_rtl_init_
libifcore.lib(for_init.obj) : error LNK2019: unresolved external symbol __argv referenced in function for_rtl_init_
libifcore.lib(for_init.obj) : error LNK2019: unresolved external symbol _pxcptinfoptrs referenced in function GETEXCEPTIONPTRSQQ
Can anyone tell me how to solve my problem?
Thanks,
Zhanghong Tang
0 Kudos
5 Replies
Steven_L_Intel1
Employee
1,150 Views
You can't create a .lib directly from the ifort command. You have to first create .obj files (use /c when compiling to prevent linking) and then use the lib command to create the library. See the User's Guide on the details of using "lib".
0 Kudos
Zhanghong_T_
Novice
1,150 Views
Can you tell me why my second method is wrong?
Thanks,
Zhanghong Tang
0 Kudos
Steven_L_Intel1
Employee
1,150 Views
Without seeing all the options, including how the C++ code was compiled, I can't say for sure. Compiled that way, the Fortran code is expecting the static, single-threaded C libraries (libc). You should not have to specify the Fortran libraries, as there are linker directives inserted to pull those in. Make sure you compile the Fortran code with the same run-time library option as the C++ code (/MD, /MT, whatever) and don't list the Fortran libraries on the link line.
0 Kudos
Zhanghong_T_
Novice
1,150 Views
Hi Steve,
Thank you very much for your kindly reply.
Now I have listed the compile and link option in my C++ project.
F90=df.exe
CPP=cl.exe
CPP_PROJ=/nologo /MD /W3 /GX /O2 /Op /GR /D "NDEBUG" /D "WIN64" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Fp"$(INTDIR) emp AMD64.pch" /Yu"stdafx.h" /Fo"$(INTDIR)" /Fd"$(INTDIR)" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
...
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /WIN64
RSC=rc.exe
RSC_PROJ=/l 0x409 /fo"$(INTDIR) emp.res" /d "NDEBUG" /d "_AFXDLL"
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR) emp AMD64.bsc"
BSC32_SBRS=

LINK32=link.exe
LINK32_FLAGS=rpcrt4.lib version.lib FortranLib*.lib netapi32.lib OPENGL32.LIB GLU32.LIB GLAUX.LIB /nologo /FORCE:MULTIPLE /subsystem:windows /STACK:0x5f5e100,0x5f5e100 /incremental:no /pdb:"$(OUTDIR) emp.pdb" /nodefaultlib:"libc.lib" /out:"$(OUTDIR) emp.exe" /machine:AMD64
The Fortran static library is placed in the directory of fortranlib, in the C++ project, no fortran code exists and there is no Fortarn compiler in the AMD64 machine which compile the C++ project.
The C++ compiler I used for AMD64 is shown in the picture attached.
Can you help me to modify the options of IFORT and LIB to generate a Fortran Static Library to be called by the C++ project?
Thanks,
Zhanghong Tang
0 Kudos
Zhanghong_T_
Novice
1,150 Views
re
0 Kudos
Reply