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

GH-40577: [C++] Ensure pkg-config flags include -ldl for static builds #40578

Merged
merged 2 commits into from
Mar 16, 2024

Conversation

bkietz
Copy link
Member

@bkietz bkietz commented Mar 15, 2024

Rationale for this change

When linking statically, pkg-config doesn't pick up the new dependency on libdl introduced by #39067

This produces unresolved symbol errors

What changes are included in this PR?

Addition of -ldl to ARROW_PC_LIBS_PRIVATE to ensure linkage to the necessary library

Are these changes tested?

yes

Are there any user-facing changes?

no

@bkietz bkietz requested review from kou and felipecrv March 15, 2024 15:02
@bkietz bkietz self-assigned this Mar 15, 2024
Copy link

⚠️ GitHub issue #40577 has no components, please add labels for components.

@@ -968,6 +968,8 @@ if(NOT ARROW_BUILD_SHARED AND ARROW_BUILD_STATIC)

string(APPEND ARROW_TESTING_PC_CFLAGS "${ARROW_TESTING_PC_CFLAGS_PRIVATE}")
set(ARROW_TESTING_PC_CFLAGS_PRIVATE "")

string(APPEND ARROW_PC_LIBS_PRIVATE " -l${CMAKE_DL_LIBS}")
Copy link
Member

@kou kou Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we put this to this block, this flag isn't used when -DARROW_BUILD_SHARED=ON -DARROW_BUILD_STATIC=ON is used. Does this work?

diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt
index c5449d9956..4329d66821 100644
--- a/cpp/src/arrow/CMakeLists.txt
+++ b/cpp/src/arrow/CMakeLists.txt
@@ -140,9 +140,10 @@ if(ARROW_ENABLE_THREADING)
   list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS Threads::Threads)
 endif()
 
-if(NOT MSVC_TOOLCHAIN)
+if(CMAKE_DL_LIBS)
   list(APPEND ARROW_SHARED_INSTALL_INTERFACE_LIBS ${CMAKE_DL_LIBS})
   list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS ${CMAKE_DL_LIBS})
+  string(APPEND ARROW_PC_LIBS_PRIVATE " -l${CMAKE_DL_LIBS}")
 endif()
 
 set(ARROW_TEST_LINK_TOOLCHAIN ${ARROW_GTEST_GMOCK} ${ARROW_GTEST_GTEST_MAIN})

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems reasonable. Out of curiosity, what's the utility of building both shared and static and libraries?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we build Apache Arrow C++ for single propose (e.g. creating a PyArrow wheel), we don't need to build shared and static libraries. But if we want to use multiple proposes (e.g. using it from Python and R), we may need shared and static libraries.

Most packaging systems (deb, rpm and so on) provide both of shared and static libraries to support multiple proposes. If Apache Arrow C++ supports building both shared and static library, they don't need to build Apache Arrow C++ twice to build shared and static libraries.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Apache Arrow C++ supports building both shared and static library, they don't need to build Apache Arrow C++ twice

I think you'd only be able to reuse the object files, which should be doable by having adjacent build directories both using ccache. We can't even reuse object files on WIN32 because we add -DARROW_STATIC there and so the object files linked into arrow_static are different from those linked into arrow_shared.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a packager view, reusability of object files isn't so important. Composing shared/static libraries to one package family (libarrow15 and libarrow-dev for .deb) is important. Building twice for shared and static libraries isn't easy to compose...

For example:

  • Both of cmake --install for shared library and cmake --install for static library install not only library files but also header files, data files and so on. Most of header files will be same but some files may be different. In our case, arrow/util/config.h may be different if we have some #cmakedefines that depend on library type. If there are different files, package for shared library and package for static library will be conflicted.
  • CMake packages for shared library and static library are different. We need to use different CMake package names (e.g. ArrowShared for shared library and ArrowStatic for static library) to avoid conflicting them.
  • ...

GoogleTest is a product that doesn't support building both of shared and static libraries at once.
MSYS2 package of it building GoogleTest twice:

The package provides only CMake package for shared library: https://github.com/msys2/MINGW-packages/blob/ad99b751d11d027345f6da4c91b4c33d5ad1ac7d/mingw-w64-gtest/PKGBUILD#L70-L71
It means that users can't use static library version via its CMake package.

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels Mar 15, 2024
@github-actions github-actions bot added awaiting change review Awaiting change review awaiting changes Awaiting changes and removed awaiting changes Awaiting changes awaiting change review Awaiting change review labels Mar 15, 2024
@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting changes Awaiting changes labels Mar 15, 2024
Copy link
Member

@assignUser assignUser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should really at some point move a way from the multiple list with dozens of targets or other lists in them ^_^ but that's of course a topic for some other time.

@assignUser
Copy link
Member

@github-actions crossbow submit example-cpp-minimal-build-static*

Copy link

Revision: 00c4b06

Submitted crossbow builds: ursacomputing/crossbow @ actions-fa21affe42

Task Status
example-cpp-minimal-build-static GitHub Actions
example-cpp-minimal-build-static-system-dependency GitHub Actions

@bkietz bkietz merged commit 2224a29 into apache:main Mar 16, 2024
39 checks passed
@bkietz bkietz removed the awaiting merge Awaiting merge label Mar 16, 2024
@bkietz bkietz deleted the 40577-pkg-config-libdl branch March 16, 2024 01:20
@github-actions github-actions bot added the awaiting changes Awaiting changes label Mar 16, 2024
Copy link

After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit 2224a29.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 67 possible false positives for unstable benchmarks that are known to sometimes produce them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants