"dyld: Library not loaded"? [50% Sorta Solved]

Discussion in 'Mac Programming' started by ajm113, Jan 16, 2011.

  1. ajm113, Jan 16, 2011
    Last edited: Jan 18, 2011

    ajm113 macrumors newbie

    Jan 16, 2011
    Hello everyone I'm new to Macs and my girlfriend got me hooked on using my Macbook and I'm converting a wxWidgets project to wxMac application and everything is going smoothly except I'm my project is using FreeImage library and I'm getting this error when I start my software.

    dyld: Library not loaded: Libfreeimage-3.14.1.dylib-i386
        Referenced from: (Path to project)/build/Debug/(Project Name)
      Reason: image not found
    I edited the path so it was shorter and understandable and this appears before anything in my software even does anything.

    I'm very new to using xCode with C++ and I don't know why this error appears if my application compiles with no errors. Is this error the same just like how Windows would complain about not finding a .dll? But in this case it's just not finding a framework file? How do I fix it? What file am I forgetting?

    I would appreciate any help since I want to have my Mac as my main development platform for cross development when I'm away from the house.
  2. misee macrumors member

    Jul 4, 2010
    My guess is that you are compiled your application as a 32 bit executable and the library 64 bit. You can check that by using the file command in the terminal for the library and check the build settings in Xcode.
    To build the wxMac as universal binary, read this.
    Edit: I didn't build wxMac and I don't have it insalled, so this is just a guess.
  3. ajm113 thread starter macrumors newbie

    Jan 16, 2011
    Thanks for the reply, but I built that library called "freeimage" under the make function and I read through the instructions and it didn't mention anything about setting up freeimage as a 32bit or 64bit, but the project that the library is using is already set for 32bit and it's set for "my current Mac", but I'll snoop around with FreeImage and that link more to see if those solve my problem.
  4. ajm113, Jan 18, 2011
    Last edited: Jan 18, 2011

    ajm113 thread starter macrumors newbie

    Jan 16, 2011
    I fixed the issue, sorta.... All I did was rename the freeimage dylib to ".dylib-i386" and it worked! But... When I tried running the software in the Debug folder or Release folder I get the same all over again and the path to the framework freeimage file is all messed up to the freeimage framework.

    Example How it loads the framework when I run my software from xcode:
    /Users/andrewmcrobb/Documents/Digital Symbol Studio (wxMac)/build/Debug/libfreeimage-3.14.1.dylib-i386
    Runtime Error I get if I run the program directly:
    Last login: Tue Jan 18 17:30:13 on ttys001
    /Users/andrewmcrobb/Documents/Digital\ Symbol\ Studio\ \(wxMac\)/build/Debug/Digital\ Symbol\ Studio ; exit;
    Andrew-McRobbs-MacBook:~ andrewmcrobb$ /Users/andrewmcrobb/Documents/Digital\ Symbol\ Studio\ \(wxMac\)/build/Debug/Digital\ Symbol\ Studio ; exit;
    dyld: Library not loaded: libfreeimage-3.14.1.dylib-i386
      Referenced from: /Users/andrewmcrobb/Documents/Digital Symbol Studio (wxMac)/build/Debug/Digital Symbol Studio
      Reason: image not found
    Trace/BPT trap
    Are you sure I don't have to set anything up with the FreeImage framework with my project or any tutorials I should read on setting up frameworks 'you' built and can this simple path error be fixed?

    Thanks, Ajm
  5. gnasher729 macrumors P6


    Nov 25, 2005
    You'll need to get the exact details from www.developer.com.

    If you use a framework that isn't one of the system frameworks, then it will obviously not be on any other machine than your own, so you have to do something. The steps you need to do:

    1. Add the framework to your project
    2. Make sure it is added in your target settings to the "Link" build phase.
    3. You need in your target settings a build phase that will copy the framework into the application bundle. Add a new "Copy files" build phase, change it to copy frameworks (Get Info + General), add the framework to that build phase.
    4. I think you have to set a path where the application will be looking for frameworks; the details will be at www.developer.com.
  6. ajm113, Jan 19, 2011
    Last edited: Jan 19, 2011

    ajm113 thread starter macrumors newbie

    Jan 16, 2011
    I fallowed what you said and I can't get anything, believe me I tried everything from even changing the Path Type in I placed the dylib in that "copy folder" to looking around in the Build settings to look for anything and I can't find where to go and that website doesn't help at all, I tried searching around, but I cant find what I want...

    (Google's Website Based Search Engine isn't the best... Would it be too hard to write their own?!? I type just "xcode" any only 2 results show and they don't help...)

    May I ask why Xcode wouldn't look for the freeimage dylib I added to the project then "freeimage.dylib-(Project Active Architecture)" ? Doesn't kinda make sense if it loads other frameworks perfectly such as wxMac that I built myself, but for some odd reason it want's freeimage's dynamic link library to have the architecture included in the file extension.

    I will post the instructions and make file of FreeImage if that helps.

    The make file for FreeImage I used to build it with:
    # -*- Makefile -*-
    # Mac OSX makefile for FreeImage
    # This file can be generated by ./gensrclist.sh
    include Makefile.srcs
    # General configuration variables:
    CC_PPC = gcc-4.0
    CC_I386 = gcc-4.0
    CC_X86_64 = gcc-4.0
    CPP_PPC = g++-4.0
    CPP_I386 = g++-4.0
    CPP_X86_64 = g++-4.0
    COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden -DNO_LCMS
    COMPILERFLAGS_PPC = -arch ppc
    COMPILERFLAGS_I386 = -arch i386
    COMPILERFLAGS_X86_64 = -arch x86_64
    COMPILERPPFLAGS = -Wno-ctor-dtor-privacy
    INCLUDE += 
    INCLUDE_PPC = -isysroot /Developer/SDKs/MacOSX10.5.sdk
    INCLUDE_I386 = -isysroot /Developer/SDKs/MacOSX10.5.sdk
    INCLUDE_X86_64 = -isysroot /Developer/SDKs/MacOSX10.6.sdk
    LIBRARIES_PPC = -Wl,-syslibroot /Developer/SDKs/MacOSX10.5.sdk
    LIBRARIES_I386 = -Wl,-syslibroot /Developer/SDKs/MacOSX10.5.sdk
    LIBRARIES_X86_64 = -Wl,-syslibroot /Developer/SDKs/MacOSX10.6.sdk
    LIBTOOL = libtool
    LIPO = lipo
    TARGET = freeimage
    STATICLIB = lib$(TARGET).a
    LIBNAME = lib$(TARGET).$(VER_MAJOR).dylib
    HEADER = Source/FreeImage.h
    .SUFFIXES: .o-ppc .o-i386 .o-x86_64
    MODULES_PPC = $(SRCS:.c=.o-ppc)
    MODULES_I386 = $(SRCS:.c=.o-i386)
    MODULES_X86_64 = $(SRCS:.c=.o-x86_64)
    MODULES_PPC := $(MODULES_PPC:.cpp=.o-ppc)
    MODULES_I386 := $(MODULES_I386:.cpp=.o-i386)
    MODULES_X86_64 := $(MODULES_X86_64:.cpp=.o-x86_64)
    PREFIX = /usr/local
    INCDIR = $(PREFIX)/include
    default: all
    all: dist
    dist: FreeImage
    	cp *.a Dist
    	cp *.dylib Dist
    	cp Source/FreeImage.h Dist
    FreeImage: $(STATICLIB) $(SHAREDLIB)
    $(STATICLIB): $(STATICLIB)-ppc $(STATICLIB)-i386 $(STATICLIB)-x86_64
    	$(LIPO) -create $(STATICLIB)-ppc $(STATICLIB)-i386 $(STATICLIB)-x86_64 -output $(STATICLIB)
    	$(LIBTOOL) -arch_only ppc -o $@ $(MODULES_PPC)
    $(STATICLIB)-i386: $(MODULES_I386)
    	$(LIBTOOL) -arch_only i386 -o $@ $(MODULES_I386)
    $(STATICLIB)-x86_64: $(MODULES_X86_64)
    	$(LIBTOOL) -arch_only x86_64 -o $@ $(MODULES_X86_64)
    $(SHAREDLIB): $(SHAREDLIB)-ppc $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64
    	$(LIPO) -create $(SHAREDLIB)-ppc $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64 -output $(SHAREDLIB)
    	$(CPP_PPC) -arch ppc -dynamiclib $(LIBRARIES_PPC) -o $@ $(MODULES_PPC)
    $(SHAREDLIB)-i386: $(MODULES_I386)
    	$(CPP_I386) -arch i386 -dynamiclib $(LIBRARIES_I386) -o $@ $(MODULES_I386)
    $(SHAREDLIB)-x86_64: $(MODULES_X86_64)
    	$(CPP_X86_64) -arch x86_64 -dynamiclib $(LIBRARIES_X86_64) -o $@ $(MODULES_X86_64)
    	$(CC_PPC) $(CFLAGS_PPC) -c $< -o $@
    	$(CC_I386) $(CFLAGS_I386) -c $< -o $@
    	$(CC_X86_64) $(CFLAGS_X86_64) -c $< -o $@
    	$(CPP_PPC) $(CPPFLAGS_PPC) -c $< -o $@
    	$(CPP_I386) $(CPPFLAGS_I386) -c $< -o $@
    	$(CPP_X86_64) $(CPPFLAGS_X86_64) -c $< -o $@
    	install -d -m 755 -o root -g wheel $(INCDIR) $(INSTALLDIR)
    	install -m 644 -o root -g wheel $(HEADER) $(INCDIR)
    	install -m 644 -o root -g wheel $(SHAREDLIB) $(STATICLIB) $(INSTALLDIR)
    	ranlib -sf $(INSTALLDIR)/$(STATICLIB)
    	rm -f core Dist/*.* u2dtmp* $(MODULES_PPC) $(MODULES_I386) $(MODULES_X86_64) $(STATICLIB) $(STATICLIB)-ppc $(STATICLIB)-i386 $(SHAREDLIB) $(SHAREDLIB)-ppc $(SHAREDLIB)-i386 $(SHAREDLIB)-x86_64

Share This Page