Build and install Boost 1.60 in 32 bit on a 64 bit Mac OS X El Capitan - c++

I have an application that use the 32 bit boost library( 1.48 ). The 1.48 version of boost was pre built on 32 bit platform and uses older C++ standards.
For example file libboost_wserialization.dylib gives
libboost_wserialization.dylib: Mach-O universal binary with 2 architectures
libboost_wserialization.dylib (for architecture i386): Mach-O dynamically linked shared library i386
libboost_wserialization.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
The requirements have changed and i want to link/use the boost 1.60 with C++ 11 and 32 bit.
I have downloaded the 1.60 boost and modified the bootstrap.sh to include application specific lib and include directories.
I am running the following command
./b2 cxxflags="-std=c++0x -stdlib=libc++" linkflags="-stdlib=libc++" address-model=32 architecture=x86 install
I get the following error
error: unknown target CPU 'i686' for all the files.
If i install the default then I don get the 32 bit version of the boost libraries and application fails to link.
How do i get rid of this error ?. The machine that i am building boost on is Mac OS X El capitan 64 bit.
The entire error is
"clang++" -x c++ -std=c++0x -stdlib=libc++ -O3 -O3 -Wno-inline -Wall -march=i686 -DBOOST_ALL_NO_LIB=1 -DBOOST_MATH_TR1_DYN_LINK=1 -DNDEBUG -I"." -I"libs/math/src/tr1" -c -o "bin.v2/libs/math/build/clang-darwin-4.2.1/release/address-model-32/threading-multi/atanh.o" "libs/math/build/../src/tr1/atanh.cpp"
...failed clang-darwin.compile.c++ bin.v2/libs/math/build/clang-darwin-4.2.1/release/address-model-32/threading-multi/atanh.o...
clang-darwin.compile.c++ bin.v2/libs/math/build/clang-darwin-4.2.1/release/address-model-32/threading-multi/cbrt.o
error: unknown target CPU 'i686'

Try with address-model=64.
More info: http://www.boost.org/build/doc/html/bbv2/reference/tools.html#bbv2.reference.tools.compiler.darwin

Related

Building C++11 iOS console app from command line

I am trying to build a simple C++ console app for jailbroken iOS device.
I use the following command:
`xcrun --sdk iphoneos --find g++` -std=c++14 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -arch armv7 -arch armv7s -arch arm64 -c main.cpp
It compiles without errors.
But I cannot use c++11 features like chrono dispite '-std=c++14' passed:
chrono header is present in iOS SDK: ../iPhoneOS.sdk/usr/include/c++/v1.
I use XCode Version 9.2 (9C40b), macOS 10.12.6 (16G1710)

building 32 exe on 64 bit open suse linux gives link error

In my VM, I have installed open suse linux 64 bit.
Trying to build an exe for 32 bit.
But on running the command :
g++ prg1.cpp -o prg1 -m32
I get the following error:
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld:
skipping incompatible
/usr/lib64/gcc/x86_64-suse-linux/4.8/libstdc++.so when searching for
-lstdc++ /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld:
skipping incompatible /usr/lib64/gcc/x86_64-suse-linux/4.8/libstdc++.a
when searching for -lstdc++
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld:
cannot find -lstdc++ collect2: error: ld returned 1 exit status
To build for 32 i have installed the necessary rpms for 32 bit.
On running
g++ -print-search-dirs , the output is
install: /usr/lib64/gcc/x86_64-suse-linux/4.8/ programs:
=/usr/lib64/gcc/x86_64-suse-linux/4.8/:/usr/lib64/gcc/x86_64-suse-linux/4.8/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.8/:/usr/lib64/gcc/x86_64-suse-linux/:/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/x86_64-suse-linux/4.8/:/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/
libraries:
=/usr/lib64/gcc/x86_64-suse-linux/4.8/:/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/lib/x86_64-suse-linux/4.8/:/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/lib/../lib64/:/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../x86_64-suse-linux/4.8/:/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../lib64/:/lib/x86_64-suse-linux/4.8/:/lib/../lib64/:/usr/lib/x86_64-suse-linux/4.8/:/usr/lib/../lib64/:/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/lib/:/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../:/lib/:/usr/lib/
Although the 32 bit libstdc++ is also installed, the linker is not able to link to it. Is any specific flag required to tell the linker to build 32 bit
Or I have to install any other package?
To build for 32 i have installed the necessary rpms for 32 bit.
No, you have not.
Note that in order to build programs you need 32-bit runtime and development libraries. I am guessing that you've installed the former, but not the latter.

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

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.4 10.6 sdk library not found for -lstdc++

I am trying to build a dylib using Xcode 4.4, which previously built fine. I have run into 2 issues:
If I build against the 10.7 sdk, it builds fine. However when testing on 10.6.8 I get the following error:
Dyld Error Message: Symbol not found: _wcsdup Referenced from:
/lib/Release/libwx_baseu-2.9.dylib Expected in:
/usr/lib/libSystem.B.dylib
If I build against the 10.6 sdk (extracted from a download of Xcode 4.3.3), I get the following link error:
Ld build/Debug/libCodec.dylib normal i386
cd /Developer/Projects/Common/osx
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Applications/Xcode.app/Contents/Developer/usr/bin/llvm-g++-4.2 -arch i386 -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk
-L/Developer/Projects/Common/osx/build/Debug -L/Developer/Packages/libsndfile/osx/lib -L/Developer/Packages/wxWidgets/build-debug/lib -F/Developer/Projects/Common/osx/build/Debug -filelist /Developer/Projects/Common/osx/build/Common.build/Debug/Codec.build/Objects-normal/i386/Codec.LinkFileList
-install_name "#rpath/libCodec.dylib" -mmacosx-version-min=10.6 -lSampleFormat -lSoundFile -lsndfile.1 -lwx_baseu-2.9 -single_module -compatibility_version 1 -current_version 1 -o /Developer/Projects/Common/osx/build/Debug/libCodec.dylib
ld: library not found for -lstdc++ collect2: ld returned 1 exit status
Command
/Applications/Xcode.app/Contents/Developer/usr/bin/llvm-g++-4.2 failed
with exit code 1
I would prefer to build against the 10.6 sdk, since i need to support 10.6.8. In all cases I set my min deployment target to 10.6, however that hasn't helped.
Update (08/05/2012):
I resolved the error I was receiving when building against the 10.6 SDK by changing to apple's devualt llvm 4.0 compiler (instead of the llvm gcc compiler which I was using).
Just because you manually copied the 10.6 from an older version of Xcode doesn't mean your new Xcode is going to know what to do with it.
But do not fret, simply set the Deployment Target (as you already have done) to 10.6 and link against whatever the current SDK that is shipping with Xcode 4.4.
You'll run on 10.6 just fine.
The same concept applies for iOS, and here's a related question that adds some extra detail (in terms of iOS, but the same philosophy applies for MacOS).