Why cant libgtest.a be moved to a different location?

426 Views Asked by At

Dear gtest/cmake experts: Is there a way to use the gtest archive libgtest.a from a location that is different from the location where it was created?

Here's my working case:

libgtest location: /usr/lib/x86_64-linux-gnu/libgtest.a and also in /usr/src/googletest/googletest/lib/libgtest.a

(I'm not sure why/how it is present in two locations. Its possible that I copy/pasted it long ago). The source code and CMakeLists etc for gtest are under /usr/src/googletest/

CMakeLists.txt:

< .. link other libraries, dependencies etc .. >
target_link_libraries(Application PRIVATE libgtest.a)

Note: Application is being built as a "shared object". libgtest.a is static. But this works fine.

Non-working case:

I copied libgtest.a to another location:

 /my/project/dir/depends/pkgs/libgtest.a

CMakeLists.txt:

< .. link other libraries, dependencies etc .. >
target_link_libraries(Application PRIVATE /my/project/dir/depends/pkgget/libgtest.a)

This throws a LOT of "relocation/ fPIC" related errors. For example:

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol testing::FLAGS_gtest_output[abi:cxx11]; recompile with -fPIC
>>> defined in ../../depends/lib/libgtest.a(gtest-all.cc.o)
>>> referenced by gtest-all.cc
>>>               gtest-all.cc.o:(testing::internal::UnitTestOptions::GetOutputFormat[abi:cxx11]()) in archive ../../depends/lib/libgtest.a

ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol testing::FLAGS_gtest_output[abi:cxx11]; recompile with -fPIC
>>> defined in ../../depends/lib/libgtest.a(gtest-all.cc.o)
>>> referenced by gtest-all.cc
>>>               gtest-all.cc.o:(testing::internal::UnitTestOptions::GetAbsolutePathToOutputFile[abi:cxx11]()) in archive ../../depends/lib/libgtest.a

Questions:

  1. How come there is no problem with relocation/ fPIC in the former case but there is a problem in the latter case? What gives?
  2. What's the correct way to use the pre-compiled archive from a different location?

I'm looking forward to your inputs.

Best regards,

--Venk

0

There are 0 best solutions below