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.

Linking to libtiff

gib
New Contributor II
1,070 Views
I'm trying to use Sam Leffler's libtiff library to read/write tiff files from Fortran. I have built the library with icl, and the test programs work. I have also tested calling a C procedure from Fortran. Now I have some test C code (my_write.cpp) which I compile with icl to my_write.obj, and a Fortran program ftest.f90 which calls the C procedure. All seems OK until I try to link these two with libtiff.lib. I've tried it from the command line (in which case the linker complains about multiply defined symbols, and tells me to use /NODEFAULTLIB:MSVCRT, but that gives far more errors), and from within VS, but that gives a lot of "unresolved external symbol" errors.

It would be great if someone has already figured out how to link to libtiff.lib, otherwise I'd appreciate more general advice about linking to a C-created library.

Thanks
Gib
0 Kudos
5 Replies
Jugoslav_Dujic
Valued Contributor II
1,070 Views
Quoting - gib
I'm trying to use Sam Leffler's libtiff library to read/write tiff files from Fortran. I have built the library with icl, and the test programs work. I have also tested calling a C procedure from Fortran. Now I have some test C code (my_write.cpp) which I compile with icl to my_write.obj, and a Fortran program ftest.f90 which calls the C procedure. All seems OK until I try to link these two with libtiff.lib. I've tried it from the command line (in which case the linker complains about multiply defined symbols, and tells me to use /NODEFAULTLIB:MSVCRT, but that gives far more errors), and from within VS, but that gives a lot of "unresolved external symbol" errors.

It would be great if someone has already figured out how to link to libtiff.lib, otherwise I'd appreciate more general advice about linking to a C-created library.


What does

/dumpbin:directives libtiff.lib

(ran from Ifort command prompt) say about defaultlibs?


0 Kudos
gib
New Contributor II
1,070 Views
Quoting - Jugoslav Dujic

What does

/dumpbin:directives libtiff.lib

(ran from Ifort command prompt) say about defaultlibs?


I'm not familiar with dumpbin. The command you gave doesn't seem to work, but this one does:
dumpbin /directives libtiff.lib
and gives a great deal of info, most of it repeating the same thing many times. I've attached the output. Does this help?

Should I be trying to build my program at the command line or in VS?
Would it be easier to combine libtiff.lib and my_write.c as a DLL?
0 Kudos
gib
New Contributor II
1,070 Views
Quoting - Jugoslav Dujic

What does

/dumpbin:directives libtiff.lib

(ran from Ifort command prompt) say about defaultlibs?


I am linking like this:
link ftest.obj my_write.obj libtiff.lib

Since libtiff uses -defaultlib:"MSVCRT" I thought I should look at the other object files:

Dump of file ftest.obj

File Type: COFF OBJECT

Linker Directives
-----------------
-defaultlib:"ifconsol"
-defaultlib:"libifcoremt"
-defaultlib:"libifport"
-defaultlib:"libmmt"
-defaultlib:"LIBCMT"
-defaultlib:"libirc"
-defaultlib:"svml_disp"
-defaultlib:"OLDNAMES"
-defaultlib:"ifconsol"
-defaultlib:"libifcoremt"
-defaultlib:"libifport"
-defaultlib:"libmmt"
-defaultlib:"LIBCMT"
-defaultlib:"libirc"
-defaultlib:"svml_disp"
-defaultlib:"OLDNAMES"

Dump of file my_write.obj

File Type: COFF OBJECT

Linker Directives
-----------------
-defaultlib:"libmmt"
-defaultlib:"LIBCMT"
-defaultlib:"libirc"
-defaultlib:"svml_disp"
-defaultlib:"OLDNAMES"
-defaultlib:"libmmt"
-defaultlib:"LIBCMT"
-defaultlib:"libirc"
-defaultlib:"svml_disp"
-defaultlib:"OLDNAMES"

It seems that while libtiff.lib uses msvcrt, the other object files both use libcmt. I'm guessing that I need to compile libtiff.lib so that it uses libcmt. Is this correct? I wonder how I can do that ...
0 Kudos
gib
New Contributor II
1,070 Views
I changed the makefile for libtiff.lib to get icl to use /MT and lib to use /NODEFAULTLIB:"msvcrt". Now I see libcmt in the dumpbin output for libtiff.lib, and my code links and runs successfully.

Thanks for the pointer.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,070 Views
Quoting - gib
I changed the makefile for libtiff.lib to get icl to use /MT and lib to use /NODEFAULTLIB:"msvcrt". Now I see libcmt in the dumpbin output for libtiff.lib, and my code links and runs successfully.

Thanks for the pointer.

You're welcome -- y'know, different time zones :-).

You found one solution to the problem, i.e. build the lib and exe with same C run-time library. I'd rather try building the library with /Zl (Omit Default Library Name) -- not to save space, but to strip those nasty references to libm*.lib from the library. Tentatively, in this way you should be able to build the library with any RTL setting of the exe (although MSVC++ has some ugly features which might prevent that).
0 Kudos
Reply