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

Creating Static Library and Linking

acobulareddy
Beginner
785 Views

I am using Intel Fortran 9.1 and VC++ 2005.

I have two programs

PROGRAM main
write(*,*)"Calling C Function"
CALL ChgStr()
write(*,*)"Back From C Function"
END PROGRAM main

#include
#include
void chgstr()
{
printf("\nIn C function");
}

I would like to create a static library of C program and use it for fortran executable.

Please suggest how to do it.

I did the following.

cl -c chgstr.c
created a object file chgstr.obj

lib /out:clib.lib chgstr.obj
created static library for chgstr.obj

ifort /names:lowercase /extend_source -c fmain.f
created fmain.obj

ifort fmain.obj clib.lib
(to create executable of fmain.obj clib.lib but gave following error)
Intel Fortran Compiler for Intel EM64T-based applications, Version 9.1 Build 20070109
Copyright (C) 1985-2007 Intel Corporation. All rights reserved.

Fatal error cannot open "ifconsol"
ifort: error: problem during multi-file optimization compilation (code 1)

tried with the link command
link /out:1.exe fmain.obj clib.lib
gave the following error
Microsoft Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

LINK : fatal error LNK1104: cannot open file 'ifconsol.lib'

Please suggest how to do.

Is there a way I can do it through IDE (VS2005)

Thanks,
Chandra

0 Kudos
1 Solution
Steven_L_Intel1
Employee
785 Views
Quoting - acobulareddy
tried the folliowing
C:Documents and Settings105032692DesktopDesktopc-fortran1>link /out:1.exe fmain.obj clib.lib "C:Program FilesIntelCompilerFortran9.1ItaniumLibifconsol.lib"
Microsoft Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
LINK : fatal error LNK1561: entry point must be defined
still it is not working.

In your original post you indicated that you were using the EM64T compiler but here I see you referencing Itanium libraries. These are not the same! What kind of system are you building for?

I recommend using the ifort command to link.

View solution in original post

0 Kudos
8 Replies
lklawrie
Beginner
785 Views


When I did this recently (all through the IDE), I just added the lib to my fortran project.

Linda

0 Kudos
tung_nguyen
Beginner
785 Views


When I did this recently (all through the IDE), I just added the lib to my fortran project.

Linda

I suggest adding the path of the ifconsol library to the link command.

Tung.

0 Kudos
acobulareddy
Beginner
785 Views
May I know the procedure you have followed to add it through IDE.
What is the version of VS you have. I have VS2005, Does it have the capability


When I did this recently (all through the IDE), I just added the lib to my fortran project.

Linda

0 Kudos
acobulareddy
Beginner
785 Views
tried the folliowing
C:Documents and Settings105032692DesktopDesktopc-fortran1>link /out:1.exe fmain.obj clib.lib "C:Program FilesIntelCompilerFortran9.1ItaniumLibifconsol.lib"
Microsoft Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
LINK : fatal error LNK1561: entry point must be defined
still it is not working.

I suggest adding the path of the ifconsol library to the link command.

Tung.

0 Kudos
Steven_L_Intel1
Employee
786 Views
Quoting - acobulareddy
tried the folliowing
C:Documents and Settings105032692DesktopDesktopc-fortran1>link /out:1.exe fmain.obj clib.lib "C:Program FilesIntelCompilerFortran9.1ItaniumLibifconsol.lib"
Microsoft Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
LINK : fatal error LNK1561: entry point must be defined
still it is not working.

In your original post you indicated that you were using the EM64T compiler but here I see you referencing Itanium libraries. These are not the same! What kind of system are you building for?

I recommend using the ifort command to link.

0 Kudos
acobulareddy
Beginner
785 Views
even I tried with IA32 and got the same error
C:Documents and Settings105032692DesktopDesktopc-fortran1>link /out:1.exe fmain.obj clib.lib "C:Program FilesIntelCompilerFortran
9.1IA32Libifconsol.lib"
Microsoft Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
LINK : fatal error LNK1561: entry point must be defined
I am more interested with link because VS uses LINK command to create executable (VS uses ifort only for creating objects)
even I tried with ifort O gpt the following errors
C:Documents and Settings105032692DesktopDesktopc-fortran1>ifort fmain.obj clib.lib /exe:fmain.exe
Intel Fortran Compiler for 32-bit applications, Version 9.1 Build 20061103Z Package ID: W_FC_C_9.1.033
Copyright (C) 1985-2006 Intel Corporation. All rights reserved.
Microsoft Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
-out:fmain.exe
-subsystem:console
fmain.obj
clib.lib
fmain.obj : error LNK2019: unresolved external symbol __intel_new_proc_init referenced in function MAIN__
fmain.obj : error LNK2019: unresolved external symbol for_set_reentrancy referenced in function MAIN__
fmain.obj : error LNK2019: unresolved external symbol for_write_seq_lis referenced in function MAIN__
fmain.obj : error LNK2019: unresolved external symbol CHGSTR referenced in function MAIN__
LINK : error LNK2001: unresolved external symbol mainCRTStartup
fmain.exe : fatal error LNK1120: 5 unresolved externals
I tried by changing the case of CHGSTR in C function. that is also not eliminating the unresolved symbol CHGSTR referenced in function main.

In your original post you indicated that you were using the EM64T compiler but here I see you referencing Itanium libraries. These are not the same! What kind of system are you building for?

I recommend using the ifort command to link.

0 Kudos
Steven_L_Intel1
Employee
785 Views

It would help if I could see all the commands used to build this application. There's something wrong in either the environment or an inconsistency in the build commands but I am not seeing everything. Part of the problem is that there is nothing supplying the main entry point (which is typically in a C run-time library. I am also puzzled by the routine names shown in the linker errors as it looks as if they are EM64T references. You cannot mix architectures - you must be consistent in the tools you use.

0 Kudos
sarma_amras
New Contributor I
785 Views
acobulareddy

You are getting the error with ifconsol.lib because you might be trying to link in the normal command prompt window.

Try to do the link in the Intel IA-32 command prompt.

Regards

Kameswara Sarma


0 Kudos
Reply