Skip to content
Open
1 change: 1 addition & 0 deletions libs/core/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set(config_macro_headers
hpx/config/forward.hpp
hpx/config/manual_profiling.hpp
hpx/config/move.hpp
hpx/config/static_linker_check.hpp
hpx/config/threads_stack.hpp
hpx/config/warnings_prefix.hpp
hpx/config/warnings_suffix.hpp
Expand Down
42 changes: 42 additions & 0 deletions libs/core/config/include/hpx/config/static_linker_check.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2026 The STE||AR-Group
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

// hpxinspect:linelength
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we still need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @hkaiser

Yes, we still need it. I kept the suppression because the #warning diagnostic message explaining how to fix the linker issue (using HPX::wrap_main or -Wl,--wrap=main) is longer than 80 characters.

I wanted the message to be as clear and actionable as possible for the user, which unfortunately makes it fail the inspect tool's line-length check. If you’d prefer, I can try to break the warning across multiple lines, but the suppression was the cleanest way to keep the message readable in the compiler output.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But you have split the line using \ continuation characters. I don't think inspect will concatenate the split line to check whether its longer than allowed. This comment should not be necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That’s a fair point. I was under the impression that the tool might evaluate the logical line length, but if it only checks physical line length, then you're right,the line continuations already solve the problem.

I’ll remove the hpxinspect:linelength suppression and push the change now. If the CI 'inspect' tool still flags it for some reason, I'll know for sure, but it's better to keep the code clean of unnecessary suppressions. Thanks for the correction!

#pragma once

#include <hpx/config/defines.hpp>

// Emit a compile-time diagnostic when the user includes hpx/hpx_main.hpp
// while building a statically-linked HPX application on Linux or macOS.
//
// Root cause: the '--wrap=main' linker flag, which redirects user 'main' to
// the HPX runtime entry-point, is only applied automatically when the user
// links against 'HPX::wrap_main'. Without it, the resulting binary will call
// the raw 'main' symbol, bypassing HPX initialisation and producing a
// hard-to-diagnose runtime crash or silent hang.
//
// Actionable remedies (pick one):
// CMake -- add target_link_libraries(<target> PRIVATE HPX::wrap_main)
// Manual -- pass -Wl,--wrap=main to the linker explicitly
//
// This check is intentionally limited to Linux/macOS static builds because:
// * On Windows the wrap mechanism is not used (MSVC uses a different ABI).
// * Dynamic (shared-library) builds already embed the wrap stub inside
// libhpx.so/dylib, so no extra linker flag is needed.

#if defined(HPX_HAVE_DYNAMIC_HPX_MAIN)
#if (defined(__linux) || defined(__linux__) || defined(linux) || \
defined(__APPLE__)) && \
defined(HPX_HAVE_STATIC_LINKING) && \
!defined(HPX_HAVE_WRAP_MAIN_CONFIGURED)
#warning \
"HPX static-link wrap-main check: you included hpx/hpx_main.hpp but the " \
"--wrap=main linker flag has not been applied. Add " \
"target_link_libraries(<target> PRIVATE HPX::wrap_main) to your " \
"CMakeLists.txt, or pass -Wl,--wrap=main to the linker manually. " \
"Without this flag the HPX runtime will not be initialised correctly."
#endif
#endif
4 changes: 4 additions & 0 deletions wrap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ endif()
if(HPX_WITH_DYNAMIC_HPX_MAIN)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
target_link_libraries(hpx_wrap INTERFACE "-Wl,-wrap=main")
target_compile_definitions(hpx_wrap INTERFACE HPX_HAVE_WRAP_MAIN_CONFIGURED)
target_link_libraries(hpx_auto_wrap INTERFACE "-Wl,-wrap=main")
target_compile_definitions(
hpx_auto_wrap INTERFACE HPX_HAVE_WRAP_MAIN_CONFIGURED
)
elseif(APPLE)
target_link_libraries(hpx_wrap INTERFACE "-Wl,-e,_initialize_main")
target_link_libraries(hpx_auto_wrap INTERFACE "-Wl,-e,_initialize_main")
Expand Down
1 change: 1 addition & 0 deletions wrap/include/hpx/hpx_main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include <hpx/config/static_linker_check.hpp>
#include <hpx/wrap_main.hpp>

#if defined(HPX_HAVE_RUN_MAIN_EVERYWHERE)
Expand Down
Loading