How to create a 32bit shared library on a 64bit system?
Armin Lambacher
lambache at biochem.mpg.de
Wed Jun 13 13:38:29 BST 2007
Hello,
I have the problem that I must build a 32bit shared library, that will be used
with a 3rd party software (which is 32bit).
The system that I have is a Suse 10.2 linux, 64bit version on a Intel Core 2
CPU.
Now I tried the shared object template in kdevelopp (version 3.4.1) under
C++ --> CMakes based projects --> Shared Library.
This compiles and runs well if I don't make any changes.
Then I tried to find out at what point I could change the compiler/linker
flags to produce 32bit code. Googling for the solution gave me either so many
links that I could not find the correct one there or none at all. Maybe I
tried the wrong keywords.
I'm am complete newbie to CMake, I must admit.
Then I found the file CMakeLists.txt, where there seems to be an appropriate
place to put options. The file reads:
-------------------------
#this is just a basic CMakeLists.txt, for more information see the cmake
manpage
#add definitions, compiler switches, etc.
ADD_DEFINITIONS(-Wall -O2)
#build a shared library
ADD_LIBRARY(so_test SHARED so_test.cpp)
#for testing the shared library you probably need some test app too
ADD_EXECUTABLE(so_testtest so_testtest.cpp)
#need to link to some other libraries ? just add them here
TARGET_LINK_LIBRARIES(so_testtest so_test)
#add an install target here
#INSTALL_FILES(...)
#INSTALL_PROGRAMS(...)
#INSTALL_TARGET(...)
-------------------------
I tried to add "-m32" to the ADD_DEFINITIONS line, so that the line reads
ADD_DEFINITIONS(-m32 -Wall -O2)
According to the gcc documentation this should produce 32bit code. BTW, I'm
using the gcc 4.1.2 that comes with the suse distribution.
The I tried to build the project again. The output is:
--------------------------------------------------
cd '/home/lambache/cprog/so_test' && gmake -k -j1
/usr/bin/cmake -H/home/lambache/cprog/so_test -B/home/lambache/cprog/so_test --check-build-system
CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/lambache/cprog/so_test/CMakeFiles
2
gmake -f CMakeFiles/Makefile2 all
gmake -f src/CMakeFiles/so_test.dir/build.make
src/CMakeFiles/so_test.dir/depend
Scanning dependencies of target so_test
cd /home/lambache/cprog/so_test && /usr/bin/cmake -E
cmake_depends "KDevelop3" /home/lambache/cprog/so_test /home/lambache/cprog/so_test/src /home/lambache/cprog/so_test /home/lambache/cprog/so_test/src /home/lambache/cprog/so_test/src/CMakeFiles/so_test.dir/DependInfo.cmake
gmake -f src/CMakeFiles/so_test.dir/build.make
src/CMakeFiles/so_test.dir/build
/usr/bin/cmake -E
cmake_progress_report /home/lambache/cprog/so_test/CMakeFiles 1
[ 50%] Building CXX object src/CMakeFiles/so_test.dir/so_test.o
/usr/bin/c++ -Dso_test_EXPORTS -fPIC -m32 -Wall -O2 -o
src/CMakeFiles/so_test.dir/so_test.o -c /home/lambache/cprog/so_test/src/so_test.cpp
Linking CXX shared library libso_test.so
cd /home/lambache/cprog/so_test/src && /usr/bin/cmake -P
CMakeFiles/so_test.dir/cmake_clean_target.cmake
cd /home/lambache/cprog/so_test/src && /usr/bin/cmake -E cmake_link_script
CMakeFiles/so_test.dir/link.txt --verbose=1
/usr/bin/c++ -fPIC -shared -Wl,-soname,libso_test.so -o
libso_test.so "CMakeFiles/so_test.dir/so_test.o"
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/bin/ld:
warning: i386 architecture of input file `CMakeFiles/so_test.dir/so_test.o'
is incompatible with i386:x86-64 output
/usr/bin/cmake -E
cmake_progress_report /home/lambache/cprog/so_test/CMakeFiles 1
[ 50%] Built target so_test
gmake -f src/CMakeFiles/so_testtest.dir/build.make
src/CMakeFiles/so_testtest.dir/depend
gmake[2]: Für das Ziel »src/CMakeFiles/so_testtest.dir/depend« ist nichts zu
tun.
gmake -f src/CMakeFiles/so_testtest.dir/build.make
src/CMakeFiles/so_testtest.dir/build
Linking CXX executable so_testtest
cd /home/lambache/cprog/so_test/src && /usr/bin/cmake -P
CMakeFiles/so_testtest.dir/cmake_clean_target.cmake
cd /home/lambache/cprog/so_test/src
&& /usr/bin/c++ -fPIC "CMakeFiles/so_testtest.dir/so_testtest.o" -o
so_testtest -rdynamic -L/home/lambache/cprog/so_test/src -lso_test -Wl,-rpath,/home/lambache/cprog/so_test/src
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/bin/ld:
warning: i386 architecture of input file
`CMakeFiles/so_testtest.dir/so_testtest.o' is incompatible with i386:x86-64
output
/usr/bin/cmake -E
cmake_progress_report /home/lambache/cprog/so_test/CMakeFiles 2
[100%] Built target so_testtest
/usr/bin/cmake -E cmake_progress_start /home/lambache/cprog/so_test/CMakeFiles
0
*** Erfolg ***
-----------------------------------------------------------------------------
Interestingly the last line seems to indicate a successful build of the
project, however, there are some issues with linking, see the lines
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/bin/ld:
warning: i386 architecture of input file `CMakeFiles/so_test.dir/so_test.o'
is incompatible with i386:x86-64 output
/usr/lib64/gcc/x86_64-suse-linux/4.1.2/../../../../x86_64-suse-linux/bin/ld:
warning: i386 architecture of input file
`CMakeFiles/so_testtest.dir/so_testtest.o' is incompatible with i386:x86-64
output
The program crashes upon starting it with SIGSEGV.
Can somebody please put me into the right directon on how to solve this
problem?
Again, I'm a newbie to CMake, so at the moment I don't really know whether
there is an option in kdevelop where I can solve this or whether I have to
edit the CMake files.
Best regards
Armin Lambacher
More information about the KDevelop
mailing list