在Mac上建立谷歌测试时,链接错误(命令行) [英] linking error when building Google test on mac (commandline)

查看:1227
本文介绍了在Mac上建立谷歌测试时,链接错误(命令行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在试图构建一个使用谷歌的C ++测试框架的一些测试code,但我不断收到一个错误,说明

I am currently trying to build some test code that uses Google C++ Test framework but I keep getting an error stating

LD:警告:在/usr/local/lib/libgtest.dylib,文件是专为不支持的文件格式,这是不被连接的体系结构(I386)

ld: warning: in /usr/local/lib/libgtest.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

我试图使问题尽可能简单:

I have tried to make the issue as simple as possible:

我有一个主要功能
cmtest.cc

I have a main function cmtest.cc

#include <gtest/gtest.h>

/** Main entry point */
int main(int argc, char**argv, char**envArg)
{
    testing::InitGoogleTest(&argc, argv);
    return(RUN_ALL_TESTS());
}

很基本的测试code
CrazyTest.cc

really basic test code CrazyTest.cc

#include <gtest/gtest.h>
TEST(CrazyTest, one) {
    EXPECT_EQ(2, 2);
}

我用下面的命令来建立GTEST和我的测试code。

I use the following commands to build gtest and my test code.

g++ -o CrazyTest.o -c -Wall -Werror=non-virtual-dtor -pipe -std=c++98 -fno-rtti -fno-exceptions -fno-strict-aliasing -Wno-deprecated -g -arch i386 -arch x86_64 -mmacosx-version-min=10.5.4 -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_HAS_RTTI=0 -I/opt/gtest-1.6.0/include CrazyTest.cc

g++ -o cmtest.o -c -Wall -Werror=non-virtual-dtor -pipe -std=c++98 -fno-rtti -fno-exceptions -fno-strict-aliasing -Wno-deprecated -g -arch i386 -arch x86_64 -mmacosx-version-min=10.5.4 -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_HAS_RTTI=0 -I/opt/gtest-1.6.0/include cmtest.cc

g++ -o gtest-all.o -c -Wall -Werror=non-virtual-dtor -pipe -std=c++98 -fno-rtti -fno-exceptions -fno-strict-aliasing -Wno-deprecated -g -arch i386 -arch x86_64 -mmacosx-version-min=10.5.4 -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_HAS_RTTI=0 -I/opt/gtest-1.6.0 -I/opt/gtest-1.6.0/include /opt/gtest-1.6.0/src/gtest-all.cc

ar rc libgtest.a gtest-all.o

ranlib libgtest.a

g++ -o cmtest -arch i386 -arch x86_64 -mmacosx-version-min=10.5.4 CrazyTest.o cmtest.o -lstdc++ -lgtest

最后生成步骤给我下面的错误,我无法找出原因。我能够得到实际的测试(未显示简单的一)建立在其他操作系统的MAC OS(豹)是给我的问题。

The final build step gives me the following error and I am unable to figure out why. I am able to get the actual tests (not the simple one shown) to build on other OSs the mac OS (leopard) is giving me problems.

 ld: warning: in /usr/local/lib/libgtest.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
Undefined symbols for architecture i386:
  "testing::Test::~Test()", referenced from:
      CrazyTest_one_Test::~CrazyTest_one_Test()in CrazyTest.o
      CrazyTest_one_Test::~CrazyTest_one_Test()in CrazyTest.o
  "testing::internal::AssertHelper::~AssertHelper()", referenced from:
      CrazyTest_one_Test::TestBody()      in CrazyTest.o
  "testing::Test::Test()", referenced from:
      CrazyTest_one_Test::CrazyTest_one_Test()in CrazyTest.o
  "testing::internal::GetTestTypeId()", referenced from:
      __static_initialization_and_destruction_0(int, int)in CrazyTest.o
  "testing::Test::TearDown()", referenced from:
      vtable for CrazyTest_one_Testin CrazyTest.o
  "testing::internal::EqFailure(char const*, char const*, testing::internal::String const&, testing::internal::String const&, bool)", referenced from:
      testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&)in CrazyTest.o
  "testing::UnitTest::GetInstance()", referenced from:
      _main in cmtest.o
  "testing::internal::IsTrue(bool)", referenced from:
      testing::internal::scoped_ptr<std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> > >::reset(std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >*)in CrazyTest.o
      testing::internal::scoped_ptr<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::reset(std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)in CrazyTest.o
  "testing::UnitTest::Run()", referenced from:
      _main in cmtest.o
  "testing::internal::AssertHelper::operator=(testing::Message const&) const", referenced from:
      CrazyTest_one_Test::TestBody()      in CrazyTest.o
  "testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)", referenced from:
      CrazyTest_one_Test::TestBody()      in CrazyTest.o
  "testing::AssertionSuccess()", referenced from:
      testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&)in CrazyTest.o
  "testing::Test::SetUp()", referenced from:
      vtable for CrazyTest_one_Testin CrazyTest.o
  "testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)", referenced from:
      __static_initialization_and_destruction_0(int, int)in CrazyTest.o
  "testing::InitGoogleTest(int*, char**)", referenced from:
      _main in cmtest.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
lipo: can't open input file: /var/tmp//ccZQiF8k.out (No such file or directory)

我已经定义-arch i386和x86_64的-arch的一切我已经建立,所以我无法弄清楚什么我已经错过了。我不这样做在Mac上大量的编程和这一具体问题有我卡住了。

I have defined -arch i386 and -arch x86_64 for everything I have built so I am unable to figure out what I have missed. I don't do a lot of programming on Macs and this particular issue has me stuck.

任何建议将是有益的。

推荐答案

解决方案中。事实证明,使用的构建指令是正确的问题是,当时正在执行的构建另一个开发者做了与谷歌测试框架1.5的一些工作,他们已经安装在编译器搜索路径在计算机上的库在计算机上。这导致了编译器找到其他图书馆第一,这不是使用多个架构选项编译。

Solution found. It turns out that the build instructions used are correct the issue was that on the computer that the build was being performed another developer had done some work with Google Test Framework 1.5 and they had installed the libraries on the computer in the compilers search path. This resulted in the compiler finding the other library first that was not compiled using multiple architecture options.

这篇关于在Mac上建立谷歌测试时,链接错误(命令行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆