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

动态库依赖 abseil 时,链接报错提示 abseil 非 -fPIC 编译,即使加上选项 #5816

Closed
vrecluse opened this issue Nov 13, 2024 · 5 comments
Labels
Milestone

Comments

@vrecluse
Copy link

Xmake 版本

2.9.6

操作系统版本和架构

Ubuntu 23.04

描述问题

如题,手动加上 cxflags -fPIC 和 requires 里 configs 设置都不行

期待的结果

成功链接

工程配置

add_rules("mode.debug", "mode.release")

add_cxflags("-fPIC")
add_requires("abseil", {configs = {pic = true}})
add_requires("spdlog")

target("mylib")
set_kind("shared")
set_languages("c++20")
add_packages("abseil", "spdlog")
add_files("./src/*.cpp")
set_toolchains("clang")

附加信息和错误日志

error: mold: error: /home/xavier/.xmake/packages/a/abseil/20240722.0/e068e8bd8b7e42199d4d8762b92b8f9a/lib/libabsl_hash.a(hash.cc.o):(.text): R_X86_64_PC32 relocation at offset 0x110 against symbol `absl::lts_20240722::hash_internal::MixingHashState::kSeed' can not be used; recompile with -fPIC
@vrecluse vrecluse added the bug label Nov 13, 2024
@Issues-translate-bot
Copy link

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


Title: When the dynamic library depends on abseil, the link error prompts that abseil is not compiled with -fPIC, even if the option is added

@star-hengxing
Copy link
Contributor

pic 默认开启的,会传给 cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON。如果是交叉编译,那应该和这个一样 #5814


项目 xmake.lua 各种操作都不会影响 package 的构建,额外操作都在 add_requires 控制。

add_requires("abseil", {configs = {cxflags = "-fPIC"}})

@Issues-translate-bot
Copy link

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


Pic is enabled by default and will be passed to cmake -DCMAKE_POSITION_INDEPENDENT_CODE=ON. If it is cross-compiled, it should be the same as this #5814.


Various operations of the project xmake.lua will not affect the construction of the package, and additional operations are controlled by add_requires.

add_requires("abseil", {configs = {cxflags = "-fPIC"}})

@waruqi
Copy link
Member

waruqi commented Nov 13, 2024

目前 交叉编译对 cmake 包,默认没处理 pic ,就只对处理 linux/bsd 处理了。主要是之前我不确定所有交叉编译工具链是否都支持 pic

我先暂时放开了,让 cmake 自己去处理好了。

试下这个 patch #5817

@Issues-translate-bot
Copy link

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


Currently, cross-compilation does not process pic by default for the cmake package, but only processes linux/bsd. Mainly because I was not sure whether all cross-compilation tool chains support pic before

I let go temporarily and let cmake handle it by itself.

#5817

@waruqi waruqi closed this as completed Nov 13, 2024
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

4 participants