【发布时间】:2011-09-07 04:59:01
【问题描述】:
我在 linux 中使用 cmake 构建我的项目。
我通过使用链接一些静态库
set(BUILD_SHARED_LIBS FALSE)
set(CMAKE_EXE_LINKER_FLAGS "-static")
target_link_libraries(MyProject /usr/lib/libImlib2.a)
它在 32 位 linux(在我的例子中是 Ubuntu)中完美运行,而不是在 64 位 Ubuntu 中
出现此错误消息。
/usr/bin/ld: /usr/lib64/libImlib2.a(api.o) : relocation R_X86_64_32 againts '.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/lib64/libImlib2.a : could not read symbols: Bad value
collect2:ld returned 1 exit status
我发现的一些文件说这是关于 64 位 linux 的问题,需要设置标志。
所以我加了
set(CMAKE_CXX_FLAGS_DEBUG "-fPIC")
set(CMAKE_CXX_FLAGS_RELEASE "-fPIC")
但没有任何改变。
你能给我一些关于我应该做什么的建议吗?
非常感谢您阅读这个问题。
【问题讨论】:
-
尝试自己构建 Imlib2,可能是打包或上游故障。
-
我这样做并链接了我自己的 Imlib2.a,但问题仍然存在。
-
我猜你必须用
-fPIC重建Imlib2.a作为common x64 issue
标签: linux 64-bit cmake static-libraries static-linking