5

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

4 Answers 4

11

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
  • 8
    This no longer works. That flag is unsupported on x86_64 and is also incompatible with BYTECODE=YES.
    – dgatwood
    Mar 30, 2017 at 18:07
  • This still works. I just used this flag with Xcode 9.4.1 to fix an app that includes a library which caused this error when compiling for the iPhone 5 / iOS 10 simulator.
    – Dorian Roy
    Jul 5, 2018 at 10:11
4

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
  • With the flag, the lib can be compiled success, but will crash on 32 bit device when using the lib:``` dyld: REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment 0 which is not a writable segment (__TEXT) in /private/var/containers/Bundle/Application/25DBDD6A-F5C1-4DD3-B432-F9FAB43A3673/UPLiveSDKDemo.app/Frameworks/SomeLibDll.framework/SomeLibDll ``
    – Amalaric
    May 5, 2017 at 7:22
  • @rotoava Did you find any solution? I am also facing the same issue with 32 bit device. Nov 16, 2018 at 7:25
  • @PankajVavadiya Sorry, this has passed too along time, and I forget the final solution. I didn't come back to write the result, maybe I did not find a solution. The 32-bit machine only has the iPhone 5, and our SDK ignores the simulator problem. At the same time, we only provide static libraries when the dynamic libraries have problems, and so on.
    – Amalaric
    Nov 17, 2018 at 8:44
2

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

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.