ld: symbol(s) not found when linking

Chris picture Chris · Sep 13, 2010 · Viewed 54.5k times · Source

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?

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

# 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

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:

Answer

Jonathan Leffler picture Jonathan Leffler · Sep 13, 2010

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

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.

For the 32-bit build, you could use:

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

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

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.


How to identify file types on MacOS X

For a dylib, use 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
$