Re: Mac OSX - Linker Errors

620 views
Skip to first unread message

Kamlesh Mallick

unread,
May 10, 2013, 3:28:21 AM5/10/13
to googletes...@googlegroups.com
So i decided to use CMake as that is recommended by Google tests...

but i still get issues with 32 bit binaries

Here is what i did 
a) in my Google Test folder = mkdir mybuild
b) cd mybuild
c) cmake /AC/H/tools/googletests  (this generates Makefile)
d) make  (this generates the gtest libraries - libgtest.a and libgtest_main.a )
e) I check the architechture
    lipo -info libgtest.a
input file libgtest.a is not a fat file
Non-fat file: libgtest.a is architecture: x86_64
(its build it for 64 bit architecture)

d) Now when i try to statically link the (libgtest.a) with my Unix executable (containing the tests)
    i run the following command and here is the output...

make -f Makefile.newWay
echo linking /ac/h/tools/mtxtests/build/unix/macosx/debug/mtxtests for unix/macosx/debug ; \

sh -c ' gcc -o /ac/h/tools/mtxtests/build/unix/macosx/debug/mtxtests /ac/h/tools/mtxtests/build/unix/macosx/debug/ACBaseTest.o /ac/h/tools/mtxtests/build/unix/macosx/debug/XmlLibTest.o /ac/h/tools/mtxtests/build/unix/macosx/debug/TestCase1.o /ac/h/tools/mtxtests/build/unix/macosx/debug/main.o /ac/h/tools/googletests/mybuild/libgtest_main.a /ac/h/library/src/MtxLib/build/unix/macosx/debug/libMtx.so -execute -execute  -m32 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -fPIC -fvisibility=hidden -g -lpthread -ldl -lstdc++ -lpam -m32 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk /ac/h/library/lib/unix/macosx/libcrypto.1.0.0.dylib /ac/h/library/lib/unix/macosx/libssl.1.0.0.dylib'  ; \

You can see the GCC command above, but when it comes to statically linking our libgtest.a file, i get errors

linking /ac/h/tools/mtxtests/build/unix/macosx/debug/mtxtests for unix/macosx/debug
ld: warning: ignoring file /ac/h/tools/googletests/mybuild/libgtest_main.a, file was built for archive which is not the architecture being linked (i386): /ac/h/tools/googletests/mybuild/libgtest_main.a
Undefined symbols for architecture i386:
  "testing::InitGoogleTest(int*, char**)", referenced from:
      _main in main.o
  "testing::AssertionResult::AssertionResult(testing::AssertionResult const&)", referenced from:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Looks like CMake builds a 32 bit libraries ( libgtest.a &  libgtest_main.a), is there anyway of building 32 bit libraries using CMake?


Thanks for going thro this long post.  Appreciate any help.



On Thursday, May 9, 2013 4:13:17 PM UTC+5:30, Kamlesh Mallick wrote:
Hey experts,

    Am trying to setup and run Google Tests.
    I did the following on my Mac 

   a) $ wget http://googletest.googlecode.com/files/gtest-1.6.0.zip    (I Installed 'wget' previosuly)
   b)  Unzip and build google test
$ unzip gtest-1.6.0.zip
$ cd gtest-1.6.0
$ ./configure 
$ make
 c)  "Install" the headers and libs on your system
    $ sudo cp -a include/gtest /usr/include
    $ sudo cp -a lib/.libs/* /usr/lib/
d)  "Install" the headers and libs.
    I see a libs/.libs folder with the libraries = libgtest.dylib  and other files.
e) Start compile
  The compiling goes ok.  But am facing crazy Linker issues.  Here is the output
 mac-kmallick-01:mtxtests bmctiac$ make -f Makefile.newWay
echo linking /AC/H/tools/mtxtests/build/unix/macosx/debug/mtxtests for unix/macosx/debug ; \
sh -c ' gcc -o /AC/H/tools/mtxtests/build/unix/macosx/debug/mtxtests /AC/H/tools/mtxtests/build/unix/macosx/debug/ACBaseTest.o /AC/H/tools/mtxtests/build/unix/macosx/debug/XmlLibTest.o /AC/H/tools/mtxtests/build/unix/macosx/debug/TestCase1.o /AC/H/tools/mtxtests/build/unix/macosx/debug/main.o /AC/H/library/src/MtxLib/build/unix/macosx/debug/libMtx.so -execute -execute -m32 -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -fPIC -fvisibility=hidden -g -lpthread -ldl -lstdc++ -lpam /AC/H/tools/googletests/lib/.libs/libgtest_main.0.dylib' ; \
linking /AC/H/tools/mtxtests/build/unix/macosx/debug/mtxtests for unix/macosx/debug
ld: warning: ignoring file /AC/H/tools/googletests/lib/.libs/libgtest_main.0.dylib, file was built for unsupported file format ( 0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (i386): /AC/H/tools/googletests/lib/.libs/libgtest_main.0.dylib
Undefined symbols for architecture i386:
  "testing::InitGoogleTest(int*, char**)", referenced from:
      _main in main.o
  "testing::AssertionResult::AssertionResult(testing::AssertionResult const&)", referenced from:
...
...
...
I get a whole bunch of Linker errors.

Can anyone help?
Id appreciate a response.

Kamlesh Mallick

unread,
May 10, 2013, 5:34:31 AM5/10/13
to googletes...@googlegroups.com
No worries guys - 
I added these flags in the cmake\internal_utils.cmake  file

set(CMAKE_C_FLAGS -m32) set(CMAKE_CXX_FLAGS -m32)

And i got a library compiled in 32 bit.

Now i can link to my main unix executable.


Thanx all for the replies!
Reply all
Reply to author
Forward
0 new messages