Linker error when unit testing: ld: illegal text-relocation to cstring in … from _av_image_check_size in …/libavutil.a(imgutils.o)

陌路散爱 提交于 2019-12-01 02:59:55

问题


In Xcode 4.3.2, building an iPad app, which includes libavutil.a from the ffmpeg distribution, it builds and runs correctly but when I try to run unit tests (Cmd-U) I get the following linker error:

ld: illegal text-relocation to cstring in /myPath/libavutil.a(imgutils.o) from _av_image_check_size in /myPath/libavutil.a(imgutils.o) for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is on the device (We can't run it in the simulator currently because we don't have fat binaries for all the libraries we are including).

Why will it build and run correctly normally but not link when running unit tests?


回答1:


The answer, from here.

is to add:

-read_only_relocs suppress

to the linker flags.

The other link explains why. The solution was originally found here.




回答2:


Just to be specific, the line that specifically worked to fix a similar linking error with ffmpeg for 32bit OSX link using xcode/c++11, was to add -Wl,-read_only_relocs,suppress to the link line. Variations of this didn't work.




回答3:


I solved this linker error by enabling Position-Independent Code in the compiler and linker settings in XCode.




回答4:


For those who have read answers above but it did not help, check your "Product -> Scheme -> Edit Scheme". It should be "debug" for simulator and for device it does not matter. Otherwise you will get strange bugs like it cannot see some parts of your project.



来源:https://stackoverflow.com/questions/11317637/linker-error-when-unit-testing-ld-illegal-text-relocation-to-cstring-in-fr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!