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

禁止链接 boost_python313失败 #6136

Closed
githubnotebooks opened this issue Jan 5, 2025 · 10 comments
Closed

禁止链接 boost_python313失败 #6136

githubnotebooks opened this issue Jan 5, 2025 · 10 comments
Labels

Comments

@githubnotebooks
Copy link

Xmake Version

2.9.7

Operating System Version and Architecture

archlinux

Describe Bug

添加 boost 库:

add_requires("boost", { configs = { system = false, all = false, shared = false, cmake = false, python=false } })

我这里令 python=false,也就是禁止链接 Boost.Python 库。
但显示执行过程的详细信息表明,它还是链接了 python 库:

[ 88%]: linking.debug test
/usr/bin/g++ -o build/linux/x86_64/debug/test build/.objs/test/linux/x86_64/debug/test/src/de.cpp.o build/.objs/test/linux/x86_64/debug/test/src/eg.cpp.o build/.objs/test/linux/x86_64/debug/test/src/main.cpp.o -m64 -Lbuild/linux/x86_64/debug -L/usr/lib -llib -lcommon -lboost_wave -lboost_url -lboost_type_erasure -lboost_timer -lboost_prg_exec_monitor -lboost_unit_test_framework -lboost_test_exec_monitor -lboost_stacktrace_noop -lboost_stacktrace_addr2line -lboost_stacktrace_basic -lboost_program_options -lboost_process -lboost_nowide -lboost_log -lboost_log_setup -lboost_locale -lboost_json -lboost_iostreams -lboost_graph_parallel -lboost_mpi -lboost_python313 -lboost_numpy313 -lboost_graph -lboost_wserialization -lboost_serialization -lboost_regex -lboost_random -lboost_fiber -lboost_filesystem -lboost_coroutine -lboost_contract -lboost_thread -lboost_date_time -lboost_exception -lboost_cobalt -lboost_context -lboost_container -lboost_chrono -lboost_system -lboost_charconv -lboost_atomic -lbz2 -lz -lpthread
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to `PyNumber_InPlaceRemainder'
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to `_Py_Dealloc'
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to `PyLong_FromLong'
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to `PyUnicode_AsUTF8String'
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to `PyUnicode_FromFormat'
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to `PyExc_ValueError'
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to `PyModule_Create2'
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to `PyNumber_And'
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to `PySlice_New'
....

它这里链接了 -lboost_python313,我在配置中禁止从系统找库,但它还是到 /usr/lib/ 下找到了 libboost_python313 这个库。然后这个库好像依赖于 python 虚拟机中的一些库,导致缺少一堆符号。

我在配置中给出的几个配置项基本都是不好使的。
system=false,结果还是从系统路径找库。
all=false,结果还是链接了一堆 boost库。
shared=false,结果还是链接了 so 文件。
python=false,结果还是链接了 boost_python313 这个库。

通过命令 xmake require --info boost 查看 boost 库的配置信息,有:

 -> configs:
         -> wave: Enable wave library. (default: false)
         -> url: Enable url library. (default: false)
         -> type_erasure: Enable type_erasure library. (default: false)
         -> timer: Enable timer library. (default: false)
         -> test: Enable test library. (default: false)
         -> stacktrace: Enable stacktrace library. (default: false)
         -> program_options: Enable program_options library. (default: false)
         -> process: Enable process library. (default: false)
         -> nowide: Enable nowide library. (default: false)
         -> log: Enable log library. (default: false)
         -> locale: Enable locale library. (default: false)
         -> json: Enable json library. (default: false)
         -> iostreams: Enable iostreams library. (default: false)
         -> graph_parallel: Enable graph_parallel library. (default: false)
         -> mpi: Enable mpi library. (default: false)
         -> python: Enable python library. (default: false)
         -> graph: Enable graph library. (default: false)

倒数第二行,明确说 add_requires 中 configs 子项目 python 用于控制是否链接 python 库,默认是 false,但默认还是链接 python 库,我手动给 false,结果还是链接 python 库。

Expected Behavior

add_requires("boost", { configs = { system = false, all = false, shared = false, cmake = false, python=false } })

我希望不要链接 boost_numpy313 这个库,我只使用 boost 中的部分子库,不需要链接全部,也希望上述几个配置项能起作用。

Project Configuration

add_requires("spdlog", "cli11")
add_requires("boost", { configs = { system = false, all = false, shared = false, cmake = false, python=false } })
add_packages("spdlog", "boost", "cli11")

Additional Information and Error Logs

[ 88%]: linking.debug test
/usr/bin/g++ -o build/linux/x86_64/debug/test build/.objs/test/linux/x86_64/debug/test/src/de.cpp.o build/.objs/test/linux/x86_64/debug/test/src/eg.cpp.o build/.objs/test/linux/x86_64/debug/test/src/main.cpp.o -m64 -Lbuild/linux/x86_64/debug -L/usr/lib -llib -lcommon -lboost_wave -lboost_url -lboost_type_erasure -lboost_timer -lboost_prg_exec_monitor -lboost_unit_test_framework -lboost_test_exec_monitor -lboost_stacktrace_noop -lboost_stacktrace_addr2line -lboost_stacktrace_basic -lboost_program_options -lboost_process -lboost_nowide -lboost_log -lboost_log_setup -lboost_locale -lboost_json -lboost_iostreams -lboost_graph_parallel -lboost_mpi -lboost_python313 -lboost_numpy313 -lboost_graph -lboost_wserialization -lboost_serialization -lboost_regex -lboost_random -lboost_fiber -lboost_filesystem -lboost_coroutine -lboost_contract -lboost_thread -lboost_date_time -lboost_exception -lboost_cobalt -lboost_context -lboost_container -lboost_chrono -lboost_system -lboost_charconv -lboost_atomic -lbz2 -lz -lpthread
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to PyNumber_InPlaceRemainder' /usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to _Py_Dealloc'
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to PyLong_FromLong' /usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to PyUnicode_AsUTF8String'
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to PyUnicode_FromFormat' /usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to PyExc_ValueError'
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to PyModule_Create2' /usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to PyNumber_And'
/usr/bin/ld: /usr/lib/libboost_python313.so: undefined reference to `PySlice_New'

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: Forbidden link boost_numpy313 failed

@githubnotebooks
Copy link
Author

再补充一些报错信息:

error: @programdir/core/main.lua:329: @programdir/actions/build/main.lua:148: @programdir/modules/async/runjobs.lua:325: @programdir/actions/build/kinds/binary.lua:53: @programdir/core/sandbox/modules/os.lua:378: execv(/usr/bin/g++ -o build/linux/x86_64/debug/clean build/.objs/clean/linux/x86_64/debug/tools/src/clean/src/main.cpp.o -m64 -Lbuild/linux/x86_64/debug -L/usr/lib -llib -lcommon -lboost_wave -lboost_url -lboost_type_erasure -lboost_timer -lboost_prg_exec_monitor -lboost_unit_test_framework -lboost_test_exec_monitor -lboost_stacktrace_noop -lboost_stacktrace_addr2line -lboost_stacktrace_basic -lboost_program_options -lboost_process -lboost_nowide -lboost_log -lboost_log_setup -lboost_locale -lboost_json -lboost_iostreams -lboost_graph_parallel -lboost_mpi -lboost_python313 -lboost_numpy313 -lboost_graph -lboost_wserialization -lboost_serialization -lboost_regex -lboost_random -lboost_fiber -lboost_filesystem -lboost_coroutine -lboost_contract -lboost_thread -lboost_date_time -lboost_exception -lboost_cobalt -lboost_context -lboost_container -lboost_chrono -lboost_system -lboost_charconv -lboost_atomic -lbz2 -lz -lpthread) failed(1)
stack traceback:
[C]: in function 'error'
[@programdir/core/base/os.lua:1004]:
[@programdir/core/sandbox/modules/os.lua:378]: in function 'execv'
[@programdir/modules/core/tools/gcc.lua:599]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:244]:
[@programdir/core/tool/linker.lua:232]: in function 'link'
[@programdir/actions/build/kinds/binary.lua:53]: in function 'callback'
[@programdir/modules/core/project/depend.lua:217]: in function 'on_changed'
[@programdir/actions/build/kinds/binary.lua:41]: in function '_do_link_target'
[@programdir/actions/build/kinds/binary.lua:83]:
[@programdir/actions/build/kinds/binary.lua:110]: in function '_link_target'
[@programdir/actions/build/kinds/binary.lua:138]: in function 'jobfunc'
[@programdir/modules/async/runjobs.lua:241]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:244]: in function 'trycall'
[@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
[@programdir/modules/async/runjobs.lua:224]: in function 'cotask'
[@programdir/core/base/scheduler.lua:406]:

stack traceback:
[C]: in function 'error'
@programdir/core/base/os.lua:1004: in function 'os.raiselevel'
(...tail calls...)
@programdir/core/main.lua:329: in upvalue 'cotask'
@programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>

@githubnotebooks githubnotebooks changed the title 禁止链接 boost_numpy313 失败 禁止链接 boost_python313失败 Jan 5, 2025
@waruqi waruqi transferred this issue from xmake-io/xmake Jan 5, 2025
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: Forbidden link boost_python313 failed

@star-hengxing
Copy link
Contributor

add_requires("boost", { configs = { system = false, all = false, shared = false, cmake = false, python=false } })

add_requires("boost", {
    system = false,
    configs = {
        shared = false,
        cmake = false,
}})

@githubnotebooks
Copy link
Author

add_requires("boost", { configs = { system = false, all = false, shared = false, cmake = false, python=false } })

add_requires("boost", {
    system = false,
    configs = {
        shared = false,
        cmake = false,
}})

这确实不需要使用 /usr/lib/ 目录下面的 boost 库了,但我发现要使用某个库也不行了。

add_requires("boost", { system=false, configs = {shared = false, cmake = false, filesystem = true}})

查询 xmake require --info boost 可知,本来 filesystem 默认就是 true,但链接的时候不会去查找这个库。我这里在 add_requires 中显式指定 filesystem = true,链接的时候依旧不会去查找这个库,导致链接错误:

/usr/bin/g++ -o build/linux/x86_64/debug/test build/.objs/test/linux/x86_64/debug/test/src/de.cpp.o build/.objs/test/linux/x86_64/debug/test/src/eg.cpp.o build/.objs/test/linux/x86_64/debug/test/src/main.cpp.o build/.objs/test/linux/x86_64/debug/test/src/builder.cpp.o -m64 -L/usr/lib -Lbuild/linux/x86_64/debug -llib -lcommon -lpthread
/usr/bin/ld: build/.objs/test/linux/x86_64/debug/test/src/builder.cpp.o: in function `boost::filesystem::exists(boost::filesystem::path const&)':
/usr/include/boost/filesystem/operations.hpp:181:(.text._ZN5boost10filesystem6existsERKNS0_4pathE[_ZN5boost10filesystem6existsERKNS0_4pathE]+0x2f): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/usr/bin/ld: build/.objs/test/linux/x86_64/debug/test/src/builder.cpp.o: in function `boost::filesystem::create_directory(boost::filesystem::path const&)':
/usr/include/boost/filesystem/operations.hpp:398:(.text._ZN5boost10filesystem16create_directoryERKNS0_4pathE[_ZN5boost10filesystem16create_directoryERKNS0_4pathE]+0x1e): undefined reference to `boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::filesystem::path const*, boost::system::error_code*)'
collect2: error: ld returned 1 exit status
create ok!
compile_commands.json updated!
error: @programdir/core/main.lua:329: @programdir/actions/build/main.lua:148: @programdir/modules/async/runjobs.lua:325: @programdir/actions/build/kinds/binary.lua:53: @programdir/core/sandbox/modules/os.lua:378: execv(/usr/bin/g++ -o build/linux/x86_64/debug/test build/.objs/test/linux/x86_64/debug/test/src/de.cpp.o build/.objs/test/linux/x86_64/debug/test/src/eg.cpp.o build/.objs/test/linux/x86_64/debug/test/src/main.cpp.o build/.objs/test/linux/x86_64/debug/test/src/builder.cpp.o -m64 -L/usr/lib -Lbuild/linux/x86_64/debug -llib -lcommon -lpthread) failed(1)
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:1004]:
    [@programdir/core/sandbox/modules/os.lua:378]: in function 'execv'
    [@programdir/modules/core/tools/gcc.lua:599]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:244]:
    [@programdir/core/tool/linker.lua:232]: in function 'link'
    [@programdir/actions/build/kinds/binary.lua:53]: in function 'callback'
    [@programdir/modules/core/project/depend.lua:217]: in function 'on_changed'
    [@programdir/actions/build/kinds/binary.lua:41]: in function '_do_link_target'
    [@programdir/actions/build/kinds/binary.lua:83]:
    [@programdir/actions/build/kinds/binary.lua:110]: in function '_link_target'
    [@programdir/actions/build/kinds/binary.lua:138]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:241]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:244]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/async/runjobs.lua:224]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:1004: in function 'os.raiselevel'
        (...tail calls...)
        @programdir/core/main.lua:329: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>

本来应该给出链接参数 -lboost_filesyst,但没有。

@star-hengxing
Copy link
Contributor

star-hengxing commented Jan 6, 2025

链接的时候依旧不会去查找这个库,导致链接错误

执行过 xmake f -c 清理缓存?然后有安装的过程么?

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


This library will still not be searched when linking, resulting in link errors.

Have you executed xmake f -c to clear the cache? Then there is the installation process

@githubnotebooks
Copy link
Author

执行 xmake f -c 之后依旧是不会给出 -lboost_filesyst 参数,所以导致链接出错。将 system = false 从 configs 中拿出来放到外面之后,第一次构建会下载 boost 库。但也只是下载,链接的时候依旧出错。

/usr/bin/g++ -o build/linux/x86_64/debug/test build/.objs/test/linux/x86_64/debug/test/src/de.cpp.o build/.objs/test/linux/x86_64/debug/test/src/named_param.cpp.o build/.objs/test/linux/x86_64/debug/test/src/eg.cpp.o build/.objs/test/linux/x86_64/debug/test/src/main.cpp.o build/.objs/test/linux/x86_64/debug/test/src/boost_so.cpp.o build/.objs/test/linux/x86_64/debug/test/src/builder.cpp.o -m64 -L/usr/lib -Lbuild/linux/x86_64/debug -llib -lcommon -lpthread
/usr/bin/ld: build/.objs/test/linux/x86_64/debug/test/src/boost_so.cpp.o: in function `boost::filesystem::exists(boost::filesystem::path const&)':
/usr/include/boost/filesystem/operations.hpp:181:(.text._ZN5boost10filesystem6existsERKNS0_4pathE[_ZN5boost10filesystem6existsERKNS0_4pathE]+0x2f): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
/usr/bin/ld: build/.objs/test/linux/x86_64/debug/test/src/boost_so.cpp.o: in function `boost::filesystem::create_directory(boost::filesystem::path const&)':
/usr/include/boost/filesystem/operations.hpp:398:(.text._ZN5boost10filesystem16create_directoryERKNS0_4pathE[_ZN5boost10filesystem16create_directoryERKNS0_4pathE]+0x1e): undefined reference to `boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::filesystem::path const*, boost::system::error_code*)'
collect2: error: ld returned 1 exit status

上述报错表明只链接了 -llib -lcommon -lpthread 这几个库,没有链接 boost_filesystem。我需要在 target 下面添加如下命令:

 add_links("boost_system", "boost_filesystem")

才能链接 boost 库。

我当前的构建脚本中的配置依旧是:

add_requires("boost", { system=false, configs = {shared = false, cmake = false, filesystem = true}})

自从把 system=false 从 configs 中拿到外面之后就一直没有变动。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


After executing xmake f -c, the -lboost_filesyst parameter is still not given, causing a link error. After taking system = false out of configs, the first build will download the boost library. But it's just downloading, and there's still an error when linking.

/usr/bin/g++ -o build/linux/x86_64/debug/test build/.objs/test/linux/x86_64/debug/test/src/de.cpp.o build/.objs/test/linux/x86_64/ debug/test/src/named_param.cpp.o build/.objs/test/linux/x86_64/debug/test/src/eg.cpp.o build/.objs/test/linux/x86_64/debug/test/src/main.cpp.o build/.objs/test /linux/x86_64/debug/test/src/boost_so.cpp.o build/.objs/test/linux/x86_64/debug/test/src/builder.cpp.o -m64 -L/usr/lib -Lbuild/linux/x86_64/debug -llib -lcommon -lpthread
/usr/bin/ld: build/.objs/test/linux/x86_64/debug/test/src/boost_so.cpp.o: in function `boost::filesystem::exists(boost::filesystem::path const&) ':
/usr/include/boost/filesystem/operations.hpp:181:(.text._ZN5boost10filesystem6existsERKNS0_4pathE[_ZN5boost10filesystem6existsERKNS0_4pathE]+0x2f): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const& , boost::system::error_code*)'
/usr/bin/ld: build/.objs/test/linux/x86_64/debug/test/src/boost_so.cpp.o: in function `boost::filesystem::create_directory(boost::filesystem::path const&) ':
/usr/include/boost/filesystem/operations.hpp:398:(.text._ZN5boost10filesystem16create_directoryERKNS0_4pathE[_ZN5boost10filesystem16create_directoryERKNS0_4pathE]+0x1e): undefined reference to `boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::filesystem::path const*, boost::system::error_code*)'
collect2: error: ld returned 1 exit status

The above error report indicates that only the libraries -llib -lcommon -lpthread are linked, and boost_filesystem is not linked. I need to add the following command under target:

 add_links("boost_system", "boost_filesystem")

To link the boost library.

The configuration in my current build script is still:

add_requires("boost", { system=false, configs = {shared = false, cmake = false, filesystem = true}})

It has been unchanged since taking system=false out of configs.

@star-hengxing
Copy link
Contributor

第一次构建会下载 boost 库。但也只是下载,链接的时候依旧出错。

安装没问题,那只能是你 xmake.lua 写错了,反正我这边无法复现。

add_requires("boost", {
    system = false,
    configs = {shared = false,
        cmake = false,
    }
})

target("test")
    set_kind("shared")
    add_files("src/main.cpp")
    add_packages("boost")
$ xmake f -c -v
...
checking for xmake::boost ... boost 1.87.0
{
  license = "BSL-1.0",
  libfiles = {
    "/home/star/.xmake/packages/b/boost/1.87.0/0ea5408c29014b249b186ec7a0b93264/lib/libboost_filesystem-mt.a",
    "/home/star/.xmake/packages/b/boost/1.87.0/0ea5408c29014b249b186ec7a0b93264/lib/libboost_system-mt.a",
    "/home/star/.xmake/packages/b/boost/1.87.0/0ea5408c29014b249b186ec7a0b93264/lib/libboost_atomic-mt.a"
  },
  static = true,
  links = {
    "boost_filesystem-mt",
    "boost_system-mt",
    "boost_atomic-mt"
  },
  version = "1.87.0",
  syslinks = {
    "pthread",
    "dl"
  },
  linkdirs = {
    "/home/star/.xmake/packages/b/boost/1.87.0/0ea5408c29014b249b186ec7a0b93264/lib"
  },
  sysincludedirs = {
    "/home/star/.xmake/packages/b/boost/1.87.0/0ea5408c29014b249b186ec7a0b93264/include"
  }
}
$ xmake -rv
[ 50%]: cache compiling.release src/main.cpp
/usr/bin/gcc -c -m64 -fPIC -isystem /home/star/.xmake/packages/b/boost/1.87.0/0ea5408c29014b249b186ec7a0b93264/include -isystem /home/star/.xmake/packages/b/bzip2/1.0.8/8db6bd46210f4711a452b7767b44748c/include -isystem /home/star/.xmake/packages/z/zlib/v1.3.1/994fafa590ed48ac9f71516cc846d155/include -o build/.objs/test/linux/x86_64/release/src/main.cpp.o src/main.cpp
[ 75%]: linking.release libtest.so
/usr/bin/g++ -o build/linux/x86_64/release/libtest.so build/.objs/test/linux/x86_64/release/src/main.cpp.o -shared -m64 -fPIC -L/home/star/.xmake/packages/b/boost/1.87.0/0ea5408c29014b249b186ec7a0b93264/lib -L/home/star/.xmake/packages/b/bzip2/1.0.8/8db6bd46210f4711a452b7767b44748c/lib -L/home/star/.xmake/packages/z/zlib/v1.3.1/994fafa590ed48ac9f71516cc846d155/lib -lboost_filesystem-mt -lboost_system-mt -lboost_atomic-mt -lbz2 -lz -lpthread -ldl

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