[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference decwet::visual

Title:Microsoft Visual C++ bug reports and kits
Notice:Register in Topic 2. 5.Last for latest Kit
Moderator:DECWET::THOMASN
Created:Tue May 17 1994
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:521
Total number of notes:2938

467.0. "multiply defined symbs when linking C & fortran" by BLAZER::MIKELIS (Software Partner's Eng. MR01-3/F26) Fri Feb 21 1997 06:38

I've got a customer who is calling some fortran routines from a vc++4.0
app on NT 4.0 Alpha and is getting multiply defined symbol errors when 
linking. the code compiles alright. Any idea why? below is the make file 
and error output.

/james

    Category     :  nt
    OS Version   :  4.0
    System H/W   :  alpha


    Brief Description of Problem:
    -----------------------------

Here is the makefile which contains routines that call other routines in a
standard LIB.  This makefile is supplosed to create OVERLAY.DLL but fails 
with Fatal Error:  multiply defined symbols. 

Thanks,
Jim Case
CRC Infomation Systems, Inc
(602) 451-7474

Output from make:

link /noentry /out:overlay.dll /dll  @overlay.ooo overlay.exp dfordll.lib  
     \crc\overlay\insert\insert.lib  
     \crc\numeric\source\numeric.lib  
     \crc\kam\source\kam.lib 
     \crc\toolbox\source\toolbox.lib

Microsoft (R) 32-Bit Executable Linker Version 3.00.5270
Copyright (C) Microsoft Corp 1992-1995. All rights reserved.

addanypath.obj
addpath.obj
addprintpath.obj
addprintsycompath.obj
agebalbox.obj
attrf.obj
attrp.obj
attrs.obj
atype.obj
big.obj
blank.obj
box.obj
center.obj
chain.obj
chainm.obj
chkdate.obj
chkdaterng.obj
ckdgt.obj
clrarea.obj
clrln.obj
clrscr.obj
clrscr2.obj
cplace.obj
cpos.obj
crcbarcode.obj
crcedit.obj
crenam.obj
crtdisply.obj
crtinhp.obj
crtinput.obj
crtout.obj
cursoron.obj
date.obj
datei.obj
datrel.obj
day.obj
delay.obj
delnam.obj
dfilew.obj
dfl.obj
dirsrch.obj
displyhp.obj
doc.obj
dtimedrd.obj
dumbopen.obj
exinq.obj
expdate.obj
getkey.obj
getlog.obj
getscreen.obj
getsys.obj
getsys1.obj
getuser.obj
getvfub.obj
get_default_dir.obj
header.obj
hlinei.obj
ichr$.obj
idatrel.obj
ifauthorized.obj
inkey.obj
input.obj
ival.obj
jr30dasort.obj
lockit.obj
lpos.obj
lposd.obj
lpout.obj
lpplot.obj
lprint.obj
lprintd.obj
lptitl.obj
lvprnt.obj
mask.obj
mdata.obj
menudrvr.obj
nametomod.obj
okibar184.obj
okibarcode.obj
openbox.obj
ovreclock.obj
pfiler.obj
pfilew.obj
pfilewf.obj
phline.obj
pinit.obj
plotit.obj
pout.obj
pplot.obj
ppos.obj
ptitl.obj
pvline.obj
pvlinec.obj
pvlinel.obj
pvliner.obj
rchr$.obj
recfmt.obj
recint.obj
reclock.obj
reldat.obj
relidat.obj
rval.obj
sbmtcom.obj
scplot.obj
scplus.obj
scprntn.obj
screenon.obj
scriptcheck.obj
sctitl.obj
sendmail.obj
sendmailmessage.obj
serror.obj
spawn.obj
start.obj
subtitle.obj
sycalc.obj
termtype.obj
title.obj
today.obj
userno.obj
vali.obj
validate.obj
valr.obj
version.obj
vflongopen.obj
vfub.obj
vfup.obj
vfus.obj
vlinei.obj
wait.obj
wmbarmenu.obj
wmbarselect.obj
wmclearmenu.obj
wmgetfile.obj
wmgethotkey.obj
wmsetattr.obj
wmsethelp.obj
wmsethotkey.obj
yearrel$.obj
zerosup.obj
LIBC.lib(otsdiv.obj) : error LNK2005: _OtsDivide64 already defined in 
 dfordll.lib(DFOR.dll)
LIBC.lib(otsdiv.obj) : error LNK2005: _OtsDivide32 already defined in
 dfordll.lib(DFOR.dll)
LIBC.lib(otsdiv.obj) : error LNK2005: _OtsRemainder32 already defined in
 dfordll.lib(DFOR.dll)
overlay.dll : fatal error LNK1169: one or more multiply defined symbols found

%%%%%%%%%%%%%%%%%%%%%%%
Content-Disposition: attachment; filename="makefile"

!INCLUDE "\utils\F77.MAK"


all: overlay.obj overlay.dll

# ------------------------------
# BUILD OBJECT FILES
# ------------------------------

overlay.obj:: *.F77
          $(f77) $(fflags) /c \
!INCLUDE  "overlay.ff1"             
          $(f77) $(fflags) /c \
!INCLUDE  "overlay.ff2"

overlay.obj:: *.c
          CL /c /Gy *.c

# ------------------------------
# BUILD EXPORT LIBRARY
# ------------------------------

overlay.lib overlay.exp: overlay.def
        $(libr) /out:overlay.lib /machine:$(CPU) /def:overlay.def

# ------------------------------
# BUILD DLL
# ------------------------------

overlay.dll: overlay.exp overlay.lib 
        $(link) /noentry /out:overlay.dll /dll \
        @overlay.ooo overlay.exp dfordll.lib \
        \crc\overlay\insert\insert.lib \
        \crc\numeric\source\numeric.lib \
        \crc\kam\source\kam.lib \
        \crc\toolbox\source\toolbox.lib
clean:
      -del overlay.dll
      -del overlay.lib
      -del overlay.exp
      -del *.obj
                     

------=_NextPart_000_01BC1F3A.329C4E80
Content-Type: application/octet-stream; name="F77.mak"
Content-Transfer-Encoding: quoted-printable
Content-Description: F77.mak (MAK File)
Content-Disposition: attachment; filename="F77.mak"

#+
# F77.MAK - DEC Fortran application master NMAKE definitions file
#
# This software F77.MAK is part of the DEC Fortran.
# Copyright (C) 1993, 1994, 1995 Digital Equipment Corporation.
# All rights reserved.
#
# This software is furnished to you under a license by  Digital Equipment
# Corporation and must be used only in accordance with the terms and conditions
# of that license, and only with the inclusion of the above copyright notice.
# This software is protected by both United States copyright law and
# international treaty provisions. 
#
# This file should be included at the top of all MAKEFILEs as follows:
#  !include <f77.mak>
#
# NMAKE Options:
#
# Use the table below to determine the additional options for NMAKE
# Application Information Type         Invoke NMAKE
# ----------------------------         ------------
# For Debugging Info                   nmake debug=3D1
# For linker map                       nmake linkmap=3D1
# For linking with the DLLs            nmake linkdll=3D1
#-

!IF "$(CPU)" !=3D "ALPHA"
!ERROR This NMAKE definitions file is for Alpha AXP system only.
!ENDIF

!IF "$(DECFORT_TOOLS)" =3D=3D ""
!ERROR DECFORT_TOOLS must be defined to be one of MSVC20, MSDN35 or MSDN31
!ENDIF

!IF ( ("$(DECFORT_TOOLS)"  "MSVC20") || ("$(DECFORT_TOOLS)" "msvc20") )

crtimplibmsvcrt.lib

!IFNDEF link
link  link
!ENDIF
!IFNDEF libr
libr  lib
!ENDIF

!ENDIF

!IF ( ("$(DECFORT_TOOLS)"  "MSDN35") || ("$(DECFORT_TOOLS)"  "msdn35") )

crtimplibcrtdll.lib

!IFNDEF link
link  link
!ENDIF

!IFNDEF libr
libr  lib
!ENDIF

!ENDIF

!IF ( ("$(DECFORT_TOOLS)"  "MSDN31") || ("$(DECFORT_TOOLS)" "msdn31") )

crtimplibcrtdll.lib

!IFNDEF link
link  link32
!ENDIF

!IFNDEF libr
libr  lib32
!ENDIF

!ENDIF

#   Default

!IFNDEF link
link  link
!ENDIF
!IFNDEF libr
libr  lib
!ENDIF

#+
# Define the compiler verbs.
#-

FOR  f77
f77  f77

#+
# Macros for the compiler
#-

#f77_standard   /fort /novms /align:norecords /align:dcommons 
 /extend_source /optimize:0 /real_size:64 /warn:declarations /nolink
f77_standard  /fort /novms /align:norecords /align:dcommons
 /extend_source \
 /optimize:0 /real_size:64 /warn:declarations /align:commons /call_dll

!IFDEF DEBUG
f77_debug  /debug:full
lnk_debug  /debug:full /debugtype:both
!ELSE
f77_debug  /debug:none
lnk_debug  /debug:none
!ENDIF

!IFDEF LINKDLL

f77_dll    /call_dll
!IF ( ("$(DECFORT_TOOLS)"  "MSDN31") || ("$(DECFORT_TOOLS)"  "msdn31") )
f77libs    dfordll.lib dmathdll.lib dotsdll.lib dutildll.lib \
                $(crtimplib) kernel32.lib
!ELSE
f77libs    dfordll.lib $(crtimplib) kernel32.lib
!ENDIF

!ELSE

f77_dll   
!IF ( ("$(DECFORT_TOOLS)"  "MSDN31") || ("$(DECFORT_TOOLS)"  "msdn31") )
#f77libs    dfor.lib dmath.lib dots.lib dutil.lib libc.lib kernel32.lib
f77libs    dfor.lib dmath.lib dots.lib dutil.lib kernel32.lib
!ELSE
#f77libs    dfor.lib libc.lib kernel32.lib
f77libs    dfor.lib  kernel32.lib
!ENDIF

!ENDIF

fflags     $(f77_debug) $(f77_dll) $(f77_standard)

#+
# Macros for the FPP Preprocesor
#-

fpp  $(f77) $(fflags) /fpp
fppflags 

#+
# Macros for the linker.
#-

!IFDEF LINKMAP
lflags  /map:$(*B).map $(lflags)
!ELSE
lflags  $(lflags)
!ENDIF


#+
# Add .fpp to the .SUFFIXES list
#-

.SUFFIXES: .exe .obj .asm .c .bas .cbl .fpp .for .pas .res .rc

#+
# Define the inference rules
#-

.obj.exe:
   $(f77) $(f77_dll) $(f77_debug) /link $(lflags) $(lnk_debug) $*.obj

.for.exe:
   $(f77) $(fflags) $*.for /link $(lflags)

.fpp.exe:
   $(fpp) $(fppflags) $*.fpp /link $(lflags)

.for.obj:
   $(f77) $(f77_debug) $*.for /nolink /object:$@

.fpp.obj:
   $(f77) $(f77_debug) /nolink /object:$@ /fpp $(fppflags) $*.fpp


T.RTitleUserPersonal
Name
DateLines
467.1don't mix and (not)matchCANDOO::GRIEBFri Feb 21 1997 09:4630
James,
	In general, unless you REALLY know what you are doing, the rule
for builing images is:

 "If you link against ANY DLL's (not counting system ones) then you should
  link against ALL DLL's".

In other words, if you are building a "statically linked app" then don't
link against any import libs. If you are building an app (or DLL) that
is linked against other DLL's then link against the DLL version (not the
static version) of ALL the other libraries. If you don't do this you
will find that you have multiple copies of "shared" data (for instance,
you will have multiple errno's, multiple ctype tables, etc. etc.)

In your case you are linking against a DLL import library (dfordll.lib)
and a <<STATIC>> C library (libc.lib). This creates just the type of
problem you are seeing. The solution is to link all static or all DLL.
Since it looks like you are in fact building a DLL, this implies that
you should link all DLL so the "dfordll.lib" is correct but you need to
link against the DLL version of the C library.

Libc.lib may be being pulled in because you didn't compile using /MD
when you compiled the C code. Using /LINK /NODEFAULTLIB may "fix the
problem" but may leave you with multiple copies of errno, etc. Recompile
the C code with /MD to REALLY fix the problem and not just hide the
symptom.

I hope that helps.

467.2Thanks-i'll pass it onBLAZER::MIKELISSoftware Partner&#039;s Eng. MR01-3/F26Fri Feb 21 1997 11:361