Discussion:
How to build a universal dylib on Mac OS X?
Russell E. Owen
2012-04-17 19:53:27 UTC
Permalink
I am using scons 2.1.0 to compile C code into a library on Mac OS X
using XCode 4.3.2's clang 3.1 compiler.

I want to build a universal (32-bit and 64-bit) shared library (dylib).

I've found that I can easily build a universal static library, but I can
only build a 64-bit-only dynamic library.

The SConstruct file and log are appended below.

Any suggestions would be most welcome. I can certainly live with a
static library, but would rather not have to. I didn't find anything in
the manual or a web search, though I expect I've overlooking something
basic.

-- Russell


My SConstruct file looks like this:

env = Environment(
CC = "clang",
CFLAGS = "-arch i386 -arch x86_64",
)

staticLib = env.StaticLibrary(
target = "sla",
source =Glob("src/*.c"),
)

# I'd rather use a dylib, but this is 64-bit only; why?
env.SharedLibrary(
target = "sla",
source = libSrcList,
)


Partial log:
localhost$ scons -j 1
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
clang -o src/dafin.o -c -arch i386 -arch x86_64 src/dafin.c
clang -o src/obs.o -c -arch i386 -arch x86_64 src/obs.c
...
ar rc libsla.a src/dafin.o src/obs.o...
ranlib libsla.a
clang -o src/dafin.os -c -arch i386 -arch x86_64 -fPIC src/dafin.c
clang -o src/obs.os -c -arch i386 -arch x86_64 -fPIC src/obs.c
...
clang -o libsla.dylib -dynamiclib src/dafin.os src/obs.os...


The results:
localhost$ file libsla.a
libsla.a: Mach-O universal binary with 2 architectures
libsla.a (for architecture i386): current ar archive random library
libsla.a (for architecture x86_64): current ar archive random library

localhost$ file libsla.dylib
libsla.dylib: Mach-O 64-bit dynamically linked shared library x86_64

------------------------------------------------------
http://scons.tigris.org/ds/viewMessage.do?dsForumId=1272&dsMessageId=2949230

To unsubscribe, send an e-mail to [users-***@scons.tigris.org].
William Deegan
2012-04-19 05:30:26 UTC
Permalink
Russell,
Post by Russell E. Owen
I am using scons 2.1.0 to compile C code into a library on Mac OS X
using XCode 4.3.2's clang 3.1 compiler.
I want to build a universal (32-bit and 64-bit) shared library (dylib).
I've found that I can easily build a universal static library, but I can
only build a 64-bit-only dynamic library.
The SConstruct file and log are appended below.
Any suggestions would be most welcome. I can certainly live with a
static library, but would rather not have to. I didn't find anything in
the manual or a web search, though I expect I've overlooking something
basic.
-- Russell
env = Environment(
CC = "clang",
CFLAGS = "-arch i386 -arch x86_64",
)
staticLib = env.StaticLibrary(
target = "sla",
source =Glob("src/*.c"),
)
# I'd rather use a dylib, but this is 64-bit only; why?
env.SharedLibrary(
target = "sla",
source = libSrcList,
)
localhost$ scons -j 1
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
clang -o src/dafin.o -c -arch i386 -arch x86_64 src/dafin.c
clang -o src/obs.o -c -arch i386 -arch x86_64 src/obs.c
...
ar rc libsla.a src/dafin.o src/obs.o...
ranlib libsla.a
clang -o src/dafin.os -c -arch i386 -arch x86_64 -fPIC src/dafin.c
clang -o src/obs.os -c -arch i386 -arch x86_64 -fPIC src/obs.c
...
clang -o libsla.dylib -dynamiclib src/dafin.os src/obs.os...
localhost$ file libsla.a
libsla.a: Mach-O universal binary with 2 architectures
libsla.a (for architecture i386): current ar archive random library
libsla.a (for architecture x86_64): current ar archive random library
localhost$ file libsla.dylib
libsla.dylib: Mach-O 64-bit dynamically linked shared library x86_64
How do you create a universal dynlib from the command line?
(What are the flags and which tool do you use to make it?)
I'm not that familiar with OSX

-Bill

------------------------------------------------------
http://scons.tigris.org/ds/viewMessage.do?dsForumId=1272&dsMessageId=2949653

To unsubscribe, send an e-mail to [users-***@scons.tigris.org].
Russell E. Owen
2012-04-19 18:34:29 UTC
Permalink
Post by William Deegan
Russell,
Post by Russell E. Owen
I am using scons 2.1.0 to compile C code into a library on Mac OS X
using XCode 4.3.2's clang 3.1 compiler.
I want to build a universal (32-bit and 64-bit) shared library (dylib).
I've found that I can easily build a universal static library, but I can
only build a 64-bit-only dynamic library.
The SConstruct file and log are appended below.
Any suggestions would be most welcome. I can certainly live with a
static library, but would rather not have to. I didn't find anything in
the manual or a web search, though I expect I've overlooking something
basic.
...
I found the solution and posted it, but it does not seem to have gotten
through, so here it is again: set the desired architectures in both
CFLAGS and LINKFLAGS (I was missing the latter). For example:

archFlags = "-arch i386 -arch x86_64"

env = Environment(
CC = "clang",
CFLAGS = archFlags + " -Wall -pedantic",
LINKFLAGS = archFlags,
)
Post by William Deegan
How do you create a universal dynlib from the command line?
(What are the flags and which tool do you use to make it?)
I'm not that familiar with OSX
The source is compiled this way:
clang -o src/dt.os -c -arch i386 -arch x86_64 -fPIC src/dt.c

The library is then built this way:
clang -o libsla.dylib -arch i386 -arch x86_64 -dynamiclib src/dt.os...

Regards,

-- Russell

------------------------------------------------------
http://scons.tigris.org/ds/viewMessage.do?dsForumId=1272&dsMessageId=2949948

To unsubscribe, send an e-mail to [users-***@scons.tigris.org].
Russell E. Owen
2012-04-18 21:14:09 UTC
Permalink
Post by Russell E. Owen
I am using scons 2.1.0 to compile C code into a library on Mac OS X
using XCode 4.3.2's clang 3.1 compiler.
I want to build a universal (32-bit and 64-bit) shared library (dylib).
I've found that I can easily build a universal static library, but I can
only build a 64-bit-only dynamic library.
The SConstruct file and log are appended below.
Any suggestions would be most welcome. I can certainly live with a
static library, but would rather not have to. I didn't find anything in
the manual or a web search, though I expect I've overlooking something
basic.
-- Russell
env = Environment(
CC = "clang",
CFLAGS = "-arch i386 -arch x86_64",
)
staticLib = env.StaticLibrary(
target = "sla",
source =Glob("src/*.c"),
)
# I'd rather use a dylib, but this is 64-bit only; why?
env.SharedLibrary(
target = "sla",
source = libSrcList,
)
I solved it. I had to add LINKFLAGS:
env = Environment(
CC = "clang",
CFLAGS = "-arch i386 -arch x86_64",
LINKFLAGS = "-arch i386 -arch x86_64",
)

Dynamic libraries are working just fine now.

-- Russell

------------------------------------------------------
http://scons.tigris.org/ds/viewMessage.do?dsForumId=1272&dsMessageId=2949555

To unsubscribe, send an e-mail to [users-***@scons.tigris.org].
Loading...