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

C Project calling a Fortan Library

bsi
Beginner
2,243 Views

We have a C project that calls a fortran library. This fortran library is created from a separate project that we've made-- myFortranLibrary.lib. We compiled the fortran library without error. We placed this library into the C project's directory. But when webuild the C project, we get the following error:

Error1fatal error LNK1181: cannot open input file 'ifconsol.lib'

this is the only error we get. We checked the manual and tried both the listed options: 1) setting "Disable Default Library Search Rules" to No, and not listing 'ifconsol.lib' or 'libifcore.lib' under "Additional Dependencies" in the C project, and 2) setting "Disable Default Library Search Rules" to Yes, and listing, 'ifconsol.lib' and 'libifcore.lib' under "Additional Dependencies". However, both of these cases result in the above error message.

Any ideas? Thank you.

0 Kudos
16 Replies
Steven_L_Intel1
Employee
2,243 Views
You need to add the path to the Intel Fortran LIB folder to the C++ list of library directories using Tools..Options..Projects..C++ Directories.
0 Kudos
bsi
Beginner
2,243 Views

We did as you sugggested. We now get the following error message:

Error23fatal error LNK1104: cannot open file 'IFWIN.LIB'

0 Kudos
Steven_L_Intel1
Employee
2,243 Views
Curious. Is that file in the C:Program FilesIntelCompilerFortran9.1IA32Lib folder? Is that the folder you added to the directories list?
0 Kudos
bsi
Beginner
2,243 Views

Steve,

I have joined in the effort - here is what we have gotten to:

We have a C program - calling a Fortran created Lib - we changed the lib creation settings to add: under libraries yes to common windows libraries and yes to Portlib

and we added the lib you had for the search lib

This removed all errors for Fortran

We also have a security lib we link to that had many errors (missing functions) - by googling, we found the libraries that have the functions and removed all those errors.

The library line is:

SKeyLN32.lib Ws2_32.lib Netapi32.lib Mpr.lib FB-multipier_lib.lib

FB_Mul.. is our Fortran lib

SkeyLN32 is the security and (Ws2_32.lib Netapi32.lib Mpr.lib) were needed to resolve external problems.

We are almost there!

The last error is:

Error2error LNK2001: unresolved external symbol _WinMain@16LIBCMT.lib

This program has a main funciton which calls the security function and then the fortran function.

here is the main function fragment:

#include

#include

#include

#include

"Valid_Eng.h"

extern

void fbpier_lib(long* lLicenseID, int* bDemo, long* ncmarg, long* ngridmax, char* cmdstr );

void

main(int argc, char* argv[])

What are we missing?


0 Kudos
bsi
Beginner
2,243 Views

Steve,

I realized that the setting was for a windows program - but this is a console app!

I re-set to a console app and we are OK

On to the next problem - may get back to you

Marc

0 Kudos
bsi
Beginner
2,243 Views

OK,

Final problem:

We have a Fortran program - calling a C library (the C library is used as an interface to get an open file dialog)

When we link the programs we get:

Error675 error LNK2005: ___lookuptable already defined in LIBCMT.lib(output.obj)FB-MultiPier
Error676 error LNK2005: ___wnullstring already defined in LIBCMT.lib(output.obj)FB-MultiPier

So: How do we avoid the conflict? (I can not find the functions in any library)

Is there a simple way to call the open file dialog from quickwin (to replace the C call?)

Thanks

Marc

0 Kudos
anthonyrichards
New Contributor III
2,243 Views

The answer is 'yes'. An example:

USE DFLIB
USE DFWINTY
USE DFWIN

IMPLICIT NONE

! Define an OPENFILENAME structure (see Help for GETOPENFILENAME)

TYPE (T_OPENFILENAME) FRED

INTEGERKIND=4) IRET
! DEFINE YOUR FILTER LENGTH AND DIMENSION
CHARACTER(LEN=22)FILTER(3)
CHARACTER($MAXPATH)FILENAME, STARTDIR,DLGTITLE
!* SET UP FILE SEARCH FILTERS TO APPEAR IN SEARCH BOX
! These must appear in pairs, the list terminated wih a null entry
!so the array FILTER must be dimensioned an odd number
! Note that the filter entriesmust be a null-terminated C-strings
!The characters between the quotes+1 for the null character mustbe equal to or less
! than the length defined for the FILTER elements
FILTER(1) = "My files (*.XYZ)"C
FILTER(2) = " *.XYZ"C
FILTER(3) = ""C
! SET UP START DIRECTORY FOR SEARCH.
! Note itmust be a null-terminated C-string
STARTDIR='My_start_directory'C
! SET THE OPENFILE DIALOG TITLE, also a null-terminated C-string
DLGTITLE='Looking for my file'C
! GET THE HANDLE OF THE MAIN APPLICATION WINDOW SO THAT THE FILEOPEN
! DIALOG BOX CAN BE ATTACHED TO IT BY SPECIFYING THE APPLICATION WINDOW
! AS THE OWNER USINGGETHWNDQQ

FRED%HWNDOWNER = GETHWNDQQ (QWIN$FRAMEWINDOW)
FRED%HINSTANCE = NULL
FRED%LPSTRFILTER = LOC(FILTER(1))
FRED%LPSTRCUSTOMFILTER = NULL
FRED%NMAXCUSTFILTER = NULL
FRED%NFILTERINDEX = 1
FRED%LPSTRFILE = LOC(FILENAME)
FRED%NMAXFILE = LEN(FILENAME)
FRED%LPSTRFILETITLE = NULL
FRED%NMAXFILETITLE = NULL
FRED%LPSTRINITIALDIR = LOC(STARTDIR)
FRED%LPSTRTITLE = LOC(DLGTITLE)
! choose your own flags - see Help for options
! combine them using multiple IOR's if necessary
FRED%FLAGS = IOR(OFN_FILEMUSTEXIST,OFN_PATHMUSTEXIST)
FRED%NFILEOFFSET = NULL
FRED%NFILEEXTENSION = NULL
FRED%LPSTRDEFEXT = NULL
FRED%LCUSTDATA = NULL
FRED%LPFNHOOK = NULL
FRED%LPTEMPLATENAME = NULL

FRED%LSTRUCTSIZE = SIZEOF(FRED)
! Start the get/open file dialog
IRET = GETOPENFILENAME(FRED)
! If you selected a file and pressed the OK button, IRET will be non-zero
! so test it
! FILENAME should then contain the selected file

0 Kudos
Jugoslav_Dujic
Valued Contributor II
2,243 Views
Ideally, every static library (.lib), C or Fortran regardless should be built with /Zi switch (in IVF, it's also called /libdir:noauto if I recall correctly).

By default, compiler inserts "hyperlinks" or "hints to the linker" into .obj files to the .lib file associated with the setting specified in Properties/Libraries/Run-time library. If those settings are inconsistent in various .objs and .libs you build together, you'll get a conflict, as above. /Zi or /libdir:noauto prevents insertion of those "hints", leaving the ultimate choice of run-time library to the .exe's project.

See Steve's article on Multiple C library syndrome for details... oh, no, it's gone again. Steve?


0 Kudos
bsi
Beginner
2,243 Views

Thanks. We tried doing this but to no avail. We weren't sure exactly where to add /Zi, so we added it to the OpenF property pages, under Configuration Properties->C/C++->CommandLine, under Additional options. However, when we did this and rebuilt the project, we got the same error messages as before.

In the property pages for our fortran library (the one we created), /Zi is already listed, under Configuration Properties/Fortran/Command Line.

0 Kudos
bsi
Beginner
2,243 Views

Thanks. Any suggestion on exactly how to implement this? We will try to do the following steps:

-Create a new file with your code, customized to our project (replacing 'Fred' with our own reference). We will put the filename in the argument list for this routine.

- Include this file name in our project, so that it can be called, as a routine.

- call thisroutine from our existing code, supplying thefile name in the argument list, to receive the user's selection.

Please let us know if we should be doing something else/differently. Thank you again.

0 Kudos
Steven_L_Intel1
Employee
2,243 Views
JugoslavDujic:
See Steve's article on Multiple C library syndrome for details... oh, no, it's gone again. Steve?

Old forum bookmarks are no longer valid. Did I ever post the MCLS article? (The original was by Lorri Menard and updated by Peter Karam.) I'm typing this from an airport, so I'll post the MCLS article when I return to work next Wednesday.
0 Kudos
bsi
Beginner
2,243 Views

We've implemented this, with your code nearly verbatim. We did make the following changes:

FILTER(1) = "Input Files (*.in)"C
FILTER(2) = "AllFiles *.*"C

Problem is that no files of type .in (or any other files) are displayed in the dialog. I've double checked to make sure there are .in files at the locations we are browsing to, and the .in files are indeed present.

Any thoughts? Thanks again.

0 Kudos
anthonyrichards
New Contributor III
2,243 Views

..and the reason is because you broke the code by making your changes. You are trying to search for files with the search string 'All files *.*' !

Examine what I posted and you will see that all you need to do is change 'XYX' to 'IN' (adding an extra space somewherein the character strings to keep the lengths the same). The first entry, FILTER(1) displays a description of the files, he second, FILTER(2) is the search string, so if you change the search string back to *.in it should work. If you want to have an 'All files'option, add two more elements to FILTER, redimensioning it as FILTER(5), making FILTER(3) ='All files (*.*)'C and FILTER(4)=' *.*'C and moving the termination string to FILTER(5).

If you want to select 'All files' in the search box as default,set FRED%nfilterindex=3.

Hope this helps.

0 Kudos
Lorri_M_Intel
Employee
2,243 Views

This is a tiny nit ... the command line switch is /Zl (capital Z lowercase L) not /Zi

/Zi means "debug"

- Lorri

0 Kudos
jugoslavdujic2
Beginner
2,243 Views
Thanks Lorri; I was certain it was /Zi, (and I likely posted that on several occasions before) :-D
0 Kudos
bsi
Beginner
2,243 Views

Problem fixed!!

We cannot thank you enough for all the quick and helpful responses.

Thanks!

0 Kudos
Reply