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

4

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?

Arhna answered 3/7, 2012 at 19:15 Comment(1)
Looks like the answer to this is the same as the answer to this question: [link] #6650678Arhna
A
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.

Arhna answered 5/7, 2012 at 23:5 Comment(2)
This no longer works. That flag is unsupported on x86_64 and is also incompatible with BYTECODE=YES.Respectively
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.Ferromagnetic
C
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.

Comical answered 21/12, 2013 at 18:50 Comment(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 ``Campball
@rotoava Did you find any solution? I am also facing the same issue with 32 bit device.Wobbly
@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.Campball
K
2

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

Kinswoman answered 12/6, 2015 at 16:27 Comment(0)
Q
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.

Quartis answered 2/9, 2019 at 8:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.