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

add_rpathdirs对shared库不生效 #208

Closed
fasiondog opened this Issue Aug 31, 2018 · 9 comments

Comments

Projects
None yet
2 participants
@fasiondog
Copy link

commented Aug 31, 2018

在linux下,如果target是动态库时(set_kind("shared")),add_rpathdirs以及add_ldflags都没有办法在链接时加入相应的参数。但是binary正常。

@fasiondog

This comment has been minimized.

Copy link
Author

commented Aug 31, 2018

xmake version 2.2.1

@waruqi

This comment has been minimized.

Copy link
Member

commented Aug 31, 2018

如果是shared动态库target,通过add_deps添加的时候,就会自动继承和添加对应的rpath设置,一般不必自己手动添加rpath,例如:

target("test")
    set_kind("shared")
    add_files("src/interface.c") 

target("demo")
    set_kind("binary")
    add_deps("test")   
    add_files("src/test.c") 

上述例子,demo程序通过add_deps可自动添加rpath,加载test动态库。

g++ -o build/release/x86_64/test_demo build/.objs/test_demo/release/x86_64/src/test.c.o -Lbuild/release/x86_64 -Wl,-rpath=$ORIGIN -s -fvisibility=hidden -ltest -m64 -L/usr/local/lib -L/usr/lib

你可以通过$xmake create -t shared test 创建一个动态库工程测试下。。

另外即时自带的rpath设置,不满足需求,通过add_rpathdirs添加其他路径也是ok,我这边测试可以:

target("test")
    set_kind("shared")
    add_files("src/interface.c") 

target("demo")
    set_kind("binary")
    add_deps("test")
    add_rpathdirs("/tmp")   
    add_files("src/test.c") 

我这边测试linux是生效的:

g++ -o build/release/x86_64/test_demo build/.objs/test_demo/release/x86_64/src/test.c.o -Lbuild/release/x86_64 -Wl,-rpath=$ORIGIN -Wl,-rpath=/tmp/ -s -fvisibility=hidden -ltest -m64 -L/usr/local/lib -L/usr/lib

如果要通过add_ldflags设置,由于有自动检测,可能检测失败没通过,可以通过force参数强制设置:

add_ldflags("-Wl,-rpath=/tmp", {force = true})
@fasiondog

This comment has been minimized.

Copy link
Author

commented Aug 31, 2018

我是shared A 依赖 shared B。 如果是 exe 依赖 A 没问题,但是 A 找不到 B。我用 -v 查看过,A 的链接命令里没有 " -Wl, rpath”

@fasiondog

This comment has been minimized.

Copy link
Author

commented Aug 31, 2018

target("testB")
set_kind("shared")
add_files("src/interface.c")

target("testA")
set_kind("shared")
add_files("src/interface.c")
add_rpathdirs("@LoadPath") ro add_ldflags --这里链接testA时,-v 显示没有被加入链接命令

target("demo")
set_kind("binary")
add_deps("testA")
add_rpathdirs("/tmp")
add_files("src/test.c")

@fasiondog

This comment has been minimized.

Copy link
Author

commented Aug 31, 2018

漏写了, testA里 add_deps(testB)

@waruqi

This comment has been minimized.

Copy link
Member

commented Aug 31, 2018

对于 shared 依赖 shared的情况,目前确实没做自动rpath的自动继承,并且add_rpathdirs的设置也没对shared做支持,仅支持对binary的链接设置,这个我后两天有时间改进下。

目前你可以先通过 add_shflags("-Wl, -rpath=/tmp", {force = true})来设置,动态库的链接flags是add_shflags接口,而不是add_ldflags,这个是用于可执行程序的link。

可以看下相关文档说明:https://xmake.io/#/zh/manual?id=targetadd_shflags

等我后两天改进好,你再试试通过add_rpathdirs来对shared target的设置

@fasiondog

This comment has been minimized.

Copy link
Author

commented Aug 31, 2018

试了下“add_shflags”,可以了。3Q much

@waruqi

This comment has been minimized.

Copy link
Member

commented Sep 4, 2018

对于shared依赖shared target的情况,目前dev分支版本已经支持自动追加rpath了,并且add_rpathdirs对shared设置也可以生效了。。你可以试试 验证下,目前可以暂时还是通过add_shflags方式来设置。

等下个版本发布,可以切换过去,并且设置 set_xmakever("2.2.2") xmake最小版本提示就好。

@fasiondog

This comment has been minimized.

Copy link
Author

commented Sep 14, 2018

测试通过

@fasiondog fasiondog closed this Sep 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.