Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fails to link against gtest in shared mode #19

Closed
starius opened this issue May 3, 2016 · 2 comments
Closed

fails to link against gtest in shared mode #19

starius opened this issue May 3, 2016 · 2 comments

Comments

@starius
Copy link
Contributor

starius commented May 3, 2016

I build hyperscan in shared mode:

$ cmake ../hyperscan-4.1.0 -DBUILD_SHARED_LIBS=ON
$ make

It fails to build bin/unit-hyperscan because of linking errors:

allocators.cpp:41: undefined reference to `testing::Message::Message()'
allocators.cpp:41: undefined reference to `testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)'
allocators.cpp:41: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
allocators.cpp:41: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
allocators.cpp:41: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
... and so on

It is caused by the fact that symbols in libgtest.so are local:

$ nm --demangle lib/libgtest.so | grep IsTrue
000000000000a810 t testing::internal::IsTrue(bool)

It should be T instead of t there.

This problem seems to be caused by using -fvisibility=hidden compiler option when compiling gtest.

The following patch fixes the problem for me:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b4d8175..b53fbdd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -220,7 +220,7 @@ CHECK_FUNCTION_EXISTS(_aligned_malloc HAVE__ALIGNED_MALLOC)
 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAS_C_HIDDEN)
 CHECK_CXX_COMPILER_FLAG(-fvisibility=hidden HAS_CXX_HIDDEN)

-if (RELEASE_BUILD)
+if (RELEASE_BUILD AND NOT BUILD_STATIC_AND_SHARED AND NOT BUILD_SHARED_LIBS)
     if (HAS_C_HIDDEN)
         set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -fvisibility=hidden")
     endif()

You may want to make more precise patch, which disables -fvisibility=hidden for gtest only, because other parts seem to work well with it.

starius added a commit to starius/luahs that referenced this issue May 3, 2016
@mdb256
Copy link

mdb256 commented May 4, 2016

Thanks for this.

As it happens, we've already pushed commit 3dc8bab that solves this issue in a different way, except it is still on the develop branch. We expect to merge this to master quite soon.

However we probably should rework our use of -fvisibility=hidden so that it is only applied to the Hyperscan shared libs.

@mdb256
Copy link

mdb256 commented Jun 1, 2016

Commit 3dc8bab is now on master in release 4.2.0

@mdb256 mdb256 closed this as completed Jun 1, 2016
starius added a commit to LuaAndC/mxe that referenced this issue Jun 5, 2016
Some patches are not needed anymore:

 * "add Libs.private to fix linking errors" was fixed in
   intel/hyperscan#18
 * "fix linking against gtest in shared mode" and
   "fix linking errors in shared mode" were fixed in
   intel/hyperscan#19
 * "install .dll to bin/, not to lib/"
   intel/hyperscan#21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants