ld:链接时找不到符号

时间:2010-09-13 19:40:02

标签: macos wxwidgets compiler-errors

我正在尝试在我的Mac OSX 10.6上编译“Loch”而没有任何成功。我总是得到一些“编译时未找到的符号”错误。任何人都知道可能是什么问题?

非常感谢

c++ -o loch -Wall getline.o lxTR.o lxOGLFT.o lxSetup.o lxRender.o lxWX.o lxImgIO.o lxLRUD.o lxFile.o lxSTree.o lxData.o lxMath.o lxSView.o lxSScene.o lxGUI.o lxGLC.o lxOptDlg.o lxAboutDlg.o img.o -lz -L/usr/X11R6/lib              -framework IOKit -framework Carbon -framework Cocoa -framework System -framework QuickTime -framework OpenGL -framework AGL  -lwx_macud_gl-2.8 -lwx_macud-2.8  -L/Applications/VTK_All/VTK_Bin/lib/vtk-5.4 -lvtkHybrid -lvtkImaging -lvtkIO -lvtkGraphics -lvtkFiltering -lvtkCommon -lvtkjpeg -lvtkpng -lvtkzlib -lvtksys -lfreetype -lGLU -lGL 
ld: warning: in /System/Library/Frameworks//QuickTime.framework/QuickTime, missing required architecture x86_64 in file
ld: warning: in /usr/lib/libwx_macud_gl-2.8.dylib, missing required architecture x86_64 in file
ld: warning: in /usr/lib/libwx_macud-2.8.dylib, missing required architecture x86_64 in file

  "wxGetTopLevelParent(wxWindow*)", referenced from:
      wxTopLevelWindowBase::IsActive()      in lxRender.o
      wxTopLevelWindowBase::IsActive()      in lxSTree.o
      wxTopLevelWindowBase::IsActive()      in lxSView.o
      wxTopLevelWindowBase::IsActive()      in lxSScene.o
      wxTopLevelWindowBase::IsActive()      in lxGUI.o
      wxTopLevelWindowBase::IsActive()      in lxOptDlg.o
      wxTopLevelWindowBase::IsActive()      in lxAboutDlg.o
  "wxWindowBase::SetVirtualSizeHints(int, int, int, int)", referenced from:
      vtable for lxRenderDataConfigin lxRender.o
      vtable for wxStaticTextBasein lxRender.o
      vtable for wxCheckBoxBasein lxRender.o
      vtable for wxButtonBasein lxRender.o
      vtable for lxModelTreeDlgin lxSTree.o
      vtable for wxButtonBasein lxSTree.o
      vtable for lxViewpointSetupDlgin lxSView.o
      vtable for wxSliderBasein lxSView.o
      vtable for wxCheckBoxBasein lxSView.o
      vtable for wxStaticTextBasein lxSView.o
      vtable for wxButtonBasein lxSView.o
      vtable for lxModelSetupDlgin lxSScene.o
      vtable for wxSliderBasein lxSScene.o
      vtable for wxStaticLineBasein lxSScene.o
      vtable for wxCheckBoxBasein lxSScene.o
      vtable for wxStaticTextBasein lxSScene.o
      vtable for wxButtonBasein lxSScene.o
      vtable for lxFramein lxGUI.o
      vtable for lxGLCanvasin lxGLC.o
      vtable for lxOptionsDlgin lxOptDlg.o
      vtable for wxDirDialogBasein lxOptDlg.o
      vtable for wxStaticTextBasein lxOptDlg.o
      vtable for wxButtonBasein lxOptDlg.o
      vtable for lxAboutDlgin lxAboutDlg.o
      vtable for wxStaticTextBasein lxAboutDlg.o
  "typeinfo for wxGLCanvas", referenced from:
      typeinfo for lxGLCanvasin lxGLC.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [loch] Error 1

我使用以下Makefile

# common therion objects
CMNOBJECTS = \
  lxTR.o lxOGLFT.o lxSetup.o lxRender.o lxWX.o \
  lxImgIO.o lxLRUD.o lxFile.o lxSTree.o \
  lxData.o lxMath.o lxSView.o lxSScene.o \
  lxGUI.o lxGLC.o lxOptDlg.o lxAboutDlg.o \
  img.o

VTKVERSION = 5.4
VTKLIBS = -lvtkHybrid -lvtkImaging -lvtkIO -lvtkGraphics -lvtkFiltering -lvtkCommon -lvtkjpeg -lvtkpng -lvtkzlib -lvtksys -lfreetype
POSTMAKE =
STRIPFLAG = -s 

# PLATFORM CONFIG

# PLATFORM MACOSX
  CXX = c++
  CC = cc
  VTKPATH = /Applications/VTK_All/VTK_Bin
  VTKINCLUDEPATH = $(VTKPATH)/include/vtk-5.4
  VTKLIBPATH = $(VTKPATH)/lib/vtk-5.4
  VTKLIBS = -lvtkHybrid -lvtkImaging -lvtkIO -lvtkGraphics -lvtkFiltering -lvtkCommon -lvtkjpeg -lvtkpng -lvtkzlib -lvtksys -lfreetype -lGLU -lGL
  POBJECTS = getline.o
  CXXPFLAGS = -W -Wall -DLXMACOSX $(shell wx-config --cxxflags) -I$(VTKINCLUDEPATH) -Wno-deprecated -I/usr/X11R6/include -I/usr/X11R6/include/freetype2
  CCPFLAGS = -W -Wall -DLXMACOSX $(shell wx-config --cflags) -I/usr/X11R6/include
  LXLIBDIR = 
  PLIBS = -lz -L/usr/X11R6/lib $(shell wx-config --libs gl) -L$(VTKLIBPATH) $(VTKLIBS)
  POSTMAKE = cp -f ./loch ./loch.app/Contents/MacOS
  STRIPFLAG =
# PLATFORM ENDCONFIG


# BUILD CONFIG

# BUILD OZONE
##CCBFLAGS = -O3
##CXXBFLAGS = -O3
##LDBFLAGS = $(STRIPFLAG)

# BUILD OXYGEN
CCBFLAGS = -O2
CXXBFLAGS = -O2
LDBFLAGS = $(STRIPFLAG)

# BUILD RELEASE
##CCBFLAGS = 
##CXXBFLAGS = 
##LDBFLAGS = $(STRIPFLAG)

# BUILD DEBUG
##CCBFLAGS = -ggdb
##CXXBFLAGS = -ggdb -DLXDEBUG
##LDBFLAGS = 

# BUILD ENDCONFIG


# compiler settings
CXXFLAGS = -Wall -D_GNU_SOURCE -DLOCH $(CXXPFLAGS) $(CXXBFLAGS)
CCFLAGS = -Wall -D_GNU_SOURCE -DLOCH $(CCPFLAGS) $(CCBFLAGS)
OBJECTS = $(POBJECTS) $(CMNOBJECTS)

# linker settings
LIBS = $(PLIBS)
LDFLAGS = $(LDBFLAGS)


.SUFFIXES:
.SUFFIXES: .cxx .o .h .c

.cxx.o:
    $(CXX) -c $(CXXFLAGS) -o $@ $<

.c.o:
    $(CC) -c $(CCFLAGS) -o $@ $<

all: loch hlp

hlp:
    make -C ./help

loch:   $(OBJECTS)
    $(CXX) -o loch -Wall $(OBJECTS) $(LIBS) $(LDFLAGS)
    $(POSTMAKE)

loch.res: loch.rc loch.ico
    windres --include-dir e:/MSVCProjects/wxWidgets-2.6.0/include -i loch.rc -I rc -o loch.res -O coff

graphs: 
    dot -Tps graph-vispipe.dot -o graph-vispipe.ps


depend:
    perl makedepend.pl > Makefile.dep
    perl maketest.pl Makefile.dep
    perl makefile.pl mv Makefile.dep Makefile
    $(CXX) -DLXDEPCHECK -DLOCH -MM *.cxx >> Makefile
    $(CC) -DLXDEPCHECK -DLOCH -MM *.c >> Makefile


config-debug:
    perl makeconfig.pl BUILD DEBUG

test-release:
    zip -9 loch.zip loch.exe test.th test.jpg thconfig

config-release:
    perl makeconfig.pl BUILD RELEASE

config-oxygen:
    perl makeconfig.pl BUILD OXYGEN

config-ozone:
    perl makeconfig.pl BUILD OZONE

config-linux:
    perl makeconfig.pl PLATFORM LINUX

config-debian:
    perl makeconfig.pl PLATFORM DEBIAN

config-win32:
    perl makeconfig.pl PLATFORM WIN32

config-macosx:
    perl makeconfig.pl PLATFORM MACOSX

clean:
    perl makefile.pl rm -q *~     
    perl makefile.pl rm -q help/*/*~
    perl makefile.pl rm -q loch.exe
    perl makefile.pl rm -q loch
    perl makefile.pl rm -q loch.app/Contents/MacOS/loch
    perl makefile.pl rm -q *.o
    perl makefile.pl rm -q *.log
    perl makefile.pl rm -q core
    perl makefile.pl rmdir -q .xvpics
    perl makefile.pl rm -q *.bmp
    perl makefile.pl rm -q *.ppm
    perl makefile.pl rm -q *.zip
    perl makefile.pl rm -q *.pdf
    perl makefile.pl rm -q *.png



# DEPENDENCIES
lxAboutDlg.o: lxAboutDlg.cxx lxWX.h icons/about.xpm ../thversion.h
lxData.o: lxData.cxx lxData.h lxMath.h lxImgIO.h lxFile.h lxLRUD.h
lxFile.o: lxFile.cxx lxFile.h lxMath.h img.h
lxGLC.o: lxGLC.cxx lxGLC.h lxMath.h lxGUI.h lxData.h lxImgIO.h lxFile.h \
  lxSetup.h lxSView.h lxWX.h lxFNT6x13_bdf.h lxFNT10x20_bdf.h \
  lxFNTFreeSans_ttf.h lxRender.h lxTR.h
lxGUI.o: lxGUI.cxx lxGUI.h lxGLC.h lxMath.h lxData.h lxImgIO.h lxFile.h \
  lxSetup.h lxRender.h lxOptDlg.h lxAboutDlg.h lxSView.h lxWX.h \
  lxSScene.h icons/open.xpm icons/render.xpm icons/reload.xpm \
  icons/stereo.xpm icons/rotation.xpm icons/lockrot.xpm icons/fit.xpm \
  icons/home.xpm icons/rendersetup.xpm icons/plan.xpm icons/profile.xpm \
  icons/fullscreen.xpm icons/orto.xpm icons/camera.xpm icons/scene.xpm \
  icons/viscline.xpm icons/vissurface.xpm icons/visbbox.xpm \
  icons/viswalls.xpm icons/visinds.xpm loch.xpm
lxImgIO.o: lxImgIO.cxx lxImgIO.h
lxLRUD.o: lxLRUD.cxx lxLRUD.h lxMath.h
lxMath.o: lxMath.cxx lxMath.h
lxOGLFT.o: lxOGLFT.cxx lxOGLFT.h
lxOptDlg.o: lxOptDlg.cxx lxWX.h lxGUI.h lxGLC.h lxMath.h
lxRender.o: lxRender.cxx lxRender.h lxWX.h lxGLC.h lxMath.h lxGUI.h \
  lxSetup.h lxData.h lxImgIO.h lxFile.h lxTR.h
lxSScene.o: lxSScene.cxx lxSScene.h lxWX.h lxGUI.h lxGLC.h lxMath.h \
  lxSetup.h lxData.h lxImgIO.h lxFile.h loch.xpm
lxSView.o: lxSView.cxx lxSView.h lxWX.h lxGUI.h lxGLC.h lxMath.h \
  lxSetup.h lxData.h lxImgIO.h lxFile.h loch.xpm
lxSetup.o: lxSetup.cxx lxSetup.h lxData.h lxMath.h lxImgIO.h lxFile.h
lxWX.o: lxWX.cxx lxWX.h
getline.o: getline.c
img.o: img.c img.h
lxR2D.o: lxR2D.c lxR2D.h
lxR2P.o: lxR2P.c lxR2P.h
lxTR.o: lxTR.c lxTR.h

现在添加-m32但是收到新错误

c++ -m32 -o loch -Wall getline.o lxTR.o lxOGLFT.o lxSetup.o lxRender.o lxWX.o lxImgIO.o lxLRUD.o lxFile.o lxSTree.o lxData.o lxMath.o lxSView.o lxSScene.o lxGUI.o lxGLC.o lxOptDlg.o lxAboutDlg.o img.o -lz -L/usr/X11R6/lib              -framework IOKit -framework Carbon -framework Cocoa -framework System -framework QuickTime -framework OpenGL -framework AGL  -lwx_macud_gl-2.8 -lwx_macud-2.8  -L/Applications/VTK_All/VTK_Bin/lib/vtk-5.4 -lvtkHybrid -lvtkImaging -lvtkIO -lvtkGraphics -lvtkFiltering -lvtkCommon -lvtkjpeg -lvtkpng -lvtkzlib -lvtksys -lfreetype -lGLU -lGL 
ld: warning: in /Applications/VTK_All/VTK_Bin/lib/vtk-5.4/libvtkHybrid.a, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Applications/VTK_All/VTK_Bin/lib/vtk-5.4/libvtkImaging.a, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Applications/VTK_All/VTK_Bin/lib/vtk-5.4/libvtkIO.a, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Applications/VTK_All/VTK_Bin/lib/vtk-5.4/libvtkGraphics.a, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Applications/VTK_All/VTK_Bin/lib/vtk-5.4/libvtkFiltering.a, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Applications/VTK_All/VTK_Bin/lib/vtk-5.4/libvtkCommon.a, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Applications/VTK_All/VTK_Bin/lib/vtk-5.4/libvtkjpeg.a, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Applications/VTK_All/VTK_Bin/lib/vtk-5.4/libvtkpng.a, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Applications/VTK_All/VTK_Bin/lib/vtk-5.4/libvtkzlib.a, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: in /Applications/VTK_All/VTK_Bin/lib/vtk-5.4/libvtksys.a, file was built for unsupported file format which is not the architecture being linked (i386)
Undefined symbols:

1 个答案:

答案 0 :(得分:14)

您似乎正在编译64位软件,但编译器找到的库是针对32位软件的。

您需要以32位模式重新编译代码,以便可以使用现有库,或者需要安装(或定位)并指定64位版本库的位置。

对于32位版本,您可以使用:

BITTINESS = -m32
CC = cc ${BITTINESS}
CXX = c++ ${BITTINESS}

如果您以后想要,可以使用“make BITTINESS=-m64”覆盖命令行。

可能还有其他方法可以指定您需要某种通用二进制文件 - 但是如果要为该体系结构构建,您仍需要找到支持x86_64的WX(和QuickTime)库的版本。 / p>


如何识别MacOS X上的文件类型

对于dylib,请使用file

$ file /usr/lib/libffi.dylib
/usr/lib/libffi.dylib: Mach-O universal binary with 3 architectures
/usr/lib/libffi.dylib (for architecture x86_64):    Mach-O 64-bit dynamically linked shared library x86_64
/usr/lib/libffi.dylib (for architecture i386):  Mach-O dynamically linked shared library i386
/usr/lib/libffi.dylib (for architecture ppc7400):   Mach-O dynamically linked shared library ppc
$

对于存档,提取目标文件:

$ file libjlss-350.a
libjlss-350.a: current ar archive random library
$ ar x libjlss-350.a stuint8.o
$ file stuint8.o
stuint8.o: Mach-O 64-bit object x86_64
$