googletest icon indicating copy to clipboard operation
googletest copied to clipboard

apple M1 chip Mac build failed because of */libgtest.a does not contain the arm64 architecture.

Open WalleLoveEva opened this issue 3 years ago • 7 comments

Describe the bug

Include a clear and concise description of what the problem is, including what you expected to happen, and what actually happened.

Showing All Issues Ignoring file /Users/walle.fu/.conan/data/googletest/1.8.1/mthor/stable/package/105876dec92f9a83153bf5fcecc0fc2571d7ba2f/lib/libgtest.a, file is universal (x86_64) but does not contain the arm64 architecture: /Users/walle.fu/.conan/data/googletest/1.8.1/mthor/stable/package/105876dec92f9a83153bf5fcecc0fc2571d7ba2f/lib/libgtest.a

Undefined symbol: testing::InitGoogleTest(int*, char**)

Undefined symbol: testing::AssertionResult::AssertionResult(testing::AssertionResult const&)

Undefined symbol: testing::AssertionFailure()

Undefined symbol: testing::AssertionSuccess()

Undefined symbol: testing::Test::Test()

Undefined symbol: testing::Test::~Test()

Undefined symbol: testing::Message::Message()

Undefined symbol: testing::UnitTest::GetInstance()

Undefined symbol: testing::UnitTest::AddEnvironment(testing::Environment*)

Undefined symbol: testing::UnitTest::Run()

Undefined symbol: testing::internal::CmpHelperEQ(char const*, char const*, long long, long long)

Undefined symbol: testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)

Undefined symbol: testing::internal::AssertHelper::~AssertHelper()

Undefined symbol: testing::internal::PrintStringTo(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, std::__1::basic_ostream<char, std::__1::char_traits >*)

Undefined symbol: testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void ()(), void ()(), testing::internal::TestFactoryBase*)

Undefined symbol: testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)

Undefined symbol: testing::internal::IsTrue(bool)

Undefined symbol: testing::internal::EqFailure(char const*, char const*, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, bool)

Undefined symbol: testing::internal2::PrintBytesInObjectTo(unsigned char const*, unsigned long, std::__1::basic_ostream<char, std::__1::char_traits >*)

Undefined symbol: testing::Message::GetString() const

Undefined symbol: testing::internal::AssertHelper::operator=(testing::Message const&) const

Undefined symbol: typeinfo for testing::Test

Steps to reproduce the bug

It's important that we are able to reproduce the problem that you are experiencing. Please provide all code and relevant steps to reproduce the problem, including your BUILD/CMakeLists.txt file and build commands. Links to a GitHub branch or godbolt.org that demonstrate the problem are also helpful.

Does the bug persist in the most recent commit?

We recommend using the latest commit in the master branch in your projects.

What operating system and version are you using? MAC pro 2021

If you are using a Linux distribution please include the name and version of the distribution as well.

What compiler and version are you using? Clang 13 Xcode 13.3.1

Please include the output of gcc -v or clang -v, or the equivalent for your compiler.

What build system are you using? Mac OS 12.3.1

Please include the output of bazel --version or cmake --version, or the equivalent for your build system.

Additional context

Add any other context about the problem here.

WalleLoveEva avatar Apr 22 '22 08:04 WalleLoveEva

Hello. The steps to reproduce the bug are missing. Please provide a sample program and all compile commands.

derekmauro avatar Apr 25 '22 19:04 derekmauro

@derekmauro

Test code:

example.test.cpp

#include <gtest/gtest.h>

TEST(YetAnotherSimpleGTest, ExpectGQ) {
    int actual = 1;
    EXPECT_GT(actual, 0);
    EXPECT_EQ(1, actual) << "Should be equal to one";
}

int main(int argc, char **argv) {
    testing::InitGoogleTest(&argc, argv);

    RUN_ALL_TESTS(); 
}

gtest version: 1.12.1

Command used to build tests: cmake -DCMAKE_CXX_FLAGS=-std=c++14 ..

Computer model: MacBook Pro M1 2021

Operative system version: Ventura 13.0

Xcode version: Xcode 14.0 Clang version: 14

Command used to run tests:

clang++ -Wall -std=c++14 example.test.cpp -o test && ./test

Error:

ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Full stack trace

Undefined symbols for architecture arm64:
  "testing::InitGoogleTest(int*, char**)", referenced from:
      _main in fibonacci-fce83f.o
  "testing::AssertionResult::AssertionResult(testing::AssertionResult const&)", referenced from:
      testing::AssertionResult testing::internal::CmpHelperOpFailure<int, int>(char const*, char const*, int const&, int const&, char const*) in fibonacci-fce83f.o
  "testing::AssertionFailure()", referenced from:
      testing::AssertionResult testing::internal::CmpHelperOpFailure<int, int>(char const*, char const*, int const&, int const&, char const*) in fibonacci-fce83f.o
  "testing::AssertionSuccess()", referenced from:
      testing::AssertionResult testing::internal::CmpHelperGT<int, int>(char const*, char const*, int const&, int const&) in fibonacci-fce83f.o
      testing::AssertionResult testing::internal::CmpHelperEQ<int, int>(char const*, char const*, int const&, int const&) in fibonacci-fce83f.o
  "testing::Test::SetUp()", referenced from:
      vtable for YetAnotherBrokenKeyboard_RecursiveFib_Test in fibonacci-fce83f.o
  "testing::Test::TearDown()", referenced from:
      vtable for YetAnotherBrokenKeyboard_RecursiveFib_Test in fibonacci-fce83f.o
  "testing::Test::Test()", referenced from:
      YetAnotherBrokenKeyboard_RecursiveFib_Test::YetAnotherBrokenKeyboard_RecursiveFib_Test() in fibonacci-fce83f.o
  "testing::Test::~Test()", referenced from:
      YetAnotherBrokenKeyboard_RecursiveFib_Test::~YetAnotherBrokenKeyboard_RecursiveFib_Test() in fibonacci-fce83f.o
  "testing::Message::Message()", referenced from:
      YetAnotherBrokenKeyboard_RecursiveFib_Test::TestBody() in fibonacci-fce83f.o
      testing::AssertionResult& testing::AssertionResult::operator<<<char [12]>(char const (&) [12]) in fibonacci-fce83f.o
      testing::AssertionResult& testing::AssertionResult::operator<<<char const*>(char const* const&) in fibonacci-fce83f.o
      testing::AssertionResult& testing::AssertionResult::operator<<<char [3]>(char const (&) [3]) in fibonacci-fce83f.o
      testing::AssertionResult& testing::AssertionResult::operator<<<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in fibonacci-fce83f.o
      testing::AssertionResult& testing::AssertionResult::operator<<<char [5]>(char const (&) [5]) in fibonacci-fce83f.o
  "testing::UnitTest::GetInstance()", referenced from:
      RUN_ALL_TESTS() in fibonacci-fce83f.o
  "testing::UnitTest::Run()", referenced from:
      RUN_ALL_TESTS() in fibonacci-fce83f.o
  "testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)", referenced from:
      YetAnotherBrokenKeyboard_RecursiveFib_Test::TestBody() in fibonacci-fce83f.o
  "testing::internal::AssertHelper::~AssertHelper()", referenced from:
      YetAnotherBrokenKeyboard_RecursiveFib_Test::TestBody() in fibonacci-fce83f.o
  "testing::internal::GetTestTypeId()", referenced from:
      ___cxx_global_var_init in fibonacci-fce83f.o
  "testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)", referenced from:
      ___cxx_global_var_init in fibonacci-fce83f.o
  "testing::internal::IsTrue(bool)", referenced from:
      testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int) in fibonacci-fce83f.o
      testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int) in fibonacci-fce83f.o
  "testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)", referenced from:
      testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int) in fibonacci-fce83f.o
      testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int) in fibonacci-fce83f.o
  "testing::internal::GTestLog::~GTestLog()", referenced from:
      testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int) in fibonacci-fce83f.o
      testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int) in fibonacci-fce83f.o
  "testing::internal::EqFailure(char const*, char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)", referenced from:
      testing::AssertionResult testing::internal::CmpHelperEQFailure<int, int>(char const*, char const*, int const&, int const&) in fibonacci-fce83f.o
      ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

lgemc avatar Aug 07 '22 20:08 lgemc

Hi I have encountered the same issue.

TheCloudlet avatar Oct 20 '22 12:10 TheCloudlet

Do you have any information how to resolve this issue?

lukaszMonte avatar Jul 18 '23 12:07 lukaszMonte

hi, is there any info on how to fix this issue? I have the same problem

Hongbin-Bao avatar Aug 06 '23 23:08 Hongbin-Bao

Can the "More Information Requested" label be removed please? The info has been provided now and I suspect this issue is not getting much traction as a result. I am also running into this issue and am hoping for a fix. Thanks! @derekmauro

tandronescu avatar Aug 22 '23 18:08 tandronescu

For those still struggling to circumvent this issue, I recommend building manually... it really looks like the packaged version brought by brew install(in my case) is x86_64 only:

$ ar -x /usr/local/lib/libgtest.a gtest-all.cc.o
$ file ./gtest-all.cc.o
./gtest-all.cc.o: Mach-O 64-bit object x86_64

So, I did this process:

# firstly, uninstall the previously installed version, through brew:
$ brew uninstall googletest

# then, clone and install it manually:

$ git clone https://github.com/google/googletest.git
$ cd googletest
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_OSX_ARCHITECTURES=arm64
$ make

# if you want to install the library system-wide:
$ sudo make install

# ... otherwise, you can point out your compiler to the build directories used above, e.g.:
$ g++ --std=c++17 example.test.cpp -o test -I/path/to/googletest/include -L/path/to/googletest/build/lib -lgtest -lgtest_main -pthread

HTH.

eetavares avatar May 12 '24 05:05 eetavares