xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.5k stars 763 forks source link

Build error using shared link chain with add_package on Linux after install #5250

Open 19317362 opened 1 week ago

19317362 commented 1 week ago

Xmake 版本

2.9.2

操作系统版本和架构

ubuntu 22.04

描述问题

The same as Issue 4697

myapp => my yw_osal.so => my yw_log.so After added the code according issue 4697, it still gave me an error.

期待的结果

Can work like android and win.

工程配置

target("yw_osal")
    set_kind("shared")
    add_files("src/*.cpp")
    add_packages("yw_log",{public = true})
    -- add_rpathdirs("$(buildir)/lib")
    -- add_rpathdirs("@loader_path/lib")
    add_packages("asio",{public = true})
    add_includedirs("src")
    -- add the header files for installing
    add_headerfiles("src/*.h", {prefixdir = "yw_osal", public = true})
    if is_plat("windows") and is_kind("shared") then
        add_rules("utils.symbols.export_all", {export_classes = true})
    end
    on_load(function (target)
        if target:is_plat("linux") then
            for _, pkg in ipairs(target:orderpkgs()) do
                for _, linkdir in ipairs(pkg:get("linkdirs")) do
                    target:add("ldflags", "-Wl,-rpath-link=" .. linkdir, { public = true, force = true })
                end
            end            
        end
    end)  

附加信息和错误日志

the log of xmake f -vyD

[ 89%]: cache compiling.release src/x_time.cpp
/usr/bin/gcc -c -m64 -fPIC -std=c++11 -Isrc -isystem /home/wps/.xmake/packages/y/yw_log/20240507.161026/12d3a3f9ac2a41b7b2eb59a71faac791/include -isystem /home/wps/.xmake/packages/a/asio/1.30.2/c1047cd667c14a44bea718715a77a7f5/include -o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/x_time.cpp.o src/x_time.cpp
checking for g++ ... /usr/bin/g++
checking for the shared library linker (sh) ... g++
checking for /usr/bin/g++ ... ok
checking for flags (-fPIC) ... ok
> g++ "-fPIC" "-shared" "-m64" "-m64"
[ 94%]: linking.release libyw_osal.so
/usr/bin/g++ -o build_59af450e/linux/x86_64/release/libyw_osal.so build_59af450e/.objs/yw_osal/linux/x86_64/release/src/x_str_util.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/yw_util.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/_yw_osal_internal.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/yw_executor.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/_yw_executor_context.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/x_time_function.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/_yw_invokable_context.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/yw_invokable.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/yw_base.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/yw_semaphore.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/_yw_timer.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/yw_event.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/stdtostring.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/x_time.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/yw_proc_util.cpp.o build_59af450e/.objs/yw_osal/linux/x86_64/release/src/yw_android_stub.cpp.o -shared -m64 -fPIC -L/home/wps/.xmake/packages/y/yw_log/20240507.161026/12d3a3f9ac2a41b7b2eb59a71faac791/lib -lyw_log

build cache stats:
cache directory: build_59af450e/.build_cache
cache hit rate: 0%
cache hit: 0
cache hit total time: 0.000s
cache miss: 16
cache miss total time: 0.004s
new cached files: 16
remote cache hit: 0
remote new cached files: 0
preprocess failed: 0
compile fallback count: 0
compile total time: 6.845s

[100%]: build ok, spent 2.268s
/home/wps/.local/bin/xmake install -y --nopkgs -o /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200 --diagnosis --verbose --yes
installing yw_osal ..
installing yw_osal to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200 ..
> copy build_59af450e/linux/x86_64/release/libyw_osal.so to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/lib
> copy src/yw_android_stub.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_android_stub.h
> copy src/yw_executor.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_executor.h
> copy src/yw_functor.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_functor.h
> copy src/yw_concurrentqueue.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_concurrentqueue.h
> copy src/yw_semaphore.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_semaphore.h
> copy src/yw_tz.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_tz.h
> copy src/_yw_asio_switch.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/_yw_asio_switch.h
> copy src/yw_osal.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_osal.h
> copy src/x_time.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/x_time.h
> copy src/_yw_timer.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/_yw_timer.h
> copy src/_yw_base_context.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/_yw_base_context.h
> copy src/yw_base.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_base.h
> copy src/stdtostring.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/stdtostring.h
> copy src/yw_def.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_def.h
> copy src/yw_invokable.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_invokable.h
> copy src/_yw_osal_internal.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/_yw_osal_internal.h
> copy src/yw_boost_fix.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_boost_fix.h
> copy src/yw_proc_util.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_proc_util.h
> copy src/yw_mq.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_mq.h
> copy src/x_time_function.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/x_time_function.h
> copy src/yw_util.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_util.h
> copy src/yw_date.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_date.h
> copy src/_yw_executor_context.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/_yw_executor_context.h
> copy src/x_str_util.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/x_str_util.h
> copy src/yw_event.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_event.h
> copy src/yw_mq_msg.h to /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include/yw_osal/yw_mq_msg.h
install ok!
finding yw_osal from xmake ..
checking for xmake::yw_osal ... yw_osal 20240624.161814
{
  links = {
    "yw_osal"
  },
  shared = true,
  linkdirs = {
    "/home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/lib"
  },
  libfiles = {
    "/home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/lib/libyw_osal.so"
  },
  sysincludedirs = {
    "/home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include"
  },
  version = "20240624.161814"
}

patching /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/lib/pkgconfig/yw_osal.pc ..
checking for gcc ... /usr/bin/gcc
checking for the c++ compiler (cxx) ... gcc
checking for flags (-fPIC) ... ok
> gcc "-fPIC" "-m64"
> /usr/bin/gcc -c -m64 -isystem /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/include -o /tmp/.xmake1000/240624/_4842D53FA1B5492089CBFD1EF437FB20.o /tmp/.xmake1000/240624/_E610C6F5B2D74489ACC24013C0B7B057.cpp
checking for flags (-fdiagnostics-color=always) ... ok
> gcc "-fdiagnostics-color=always" "-m64"
> /usr/bin/g++ -o /tmp/.xmake1000/240624/_4842D53FA1B5492089CBFD1EF437FB20.b /tmp/.xmake1000/240624/_4842D53FA1B5492089CBFD1EF437FB20.o -m64 -L/home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/lib -lyw_osal
/usr/bin/ld: warning: libyw_log.so, needed by /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/lib/libyw_osal.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/lib/libyw_osal.so: undefined reference to `x_log_entry(YW_LOG_SEVERITY_LEVEL, char const*, int, char const*, ...)'
collect2: error: ld returned 1 exit status
> checking for c++ links(yw_osal)
> checking for c++ snippet(test)
checkinfo: ...gramdir/core/sandbox/modules/import/core/tool/linker.lua:75: @programdir/core/sandbox/modules/os.lua:378: execv(/usr/bin/g++ -o /tmp/.xmake1000/240624/_4842D53FA1B5492089CBFD1EF437FB20.b /tmp/.xmake1000/240624/_4842D53FA1B5492089CBFD1EF437FB20.o -m64 -L/home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/lib -lyw_osal) failed(1)
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]:
    [@programdir/core/sandbox/modules/os.lua:378]: in function 'execv'
    [@programdir/modules/core/tools/gcc.lua:580]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]:
    [@programdir/core/tool/linker.lua:221]: in function 'link'
    [...gramdir/core/sandbox/modules/import/core/tool/linker.lua:73]: in function 'link'
    [@programdir/modules/lib/detect/check_cxsnippets.lua:249]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/lib/detect/check_cxsnippets.lua:236]:
    [/mnt/d/work/cpp/yw-xmake-repo/packages/y/yw_osal/xmake.lua:55]: in function 'script'
    [...dir/modules/private/action/require/impl/utils/filter.lua:114]: in function 'call'
    [...dir/modules/private/action/require/impl/actions/test.lua:41]:
    [.../modules/private/action/require/impl/actions/install.lua:444]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [.../modules/private/action/require/impl/actions/install.lua:370]:
    [...modules/private/action/require/impl/install_packages.lua:489]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:238]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/async/runjobs.lua:220]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:406]:

error: /mnt/d/work/cpp/yw-xmake-repo/packages/y/yw_osal/xmake.lua:55: ...gramdir/core/sandbox/modules/import/core/tool/linker.lua:75: @programdir/core/sandbox/modules/os.lua:378: execv(/usr/bin/g++ -o /tmp/.xmake1000/240624/_4842D53FA1B5492089CBFD1EF437FB20.b /tmp/.xmake1000/240624/_4842D53FA1B5492089CBFD1EF437FB20.o -m64 -L/home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200/lib -lyw_osal) failed(1)
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]:
    [@programdir/core/sandbox/modules/os.lua:378]: in function 'execv'
    [@programdir/modules/core/tools/gcc.lua:580]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]:
    [@programdir/core/tool/linker.lua:221]: in function 'link'
    [...gramdir/core/sandbox/modules/import/core/tool/linker.lua:73]: in function 'link'
    [@programdir/modules/lib/detect/check_cxsnippets.lua:249]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/lib/detect/check_cxsnippets.lua:236]:
    [/mnt/d/work/cpp/yw-xmake-repo/packages/y/yw_osal/xmake.lua:55]: in function 'script'
    [...dir/modules/private/action/require/impl/utils/filter.lua:114]: in function 'call'
    [...dir/modules/private/action/require/impl/actions/test.lua:41]:
    [.../modules/private/action/require/impl/actions/install.lua:444]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [.../modules/private/action/require/impl/actions/install.lua:370]:
    [...modules/private/action/require/impl/install_packages.lua:489]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:238]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/async/runjobs.lua:220]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:406]:

  => install yw_osal 20240624.161814 .. failed
error: @programdir/core/main.lua:329: @programdir/modules/async/runjobs.lua:322: .../modules/private/action/require/impl/actions/install.lua:506: install failed!
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]:
    [.../modules/private/action/require/impl/actions/install.lua:506]: in function 'catch'
    [@programdir/core/sandbox/modules/try.lua:123]: in function 'try'
    [.../modules/private/action/require/impl/actions/install.lua:370]:
    [...modules/private/action/require/impl/install_packages.lua:489]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:238]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:973: in function 'base/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>

I've inspected the file yw_osal.pc .

cat /home/wps/.xmake/cache/packages/2406/y/yw_osal/20240624.161814/installdir.failed/lib/pkgconfig/yw_osal.pc
prefix=/home/wps/.xmake/packages/y/yw_osal/20240624.161814/59af450e91654a7a83ad97f004511200
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: yw_osal
Description: yw_osal for embeded linux and android
Version: 20240624.161814
Libs:  -L${libdir} -lyw_osal
Libs.private:
Cflags:  -I${includedir}

How to add link info to yw_osal.pc or just disable the checking?

19317362 commented 1 week ago

After comment the on_test function of the package yw_osal, it worked on linux and linux-arm-cross.

So, I think for this issue, the following things related.

  1. package code -- modify like 4697 to resolve.
  2. package test -- disable package test
    -- on_test(function (package)
    --     assert(package:check_cxxsnippets({test = [[
    --         #include <cstring>
    --         #include <vector>
    --         #include <yw_osal/x_str_util.h>
    --         static void test() {
    --             std::vector<std::string> v;
    --             std::string str{"the quick brown fox jumps over the lazy dog"};
    --             ::yw::osal::x_str_util::split_param( str, ' ', v);
    --         }
    --     ]]}, {configs = {}}))
    -- end)
waruqi commented 1 week ago

等后面有时间吧,暂时没空看这个,自己的包,可以先按你现在的方式搞。

Issues-translate-bot commented 1 week ago

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


Wait until you have time later. I don’t have time to read this at the moment. For your own package, you can do it the way you are doing now.