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

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.

Related

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

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

How to properly configure Clang?

I've just compiled latest reps of LLVM, Clang and libc++. Now however I have no idea how to configure the environment to use them. I've added in $PATH the one to compiled binaries and have set the
$D_LIBRARY_PATH=$(llvm-config --libdir)
but anyway when I test run 'clang' with example file it uses some '/usr/bin/ld' linker which I have no idea what is it (as I've uninstalled 'g++' because thought it was the problem (before 'clang' used some linker from it) and I don't have any other C++ compilers).
So now how do I point out the right 'llvm-ld', libc++ include and library paths? I don't want to pass some complex arguments every-time. Perhaps I should set some environment variables.
I'm also using KDevelop with the same effect.
Don't judge me if this sounds stupid but it's my first time with Linux (have always used Windows before). I'm using latest 'OpenSUSE' dist.
Update - here is the output window of CodeLite using clang compiler:
/bin/sh -c 'make -j 2 -e -f Makefile'
----------Building project:[ ClangTest - Debug ]---------- make[1]: Entering directory
'/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Workspace/CL_C++_WP/ClangTest'
clang++ -c
"/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Workspace/CL_C++_WP/ClangTest/main.cpp"
-stdlib=libc++ -o ./Debug/main.cpp.o -I. -I/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Build/include/c++/v1/
clang++ -o ./Debug/ClangTest #"ClangTest.txt" -L.
-L/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Build/lib/ /usr/bin/ld: cannot find crtbegin.o: No such file or directory
/usr/bin/ld: cannot find -lstdc++ /usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lgcc clang-3.7: error: linker command failed
with exit code 1 (use -v to see invocation) ClangTest.mk:76: recipe
for target 'Debug/ClangTest' failed make[1]: * [Debug/ClangTest]
Error 1 make[1]: Leaving directory
'/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Workspace/CL_C++_WP/ClangTest'
Makefile:4: recipe for target 'All' failed make: * [All] Error 2 0
errors, 0 warnings
You should be able to run make install with perhaps an optional DESTDIR=/...... so that it doesn't clobber your system files.
Since you're on OpenSUSE, you might as well use your distribution's build services, and install the SVN version of LLVM-Clang from here. You should be able to find libc++ and LLVM itself as well.
Otherwise, make install DESTDIR=/opt/llvm should work, and then you can add /opt/llvm/bin/ to PATH and use libc++ by adding this compile and link option: -stdlib=libc++. You'll need something like /opt/llvm/lib in LD_LIBRARY_PATH as well to find the libc++ so.
This should work pretty much out of the box, but I have only ever used my distribution's packages, not a self-built Clang to do this.
Note that Clang still uses your system linker, ld, and this is fine. Currently, LLVM does not yet provide a fully functional alternative to this program, but they are working on it.
EDIT: It seems you uninstalled too much: Clang also uses the GCC crtbegin and crtend object files. So just install GCC again along with glibc and its dev package.

Missing libAnalyzer

I am trying to build the analyzer using the Saleae SDK 1.1.19 but run into an error when running the python script. Not sure if it is because I am running a 64bit version of Ubuntu. I also could not find the ./lib/libAnalyzer.so
link to the analyzer that I am using
https://www.saleae.com/index
Error:
/usr/bin/ld: skipping incompatible ../lib/libAnalyzer.so when searching for -lAnalyzer
/usr/bin/ld: cannot find -lAnalyzer
collect2: ld returned 1 exit status
g++ L"../lib" -lAnalyzer -shared -o"debug/libNSLogicAnalyzer.so" debug/NSLogicAnalyzer.o debug/NSLogicAnalyzerSettings.o debug/NSLogicAnalyzerResults.o
System information:
Ubuntu 12.04LTS 64bit,
Python 2.7.3
thanks!
LC
Ah figured it out, it was calling the 32bit libAnalyzer.so in the lib folder. I just renamed the 64 bit to the same name as the 32bit (renamed the 32bit to something else so it would not create the error again)

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

libstdc++ 64bit and 32bit version on the same machine

I am trying to cross compile a version of my software for a 64bit platform. Can I have the 32bit and 64bit version of libstdc++ installed on the same machine without too much worries of breaking my linux install. The Os is 32bit ubuntu.
I have not cross compiled before and just wanted to check that if I set my CFLAGS and LDFLAGS
for the appropriate CPU I should be ok once I have the correct versions of libstdc++ installed.
I checked a 64bit version of ubuntu however this has a symbolic link
lib64 -> lib
this would mess up lots if this is the case on a 32bit machine too anyone know how to sort this?
I am hitting the following error at the moment
[exec] /usr/bin/ld: skipping incompatible /usr/lib/gcc/i486-linux-gnu/4.2.4/libstdc++.so
[exec] /usr/bin/ld: skipping incompatible /usr/lib/gcc/i486-linux-gnu/4.2.4/libstdc++.a
when searching for -lstdc++ [exec] /usr/bin/ld: skipping incompatible
and so on till
[exec] /usr/bin/ld: cannot find -lstdc++
[exec] collect2: ld returned 1 exit status
Which seems to be due to fact I do not have the 64bit version of libstdc++
Sure you can.
Just put them into /usr/lib and /usr/lib64, respectively.
Can't check it on Ubuntu, but on Fedora they get there right from the packages:
[~#] repoquery -q -l libstdc++.i386
/usr/lib/libstdc++.so.6
/usr/lib/libstdc++.so.6.0.10
[~#] repoquery -q -l libstdc++.x86_64
/usr/lib64/libstdc++.so.6
/usr/lib64/libstdc++.so.6.0.10