library linking problem in OSX 10.6.1

107 views
Skip to first unread message

Luke Dalessandro

unread,
Nov 3, 2009, 10:59:51 AM11/3/09
to Google C++ Testing Framework
Hi all, I've run into the following problem with gtest-svn.

I'm running on Max OS X and trying to use gtest in a cmake project. I
get the following error while building my test executable.

ld: warning: in /usr/local/lib/libgtest.dylib, file is not of required
architecture
Undefined symbols:
[blah]

The command line is:

/usr/bin/c++ -m32 -O2 -g -Wl,-search_paths_first -
headerpad_max_install_names -fPIC CMakeFiles/dummy_test.dir/
tests.cxx.o -o dummy_test ../../lib/urstm/libdummy.a /usr/local/lib/
libgtest.dylib

I'm using Apple's gcc-4.2.1:

luked$ c++ -v

Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5646~6/src/configure --disable-
checking --enable-werror --prefix=/usr --mandir=/share/man --enable-
languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/
$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --with-gxx-
include-dir=/include/c++/4.2.1 --program-prefix=i686-apple-darwin10- --
host=x86_64-apple-darwin10 --target=i686-apple-darwin10
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5646)

Googletest itself configures, builds, and installs without error. I
assume there's some sort of problem with the 32/64 bit libraries, but
am unsure what to do about it.

Thanks in advance,
Luke

Vlad Losev

unread,
Nov 3, 2009, 9:54:34 PM11/3/09
to Luke Dalessandro, Google C++ Testing Framework
Hi Luke,

It looks like you have a version of Google Test installed in your system in /usr/local. Can it be that that version is compiled by an older compiler? Try running 'sudo make uninstall' from your Google Test build directory, then rebuild Google Test and invoke 'make install' again. Then try to rebuild your own project.

Let us know if this helps!

Regards,
Vlad

Luke Dalessandro

unread,
Nov 4, 2009, 9:43:00 AM11/4/09
to Google C++ Testing Framework
Hi Vlad,

On Nov 3, 9:54 pm, Vlad Losev <vl...@google.com> wrote:
> Hi Luke,
>
> It looks like you have a version of Google Test installed in your system in
> /usr/local. Can it be that that version is compiled by an older compiler?
> Try running 'sudo make uninstall' from your Google Test build directory,
> then rebuild Google Test and invoke 'make install' again. Then try to
> rebuild your own project.

OK, this doesn't help. I've figured out what the problem is, and have
a workaround, though I don't know what the actual fix is. The default
gtest configuration builds a 64 bit library:

luked$ file libgtest.0.dylib
libgtest.0.dylib: Mach-O 64-bit dynamically linked shared library
x86_64

I'm trying to build a 32 bit binary with -m32, hence the error about
"not the required architecture." The workaround I used is to configure
with:

luked$ CC='gcc -m32' CXX='g++ -m32' ./configure

This builds a 32 bit library:

luked$ file libgtest.0.dylib
libgtest.0.dylib: Mach-O dynamically linked shared library i386

I don't enough about the Mac system architecture to suggest a way to
build both 32 and 64 bit versions of the library so that this error
doesn't occur.

I filed an issue with the workaround included.

Luke

>
> Let us know if this helps!
>
> Regards,
> Vlad
>

Preston Jackson

unread,
Nov 9, 2009, 6:26:38 PM11/9/09
to Luke Dalessandro, Google C++ Testing Framework
Hi Luke,

Creating mixed architecture libraries via "make" is difficult. It involves building the application multiple times in separate directories, then calling the "lipo" command to put things together. We provide an Xcode project (accessible via the command-line with "xcodebuild"), to make 4-way universal binaries. The README has a good explanation about how to use the xcode project via the terminal.


Preston

Vlad Losev

unread,
Nov 9, 2009, 10:28:57 PM11/9/09
to Preston Jackson, Luke Dalessandro, Google C++ Testing Framework, Chandler Carruth
Hi Luke,

If you want to build on multiple architectures you can also consider using SCons. You will need to modify the scons/SConstruct file to add a an environment with 64-bit flags for each platform you can build on.
Regards,
Vlad
Reply all
Reply to author
Forward
0 new messages