Compile boost as universal library (Intel and Apple Silicon architectures) - c++

I am trying to build boost library as dylib on MacOS. I need to build it for both the Intel architecture and the upcoming Apple Silicon (arm64) architecture.
I downloaded boost and ran the following commands:
./bootstrap.sh
./b2 -address-model=64 architecture=combined -a
lipo -archs always shows produced dylibs architecture is x86_64.
I have Xcode12 beta and MacOS Catalina 10.15.7,
I can build a sample universal library if I create a project in Xcode and set archs arm64 x86_64 in build settings.
Running command ./b2 cxxflags="-arch arm64 -arch x86_64" fails with following errors:
"clang++" -x c++ -fvisibility-inlines-hidden -m64 -O3 -Wall -fvisibility=hidden -Wno-inline -arch arm64 -arch x86_64 -ftemplate-depth-255 -fvisibility=hidden -fvisibility-inlines-hidden -DBOOST_ALL_NO_LIB=1 -DNDEBUG -I"." -c -o "bin.v2/libs/serialization/build/clang-darwin-12.0/release/link-static/threading-multi/visibility-hidden/polymorphic_xml_iarchive.o" "libs/serialization/src/polymorphic_xml_iarchive.cpp"
...failed clang-darwin.compile.c++ bin.v2/libs/serialization/build/clang-darwin-12.0/release/link-static/threading-multi/visibility-hidden/polymorphic_xml_iarchive.o...
clang-darwin.compile.c++ bin.v2/libs/serialization/build/clang-darwin-12.0/release/link-static/threading-multi/visibility-hidden/polymorphic_xml_oarchive.o
In file included from libs/serialization/src/polymorphic_xml_oarchive.cpp:16:
In file included from ./boost/serialization/config.hpp:18:
In file included from ./boost/config.hpp:57:
In file included from ./boost/config/platform/macos.hpp:28:
In file included from ./boost/config/detail/posix_features.hpp:18:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/unistd.h:71:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/_types.h:27:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:32:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/cdefs.h:807:2: error: Unsupported architecture
#error Unsupported architecture
^
In file included from libs/serialization/src/polymorphic_xml_oarchive.cpp:16:
In file included from ./boost/serialization/config.hpp:18:
In file included from ./boost/config.hpp:57:
In file included from ./boost/config/platform/macos.hpp:28:
In file included from ./boost/config/detail/posix_features.hpp:18:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/unistd.h:71:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/_types.h:27:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:33:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/machine/_types.h:34:2: error: architecture not supported
#error architecture not supported
^
In file included from libs/serialization/src/polymorphic_xml_oarchive.cpp:16:
In file included from ./boost/serialization/config.hpp:18:
In file included from ./boost/config.hpp:57:
In file included from ./boost/config/platform/macos.hpp:28:
In file included from ./boost/config/detail/posix_features.hpp:18:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/unistd.h:71:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/_types.h:27:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:55:9: error: unknown type name '__int64_t'
typedef __int64_t __darwin_blkcnt_t; /* total blocks */
^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:56:9: error: unknown type name '__int32_t'; did you mean '__int128_t'?
typedef __int32_t __darwin_blksize_t; /* preferred block size */
^
note: '__int128_t' declared here
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:57:9: error: unknown type name '__int32_t'; did you mean '__int128_t'?
typedef __int32_t __darwin_dev_t; /* dev_t */
^
note: '__int128_t' declared here
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:60:9: error: unknown type name '__uint32_t'; did you mean '__uint128_t'?
typedef __uint32_t __darwin_gid_t; /* [???] process and group IDs */
^
note: '__uint128_t' declared here
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:61:9: error: unknown type name '__uint32_t'; did you mean '__uint128_t'?
typedef __uint32_t __darwin_id_t; /* [XSI] pid_t, uid_t, or gid_t*/
^

The following works for me on Big Sur using Xcode 12.2. On Catalina 10.15.7 (19H15) I get the same error messages as OP.
./bootstrap.sh --with-libraries=regex,date_time
./b2 architecture=combined cxxflags="-arch x86_64 -arch arm64"

I'm on Monterey with an M1 (XCode 13.1) and failed to get any of the other answers to work, but I combined stuff from Navan and Petr along with some other bits to get the libboost_coroutine to work on x86_64. I arrived at the following script which builds all the boost libraries (why not, it doesn't take long on the M1):
#!/bin/sh
rm -rf arm64 x86_64 universal stage bin.v2
rm -f b2 project-config*
./bootstrap.sh cxxflags="-arch x86_64 -arch arm64" cflags="-arch x86_64 -arch arm64" linkflags="-arch x86_64 -arch arm64"
./b2 toolset=clang-darwin target-os=darwin architecture=arm abi=aapcs cxxflags="-arch arm64" cflags="-arch arm64" linkflags="-arch arm64" -a
mkdir -p arm64 && cp stage/lib/*.dylib arm64
./b2 toolset=clang-darwin target-os=darwin architecture=x86 cxxflags="-arch x86_64" cflags="-arch x86_64" linkflags="-arch x86_64" abi=sysv binary-format=mach-o -a
mkdir x86_64 && cp stage/lib/*.dylib x86_64
mkdir universal
for dylib in arm64/*; do
lipo -create -arch arm64 $dylib -arch x86_64 x86_64/$(basename $dylib) -output universal/$(basename $dylib);
done
for dylib in universal/*; do
lipo $dylib -info;
done
This script prints out the lipo info for each dylib in the universal directory, so you can see quickly that every one has both x86_64 and arm64 inside. I had the following result, maybe it's useful for you to see if your output matches:
Architectures in the fat file: universal/libboost_atomic.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_chrono.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_container.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_context.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_contract.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_coroutine.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_date_time.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_filesystem.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_graph.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_iostreams.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_locale.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_log.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_log_setup.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_numpy27.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_prg_exec_monitor.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_program_options.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_python27.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_random.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_regex.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_serialization.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_stacktrace_addr2line.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_stacktrace_basic.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_stacktrace_noop.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_system.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_thread.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_timer.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_type_erasure.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_unit_test_framework.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_wave.dylib are: x86_64 arm64
Architectures in the fat file: universal/libboost_wserialization.dylib are: x86_64 arm64

After spending considerable amount of time here:
https://github.com/bfgroup/b2/issues/105
I was able to compile boost on arm64. The command line is:
./b2 architecture=arm address-model=64 asmflags=--target=arm64-apple-darwin21.2.0 cflags=--target=arm64-apple-darwin21.2.0 cxxflags=--target=arm64-apple-darwin21.2.0 linkflags=--target=arm64-apple-darwin21.2.0 -s NO_LZMA=1 -s NO_ZSTD=1 abi=aapcs
the LZMA and ZSTD flags are there since I did not have an universal binary for those libs on my machine.

I was facing the same issue and came across this answer, which was for creating universal binaries for i386 and x86_64.
To summarise the answer, you need to run ./b2 twice ( with different toolsets as clang always builds for x86_64, even if you pass the appropriate CXXFlags
This is the script I used to first individually generate the libraries I required and then combined them using lipo
#!/bin/sh
rm -rf arm64 x86_64 universal
./bootstrap.sh --with-toolset=clang --with-libraries=thread,system,filesystem,program_options,serialization
./b2 cxxflags="-arch arm64" toolset=darwin -a
mkdir -p arm64 && cp stage/lib/*.dylib arm64
./b2 toolset=clang cxxflags="-arch arm64 -arch x86_64" -a
mkdir x86_64 && cp stage/lib/*.dylib x86_64
mkdir universal
for dylib in arm64/*; do
lipo -create -arch arm64 $dylib -arch x86_64 x86_64/$(basename $dylib) -output universal/$(basename $dylib);
done

You don't need to use lipo, you can pass
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk to cxxflags and it will build a universal library out of the box.

I followed the answer by Navan Chauhan which seems to be the way to go on macOS 10.15.7 with Xcode 12.3.
My only issue was that the build system was adding additional -arch armv4t clang option (or something similar) which fails the build. Using the architecture=combine cannot work as well as it is able to manage Intel and PowerPC only. What does work for me instead is:
bootstrap.sh --with-toolset=clang-darwin and cxxflags, cflags and linkflags set to -arch x86_64 -arch arm64 plus additional options.
x86_64 build: b2 toolset=clang-darwin target-os=darwin architecture=x86 stage and cxxflags, cflags and linkflags set to -arch x86_64 only (plus additional options).
arm64 build: b2 toolset=clang-darwin target-os=darwin architecture=arm abi=aapcs stage and cxxflags, cflags and linkflags set to -arch arm64 only (plus additional options).
Merge libraries with lipo…
I've been forced to set the ABI also as the automatic-guess-something is not able to recognize Apple Silicon goal therefor some assembly stuff is not compiled – hence missing symbols later on during the build. Finally the armv4t issue is solved by the clang-darwin toolset.
The only caveat of this at the moment is that both builds go into the same architectural/configuration directories which can be solved by custom user-config.jam or by immediate call to install just after each stage which is what I did.
Works on:
Host platform: Intel
macOS 10.15.7
Xcode 12.3 (with Command Line Tools installed)
Boost 1.75.0 (dependent compression and ICU libraries already compiled as universal)

For macOS with M1 building boost 1.81.0
./bootstrap.sh
sudo ./b2 -address-model=64 architecture=arm+x86 install
Libraries that support both architectures are installed

Related

What is the proper way to build for macOS-x86_64 using cmake on Apple M1 (arm)?

I'm using a library that I cannot compile for Apple M1, so I have decided to compile it and use it using (Rosetta 2) for x86_64 which I successfully did following this to install brew and clang for x86_64.
However when I compile my project and try to link it against this library I get this error:
ld: warning: ignoring file ..../libapronxx.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
...
ld: symbol(s) not found for architecture arm64
I have tried to the set compiler and linker flags ("-arch x86_64") but still got the same problem.
My question is: What is the proper way to build for macOS-x86_64 using cmake on Apple M1 (arm)?
Additional information: I'm using cmake via CLion.
UPDATE:
I successfully compiled my project using the following commands:
# install a x86 cmake
arch -x86_64 /usr/local/bin/brew install cmake
...
# in the build directory
arch -x86_64 /usr/local/bin/cmake ..
make
arch -x86_64 ./my_exe
I also specified the architecture for clang using -arch flag
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -arch x86_64 -O3")
string(APPEND CMAKE_CC_FLAGS_RELEASE " -arch x86_64 -O3")
# did the same for debug too
While this work fine, I still don't believe it is the proper way to use cmake to build for macOS-x86_64, in fact I cannot take the advantages of my IDE with all this manual approach.
After checking CMake source code, I found that it is enough to set CMAKE_OSX_ARCHITECTURES to x86_64:
set(CMAKE_OSX_ARCHITECTURES "x86_64")
This is the cleanest way so far to solve this issue, and work straight forward with CLion too.

Attempting to compile a GNU library on OS X for 32 and 64 bit

thanks in advance for any help on this, I have scoured the web and can't quite get this to work.
I am trying to compile from source the libgcrypt library from GNU on a mac running OS X 10.9.4. I need to compile to a 32 bit binary which I will later use lipo to blend with the 64 bit one (I have the 64 bit part working). I am trying to be able to reference the libgcrypt binary from both 32 and 64 bit programs. Link here: http://www.gnu.org/software/libgcrypt/
I have grabbed an un-tared the source.
I have used the following configure:
$ ./configure -host=i386-apple-darwin10.5.0 CFLAGS='-arch i386' LDFLAGS='-arch i386'
Which results in:
Libgcrypt v1.6.2 has been configured as follows:
Platform: Darwin (i386-apple-darwin10.5.0)
Hardware detection module: hwf-x86
Enabled cipher algorithms: arcfour blowfish cast5 des aes twofish
serpent rfc2268 seed camellia idea salsa20
gost28147
Enabled digest algorithms: crc gostr3411-94 md4 md5 rmd160 sha1
sha256 sha512 tiger whirlpool stribog
Enabled kdf algorithms: s2k pkdf2 scrypt
Enabled pubkey algorithms: dsa elgamal rsa ecc
Random number generator: default
Using linux capabilities: no
Try using Padlock crypto: yes
Try using AES-NI crypto: yes
Try using Intel PCLMUL: yes
Try using DRNG (RDRAND): yes
Try using Intel AVX: yes
Try using Intel AVX2: yes
Try using ARM NEON: n/a
But when I try and make (or sudo make), boom!
Making all in src
/bin/sh ../libtool --tag=CC --mode=link gcc -I/opt/local/include -arch i386 -Wall -arch i386 -o mpicalc mpicalc-mpicalc.o libgcrypt.la -L/opt/local/lib -lgpg-error
libtool: link: gcc -I/opt/local/include -arch i386 -Wall -arch i386 -o .libs/mpicalc mpicalc-mpicalc.o ./.libs/libgcrypt.dylib -L/opt/local/lib -lgpg-error
ld: warning: ignoring file /opt/local/lib/libgpg-error.dylib, file was built for x86_64 which is not the architecture being linked (i386): /opt/local/lib/libgpg-error.dylib
Undefined symbols for architecture i386:
"_gpg_strerror", referenced from:
_print_mpi in mpicalc-mpicalc.o
_scan_mpi in mpicalc-mpicalc.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [mpicalc] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
Also of possible interest:
$ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
Relevant web links:
https://gmplib.org/list-archives/gmp-discuss/2010-September/004312.html
Many, many thanks in advance for any help.
Okay, I have solved this, and hopefully other folks will find this of interest.
The configure flags above aren't quite right. The proper configure command is (-m32 is needed):
./configure -host=i386-apple-darwin CFLAGS='-arch i386 -m32' LDFLAGS='-arch i386 -m32'
This will properly compile. FYI, In order for the 32-bit libgcrypt library to compile, you will need a 32 bit version of libgpg-error.
With the 32 bit versions of these libraries compiled, I used lipo to blend the 32-bit and 64-bit versions so that both 32-bit programs and 64-bit programs can both access these libraries.
lipo -create ./libgcrypt.20.dylib /usr/local/lib/libgcrypt.20.dylib -output /tmp/libgcrypt.20.dylib
sudo mv /tmp/libgcrypt.20.dylib /usr/local/lib/libgcrypt.20.dylib

How to make Boost dylibs universal (i386 & x86_64) on os x?

I'm trying to compile a Boost library into a universal binary file (i.e. a "fat" file that contains builds for both the i386 and x86_64 architectures).
Souring the internet and SO I assembled the following instructions.
Download boost (e.g. from http://www.boost.org/users/download/)
In the downloaded folder, type ./bootstrap.sh
(or, in my case ./bootstrap.sh --with-libraries=thread, since I only need the thread library)
type ./b2 install cxxflags="-arch i386 -arch x86"
These steps installed the Boost thread library to /usr/local/lib/ (its standard location). The resulting static library is a universal binary. So far, so good.
$ lipo -i /usr/local/lib/libboost_thread.a
Architectures in the fat file: /usr/local/lib/libboost_thread.a are: i386 x86_64
The dynamic library, however, only seems to have been compiled for x86_64.
$ lipo -i /usr/local/lib/libboost_thread.dylib
Non-fat file: /usr/local/lib/libboost_thread.dylib is architecture: x86_64
I'd like the .dylib to be universal as well. Does anyone know how I can compile it for i386 as well as x86_64?
I was struggling with this as well. The trick seems to be two-fold.
You need to use a different toolset to build the i386 .dylib. clang will build an x86_64 .dylib no matter what I tried, but darwin with the right flags will build an i386 .dylib
Build twice, once for i386, once for x86_64; then use lipo to combine the result into a "fat" .dylib
Here's what I quick threw together to reproducibly get 'fat' .dylibs. Find the ones you need in universal/. The static 'fat' .a libs are left in stage/lib/.
rm -rf i386 x86_64 universal
./bootstrap.sh --with-toolset=clang --with-libraries=filesystem
./b2 toolset=darwin -j8 address-model=32 architecture=x86 -a
mkdir -p i386 && cp stage/lib/*.dylib i386
./b2 toolset=clang -j8 cxxflags="-arch i386 -arch x86_64" -a
mkdir x86_64 && cp stage/lib/*.dylib x86_64
mkdir universal
for dylib in i386/*; do
lipo -create -arch i386 $dylib -arch x86_64 x86_64/$(basename $dylib) -output universal/$(basename $dylib);
done
One-liner:
rm -rf i386 x86_64 universal && ./bootstrap.sh --with-toolset=clang --with-libraries=filesystem && ./b2 toolset=darwin -j8 address-model=32 architecture=x86 -a && mkdir -p i386 && cp stage/lib/*.dylib i386 && ./b2 toolset=clang -j8 cxxflags="-arch i386 -arch x86_64" -a && mkdir x86_64 && cp stage/lib/*.dylib x86_64 && mkdir universal && for dylib in i386/*; do lipo -create -arch i386 $dylib -arch x86_64 x86_64/$(basename $dylib) -output universal/$(basename $dylib); done

Building Portaudio on OSX 10.7.5 using SDK10.6 or 10.7 fails

I am still having trouble building the Portaudio library on my system, which is OSX 10.7.5 with Xcode 4.3.2, having Command Line Tools installed and having SDK10.6 and SDK10.7 under
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
I describe shortly (also for others that run into the same problem) what I have done so far (following different solutions I have found on the web).
1) I downloaded "Portaudio" / pa_stable_v19_20111121.tgz (last stable release) from:
www.portaudio.com/download.html
2) I read the instructions on building Portaudio here:
www.portaudio.com/docs/v19-doxydocs/compile_mac_coreaudio.html
and tried to compile from a Terminal window with the suggested command:
./configure && make
This resulted (not so surprisingly) in a lot of errors ending with:
llvm-gcc-4.2: error trying to exec '/usr/bin/../llvm-gcc-4.2/bin/powerpc-apple-darwin11-llvm-gcc-4.2': execvp: No such file or directory
lipo: can't open input file: /var/folders/1_/xkp08ky561jg02zjjrpsxg940000gn/T//ccPxCTrJ.out (No such file or directory)
make: * [src/hostapi/coreaudio/pa_mac_core.lo] Error 1
This happens because "ppc" is not supported anymore since OSX 10.5. Moreover the "Developer" folder doesn't exist on OSX 10.7 and everything that was in the Developer folder has moved to
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
3) I downloaded a patch (mac_configure_patch.txt) to fix "configure" from:
https://www.assembla.com/spaces/portaudio/tickets/216#/activity/ticket:
and copied it to the portaudio directory and applied it by typing in Terminal:
$ patch < mac_configure_patch.txt
A confirmation message said:
patching file configure.in
So everything seems fine. But still Portaudio is trying to build for "ppc".
4) Now I set the ARCHFLAGS, CFLAGS, LDFLAGS to only build for architecture i386 as follows (disabling universal build):
$ MACOSX_DEPLOYMENT_TARGET="10.7" ARCHFLAGS="-arch i386" CFLAGS="-O2 -g -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -arch i386 -mmacosx-version-min=10.7" LDFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sd -arch i386 -mmacosx-version-min=10.7" ./configure --disable-mac-universal
5) Further I found that:
A): "#include AudioToolbox.h" in ".include/pa_mac_core.h" should be UNCOMMENTED
B): that "-wError" from "Makefile" (not Makefile.in) should be removed.
accoding to:
http://www.fluxforge.com/blog/building-portaudio-under-os-x-107-lion
6) Now I try to build (using: "sudo make"), compilation starts but but fails with:
ld: framework not found CoreAudio
collect2: ld returned 1 exit status
make: * [lib/libportaudio.la] Error 1
7) So I try to point to the framework using "-F/System/Library/Frameworks -framework CoreAudio"
leading to the following Terminal command:
$ MACOSX_DEPLOYMENT_TARGET="10.7" ARCHFLAGS="-arch i386" CFLAGS="-O2 -g -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -arch i386 -mmacosx-version-min=10.7" LDFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sd -arch i386 -mmacosx-version-min=10.7 -F/System/Library/Frameworks -framework CoreAudio" ./configure --disable-mac-universal
which seems to fix the CoreAudio framework issue but results in another error saying:
ld: library not found for -lSystem
collect2: ld returned 1 exit status
make: * [lib/libportaudio.la] Error 1
I am now stuck at this point. Did anyone experience the same problems when trying to build Portaudio on OSX 10.7 using SDK10.6 or SDK10.7. Did anyone find a solution to how to build Portaudio from Terminal?
I am very thankful for any hints!!!
Thanks in advance!
Try the latest svn. If that doesn't work right off the bat, you might need to muck with some of the flags.
eg, in configure.in:
change -Werror to -Wall
add -Wno-deprecated (you shouldn't need this, but just in case)
then run
./configure --disable-mac-universal
and make as usual.
OK, finally I solved the issue. Hope the solution will help others as well. I just forgot to also add the path to the CoreAudio framework to the CFLAGS. Here is the final configure/build command for building portaudio on OSX 10.7.5 using SDK10.7 for architecture i386 & x86_64:
Open a Terminal window in the portaudio directory and type:
MACOSX_DEPLOYMENT_TARGET="10.7" ARCHFLAGS="-arch i386" CFLAGS="-O2 -g -Wall -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -arch i386 -mmacosx-version-min=10.7 -F/System/Library/Frameworks -framework CoreAudio" LDFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -arch i386 -mmacosx-version-min=10.7 -F/System/Library/Frameworks -framework CoreAudio" ./configure --disable-mac-universal
If this has finished, you need to edit Makefile and change the mention of -Werror to -Wall.
Then:
make
Voila. There you have your "libportaudio.la" in the portaudio/lib directory. You can now type
sudo make install
(you'll be asked to confirm using your password)
to put the library in the system directory.
Finally you can mess around with Portaudio!
Have fun!
Tried your instructions on Mac OSX Mountain Lion (10.8), and it was progressing a lot in compilation but then was failing with:
In file included from ./test/patest_sine_channelmaps.c:53:
./include/pa_mac_core.h:100:1: error: unknown type name 'AudioDeviceID'
AudioDeviceID PaMacCore_GetStreamInputDevice( PaStream* s );
^
./include/pa_mac_core.h:109:1: error: unknown type name 'AudioDeviceID'
AudioDeviceID PaMacCore_GetStreamOutputDevice( PaStream* s );
^
2 errors generated.
make: *** [bin/patest_sine_channelmaps] Error 1
However, I figured out you can simply use Homebrew (apt-like packet manager for OSX) and it will do the dirty job like a charm. Find binaries and headers in the specified install directory :)
$ brew install portaudio
Warning: It appears you have MacPorts or Fink installed.
Software installed with other package managers causes known problems for
Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again.
==> Downloading http://www.portaudio.com/archives/pa_stable_v19_20111121.tgz
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
==> Patching
patching file include/pa_mac_core.h
==> ./configure --prefix=/usr/local/Cellar/portaudio/19.20111121 --enable-mac-un
==> make install
/usr/local/Cellar/portaudio/19.20111121: 8 files, 316K, built in 20 seconds

Xcode 4 SFML 2 error

I used the SFML 2 installer, it can be found here. http://www.sfml-dev.org/download.php
Ld /Users/pjquinn/Library/Developer/Xcode/DerivedData/gangnam_style-ayfrlelgnycrzpdbmwbkqgtkkryv/Build/Products/Debug/gangnam_style.app/Contents/MacOS/gangnam_style normal x86_64
cd /Users/pjquinn/Programming/C++/gangnam_style
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
-L/Users/pjquinn/Library/Developer/Xcode/DerivedData/gangnam_style-ayfrlelgnycrzpdbmwbkqgtkkryv/Build/Products/Debug
-F/Users/pjquinn/Library/Developer/Xcode/DerivedData/gangnam_style-ayfrlelgnycrzpdbmwbkqgtkkryv/Build/Products/Debug
-filelist /Users/pjquinn/Library/Developer/Xcode/DerivedData/gangnam_style-ayfrlelgnycrzpdbmwbkqgtkkryv/Build/Intermediates/gangnam_style.build/Debug/gangnam_style.build/Objects-normal/x86_64/gangnam_style.LinkFileList
-mmacosx-version-min=10.7 -lsfml-system-d -lsfml-window-d -lsfml-graphics-d -lsfml-audio-d -lsfml-network-d -stdlib=libc++ -fobjc-link-runtime -framework Foundation -o /Users/pjquinn/Library/Developer/Xcode/DerivedData/gangnam_style-ayfrlelgnycrzpdbmwbkqgtkkryv/Build/Products/Debug/gangnam_style.app/Contents/MacOS/gangnam_style
ld: library not found for -lsfml-system-d clang: error: linker command failed with exit code 1 (use -v to see invocation)
When I'm creating a project should I select the Use Frameworks box?
Debug binaries are not shipped with the installer.
You should also have a look at the other issues
I used their template and checked the "Use Frameworks" box, but still had problems. What I ended up doing was adding the SFML frameworks files (which their installer script put in ~/Libraries/Frameworks) in the project myself (simple drag'n'drop). I double checked and made sure the added frameworks were then included in the Build Phases (which they were), and everything worked fine.