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

user1499742 picture user1499742 · Jul 3, 2012 · Viewed 7.2k times · Source

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?

Answer

user1499742 picture user1499742 · Jul 6, 2012

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.