Cmake报错:xxx can not be used when making a PIE object; recompile with -fPIC
1.使用Cmake时出现如下报错
错误信息:relocation R_X86_64_32S against symbol ‘xxx’ can not be used when making a PIE object; recompile with -fPIC

2.解决
在CMakeLists.txt中更改target_link_libraries内的参数(在最后添加-no-pie):
# 原:
target_link_libraries(Device_1 ${ROOT_PATH}/middleware/libMiddleware.a Task1 MyDeviceReader MyDeviceWriter)
# 更改后
target_link_libraries(Device_1 ${ROOT_PATH}/middleware/libMiddleware.a Task1 MyDeviceReader MyDeviceWriter -no-pie)
重新编译:

编译成功!!!
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
