[Insight-users] using vcf2c.lib

David Rich David.Rich@trw.com
Wed, 03 Apr 2002 10:02:25 -0500


Jeffrey,
I'm not very good with ITK, but might be able to help with the problems =
you are having.  These aree "typical" Microsoft problems.  Microsoft has =
never bothered to clean up references to multiple libraries.  As a result, =
you may create a library that is linked with a release version of one of =
the MS libs and then run into a conflict when you try to create a debug =
version of an executable--or other lib--that also contains a reference to =
the same lib is linked/compiled into one of the libs you link in.  In =
general, the whole thing gets frustrating.

Anyway, that is the beginnings of your problem below.  The first problem =
is the "_exit" function whick your current compilation tries to access =
through the MS LIBC.lib, not a debug version, but runs into a conflict =
because the debug version is already found in MSVCRTD.lib.  The "D" at the =
end of the lib name tells you that it is the debug version.

Usually the simplest approach is to make sure that all of the libs you are =
using are either debug versions or all are release versions.  You can do =
this by going into the "Project/Settings" tab, go to the C/C++ tab, select =
the "Code Generation" Category, and then off to the right select the right =
type of library to create.  Since a previous build used one of the debug =
libs, you might want to switch to a debug lib for this one.  It also helps =
to make sure all of the other variations match too, that is, only use all =
Single-Threaded or all Multi-Threaded.

Proper selection there should clear up the "already defined" problems.

The second problem is that some of the functions you are calling have not =
been linked in through some library or are not included in the current =
compilation.  Make sure everything is properly included, first.  Second, =
remember that when you compile using the C++ compiler that it "mangles" =
the names.  This is to allow for function name overloading.  You think the =
function is overloaded but in reality the compiler mangles the name--in a =
predefined fashion--to make sure every function interface is unique.  =
Although you may not have function overloading, if the name gets mangled =
even just a little, the call to the function, using the non-mangled name, =
results in not finding the function called.

To avoid name mangling, you can block off all function definitions with:

extern "C"
{
      <include all function whose name you don;t want mangled here>
}

Or, if you want to do it better, you can specify that this is only to =
occur if the compiler is building C++ code:

#ifdef __cplusplus
extern "C"
{
#endif

      <include all function whose name you don;t want mangled here>

#ifdef __cplusplus
}
#endif

Between making sure you are compiling or linking everything and avoiding =
name mangling, that should help clear your second problem.

Good luck!

Dave Rich


>>> "Jeffrey Duda" <jtduda@seas.upenn.edu> 04/02/02 07:57AM >>>
Hi,
=20
I've been trying to write some itk classes that make use of fortran code =
converted via f2c.  This requires linking to the f2c library.  Under unix =
this does not seem to be a problem, however under windows i run into the =
linking errors shown below.  If anyone has any experience or ideas =
regarding this I would greatly appreciate the help.  Thanks.
=20
Jeffrey Duda
=20
=20
[vcf2c.lib included]
--------------------Configuration: FEMOutside - Win32 Debug----------------=
----
Compiling...
itkFEMLinearSystemWrapperItpack.cxx
Linking...
LIBC.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRTD.lib=
(MSVCRTD.dll)
LIBC.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRTD.li=
b(MSVCRTD.dll)
LIBC.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in =
MSVCRTD.lib(cinitexe.obj)
LIBC.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in =
MSVCRTD.lib(cinitexe.obj)
LIBC.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in =
MSVCRTD.lib(cinitexe.obj)
LIBC.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in =
MSVCRTD.lib(cinitexe.obj)
LIBC.lib(crt0.obj) : error LNK2005: _mainCRTStartup already defined in =
MSVCRTD.lib(crtexe.obj)
LIBC.lib(strcat.obj) : error LNK2005: _strcpy already defined in MSVCRTD.li=
b(MSVCRTD.dll)
LINK : warning LNK4098: defaultlib "MSVCRTD" conflicts with use of other =
libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "LIBC" conflicts with use of other =
libs; use /NODEFAULTLIB:library
U:/jtduda/src/itk/Insight-VC/bin/Debug/FEMOutside.exe : fatal error =
LNK1169: one or more multiply defined symbols found
Error executing link.exe.

[vcf2c.lib excluded]
--------------------Configuration: FEMOutside - Win32 Debug----------------=
----
Linking...
dsrc2c.obj : error LNK2001: unresolved external symbol _do_fio
dsrc2c.obj : error LNK2001: unresolved external symbol _e_wsfe
dsrc2c.obj : error LNK2001: unresolved external symbol _s_wsfe
dsrc2c.obj : error LNK2001: unresolved external symbol _pow_dd
dsrc2c.obj : error LNK2001: unresolved external symbol _i_sign
dsrc2c.obj : error LNK2001: unresolved external symbol _etime_
U:/jtduda/src/itk/Insight-VC/bin/Debug/FEMOutside.exe : fatal error =
LNK1120: 6 unresolved externals
Error executing link.exe.
=20
ALL_BUILD - 7 error(s), 0 warning(s)