Skip to content

Instantly share code, notes, and snippets.

@ofZach
Last active September 15, 2020 15:22
Show Gist options
  • Save ofZach/e602efb4fbd43858aa01aff6d015ef32 to your computer and use it in GitHub Desktop.
Save ofZach/e602efb4fbd43858aa01aff6d015ef32 to your computer and use it in GitHub Desktop.
how to make an openframeworks dylib

I'm writing these instructions against OF 0.9 but this should work on 0.9.3, etc.

so the general idea behind making a dylib is to do this:

http://stackoverflow.com/questions/16082470/osx-how-do-i-convert-a-static-library-to-a-dynamic-one

in the case of OF, it's something like:

cd OF_ROOT/libs/openFrameworksCompiled/lib/osx
g++ -fpic -shared -Wl,-all_load openframeworks.a ../../../poco/lib/osx/PocoCrypto.a ../../../poco/lib/osx/PocoData.a ../../../poco/lib/osx/PocoDataSQLite.a ../../../poco/lib/osx/PocoJSON.a ../../../poco/lib/osx/PocoUtil.a ../../../poco/lib/osx/PocoXML.a ../../../poco/lib/osx/PocoNet.a ../../../poco/lib/osx/PocoNetSSL.a ../../../poco/lib/osx/PocoZip.a ../../../poco/lib/osx/PocoFoundation.a ../../../tess2/lib/osx/tess2.a ../../../glew/lib/osx/glew.a ../../../cairo/lib/osx/cairo-script-interpreter.a ../../../cairo/lib/osx/cairo.a ../../../cairo/lib/osx/pixman-1.a ../../../fmodex/lib/osx/libfmodex.dylib ../../../rtAudio/lib/osx/rtAudio.a ../../../openssl/lib/osx/crypto.a ../../../openssl/lib/osx/ssl.a ../../../glfw/lib/osx/glfw3.a ../../../FreeImage/lib/osx/freeimage.a ../../../freetype/lib/osx/freetype.a ../../../boost/lib/osx/boost_filesystem.a ../../../boost/lib/osx/boost_system.a -framework Accelerate -framework AGL -framework AppKit -framework ApplicationServices -framework AudioToolbox -framework AVFoundation -framework Cocoa -framework CoreAudio -framework CoreFoundation -framework CoreMedia -framework CoreServices -framework CoreVideo -framework IOKit -framework OpenGL -framework QuartzCore -framework QuickTime -framework QTKit -F../../../glut/lib/osx -framework GLUT  -Wl,-noall_load -o openframeworks.dylib

but a problem is that there are two libraries in openframeworks that use zlib (pocoFoundation and freeImage). In order to fix this, we will need to remove zlib from the compiled poco library by hand.

we basically follow this tutorial:

http://atnan.com/blog/2012/01/12/avoiding-duplicate-symbol-errors-during-linking-by-removing-classes-from-static-libraries

here's the steps:

change directory to poco/lib/osx/

#check platforms: 
lipo -info PocoFoundation.a  

#backup: 
cp PocoFoundation.a PocoFoundationBackup.a

#split platforms (assuming i386 / x86_64)
lipo -thin i386 PocoFoundation.a -o PocoFoundation_i386.a
lipo -thin x86_64 PocoFoundation.a -o PocoFoundation_x86_64.a

#make a few working directories and move the libs there
mkdir i386
mkdir x86_64



#fix each one

mv PocoFoundation_i386.a i386
cd i386
ar -x PocoFoundation_i386.a
mv PocoFoundation_i386.a ../
rm __.SYMDEF
rm adler32.o compress.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o
libtool  -static * -o ../PocoFoundation_noZlib_i386.a

cd ../

mv PocoFoundation_x86_64.a i386
cd x86_64
ar -x PocoFoundation_x86_64.a
mv PocoFoundation_x86_64.a ../
rm __.SYMDEF
rm adler32.o compress.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o
libtool  -static * -o ../PocoFoundation_noZlib_x86_64.a

cd ../

lipo -create PocoFoundation_noZlib_i386.a PocoFoundation_noZlib_x86_64.a PocoFoundation.a

now the g++ -fpic -shared above will work...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment