macos ld:链接时未找到符号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3703792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:12:25  来源:igfitidea点击:

ld: symbol(s) not found when linking

macoswxwidgetscompiler-errors

提问by Chris

I am trying to compile "Loch" without any success on my Mac OSX 10.6. I always get some "symbol(s) not found when compiling" error. Anyone an idea what could be the problem?

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

Thanks a lot

非常感谢

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

I use the following Makefile

我使用以下 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

Added now -m32 but getting new errors

现在添加 -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:

采纳答案by Jonathan Leffler

It appears you are compiling for 64-bit software, but the libraries the compiler is finding are for 32-bit software.

看起来您正在为 64 位软件编译,但编译器找到的库适用于 32 位软件。

You either need to recompile your code in 32-bit mode so you can use the existing libraries, or you need to install (or locate) and specify where the 64-bit version of the libraries are.

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

For the 32-bit build, you could use:

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

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

You could override on the command line with 'make BITTINESS=-m64' if you later wanted to.

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

There may also be other ways to specify that you want some sort of universal binary - but you will still need to locate versions of the WX (and QuickTime) libraries with support for x86_64 if you want to build for that architecture.

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



How to identify file types on MacOS X

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

For a dylib, use file:

对于 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
$

For an archive, extract an object file:

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

$ 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
$