Shared library linking error adding symbols: file in wrong format with gtest

  .so, c++, gcc, googletest

I have 2 cpp shared libraries & a cpp file. I want to link with those shared libraries.
For the first shared library I got success but for the second library got error. Details are given below:

Operating System: Ubuntu 20.04.2 LTS
Kernel: Linux 5.8.0-44-generic
Architecture: x86-64

gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
Target: x86_64-linux-gnu

libexample1.so file info:

$ file libexample1.so<br>
libexample1.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=f8b573bdeaa422c77bc8216056de5c9be264b766, not stripped

libexample2.so file info:

$ file libexample2.so<br>
libexample2.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, BuildID[sha1]=6faa5094ef527163520fde00f3d6b8528a6b30b2, with debug_info, not stripped

Creating object file of libraryTest.cpp:

$ gcc -c libraryTest.cpp -o libraryTest.o

libraryTest.o file info:

$ file libraryTest.o<br>
libraryTest.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped

Command for linking with libexample1.so: (got success in this case)

$ gcc -o runTest libraryTest.o -L. libexample1.so -lgtest -lgtest_main -pthread

Command for linking with libexample2.so: (got error in this case)

$ gcc -o runTest libraryTest.o -L. libexample2.so -lgtest -lgtest_main -pthread
/usr/bin/ld: libexample2.so: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status

libraryTest.cpp

#include <iostream>
#include <gtest/gtest.h>

using namespace std;

// TEST(TS1, TestCase1)
// {
//     int res = print_value(10);
//     EXPECT_EQ(20,res);
// }

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

Need expert’s help. Thanks in advance.

Source: Windows Questions C++

LEAVE A COMMENT