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

Fail to use system boost with undefined reference in libboost_python #6398

Open
Doekin opened this issue Feb 20, 2025 · 7 comments
Open

Fail to use system boost with undefined reference in libboost_python #6398

Doekin opened this issue Feb 20, 2025 · 7 comments
Labels

Comments

@Doekin
Copy link
Contributor

Doekin commented Feb 20, 2025

Xmake Version

xmake v2.9.8+20250204

Operating System Version and Architecture

Arch Linux

Describe Bug

When using the system-installed boost, which includes various modules such as libboost_python, attempting to link libboost_python without explicitly adding -lpython results in linker errors (undefined references).

Expected Behavior

If libboost_python is detected in the system, perhaps it could also link against python to avoid the issue.

Project Configuration

xrepo install boostdep

Additional Information and Error Logs

N/A

@Doekin Doekin added the bug label Feb 20, 2025
@waruqi
Copy link
Member

waruqi commented Feb 20, 2025

you can add python library dep in boost package when boost/python is enabled.

@Doekin
Copy link
Contributor Author

Doekin commented Feb 20, 2025

I tried adding the following to on_load:

if package:config("python") then
    package:add("deps", "python")
end

However, it didn’t work. This might be because config("python") is disabled by default, and the system boost is detected during the on_fetch step.

@star-hengxing
Copy link
Contributor

Can we add deps in on_fetch?

function _get_python_libs()
local opt = {version = true}
local result = find_tool("python3", opt)
if not result then
result = find_tool("python", opt)
end
local libs = {}
local version = result and result.version
if version then
local py_ver = semver.new(version)
py_ver = py_ver:major() .. py_ver:minor()
table.insert(libs, "python" .. py_ver)
table.insert(libs, "numpy" .. py_ver)
end
return libs
end

@waruqi
Copy link
Member

waruqi commented Feb 20, 2025

Can we add deps in on_fetch?

no, we should use add_deps to add python, boost still can fetch system libs.

@star-hengxing
Copy link
Contributor

I thought that xrepo does not execute on_load after executing on_fetch, so these code should work.

if package:config("python") then
if not package:config("shared") then
package:add("defines", "BOOST_PYTHON_STATIC_LIB")
end
package:add("deps", "python " .. package:config("pyver") .. ".x", {configs = {headeronly = true}})
end

if package:config("python") then
package:add("deps", "python", {configs = {headeronly = true}})
end

add_requires("boost[python]") work for me.

[ 50%]: cache compiling.release src/main.cpp
/usr/bin/gcc -c -m64 -fPIC -isystem /usr/include/python3.10 -isystem /home/star/.xmake/packages/o/openssl/1.1.1-w/6c51ab6278e2479b883dffafac69fdaf/include -o build/.objs/hello/linux/x86_64/release/src/main.cpp.o src/main.cpp
[ 75%]: linking.release libhello.so
/usr/bin/g++ -o build/linux/x86_64/release/libhello.so build/.objs/hello/linux/x86_64/release/src/main.cpp.o -shared -m64 -fPIC -L/usr/lib/x86_64-linux-gnu -L/home/star/.xmake/packages/o/openssl/1.1.1-w/6c51ab6278e2479b883dffafac69fdaf/lib -lboost_wave -lboost_type_erasure -lboost_timer -lboost_prg_exec_monitor -lboost_unit_test_framework -lboost_test_exec_monitor -lboost_stacktrace_noop -lboost_stacktrace_backtrace -lboost_stacktrace_addr2line -lboost_stacktrace_basic -lboost_program_options -lboost_nowide -lboost_log -lboost_log_setup -lboost_locale -lboost_iostreams -lboost_graph_parallel -lboost_mpi -lboost_python310 -lboost_numpy310 -lboost_graph -lboost_wserialization -lboost_serialization -lboost_regex -lboost_random -lboost_fiber -lboost_filesystem -lboost_coroutine -lboost_thread -lboost_date_time -lboost_exception -lboost_context -lboost_container -lboost_chrono -lboost_system -lboost_atomic -lssl -lcrypto -lpthread -ldl

@Doekin
Copy link
Contributor Author

Doekin commented Feb 28, 2025

Thank you for the insights! Your solution works well in regular projects.

The issue arises when trying to install a package that depends on boost. When using the system boost, the installation fails due to undefined reference errors.

While modifying the package recipe is one workaround, I’m curious if there might be another approach to resolve this without altering the recipes.

@star-hengxing
Copy link
Contributor

Require xmake to support using package:add("deps", "xxx") within on_fetch.

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

No branches or pull requests

3 participants