Cross compile libgcrypt for iPhone? Linker error ... Seems to not find "fwrite" and "strerror"?

I successfully cross-compiled Apache Portable Runtime (APR) for iPhone using a set of customized scripts that call GNU Autotools "./configure" with the necessary cross-compilation options.

Now I'm trying to cross-compile GNUTLS, which depends on libtasn1 and libgcrypt, which in turn depends on libgpg-error. Here I ran into difficulties and can use your help ...

I am currently trying to cross compile libgpg-error. The configuration scripts I used earlier work just fine; the "./configure" process terminates cleanly. Problems arise when I run make. When I run make, everything seems to compile, but then I get the following nasty linker error at the end:

  / bin / sh ../libtool --tag = CC --mode = link /Users/michaelsafyan/Downloads/libgpg-error-1.7/compile /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -std = c99 -arch armv6 -pipe -no-cpp-precomp --sysroot = '/ Developer / Platforms / iPhoneOS.platform / Developer / SDKs / iPhoneOS3.0.sdk' -isystem /Developer/Platforms/iPhoneOS.platform/ Developer / SDKs / iPhoneOS3.0.sdk / usr / lib / gcc / arm-apple-darwin9 / 4.2.1 / include / -isystem /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr / include -isystem /Developer/Platforms/iPhoneOS.platform/Developer/usr/include -isystem /opt/iphone-3.0/include -isystem /usr/local/iphone-3.0/include -arch armv6 --sysroot = '/ Developer /Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk '-L / Developer / Platforms / iPhoneOS.platform / Developer / SDKs / iPhoneOS3.0.sdk / usr / lib -L / Developer / Platforms / iPhoneOS. platform / Developer / usr / lib -L / opt / iphone-3.0 / lib -L / usr / local / iphone-3.0 / lib -o gpg-error gpg_error-strsource-sym.o gpg_error-strerror-sym.o gpg_error-  gpg-error.o ./libgpg-error.la  
 /Users/michaelsafyan/Downloads/libgpg-error-1.7/compile /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -std = c99 -arch armv6 -pipe -no-cpp-precomp --sysroot = / Developer / Platforms / iPhoneOS.platform / Developer / SDKs / iPhoneOS3.0.sdk -isystem /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr/lib/gcc/arm-apple- darwin9 / 4.2.1 / include / -isystem /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr/include -isystem /Developer/Platforms/iPhoneOS.platform/Developer/usr/include -isystem /opt/iphone-3.0/include -isystem /usr/local/iphone-3.0/include -arch armv6 --sysroot = / Developer / Platforms / iPhoneOS.platform / Developer / SDKs / iPhoneOS3.0.sdk -o gpg-error gpg_error-strsource-sym.o gpg_error-strerror-sym.o gpg_error-gpg-error.o -L / Developer / Platforms / iPhoneOS.platform / Developer / SDKs / iPhoneOS3.0.sdk / usr / lib -L / Developer / Platforms / iPhoneOS.platform / Developer / usr / lib -L / opt / iphone-3.0 / lib -L / usr / local / iphone-3.0 / lib ./.libs/libgpg-error.a
 Undefined symbols:
   "_fwrite $ UNIX2003", referenced from:
       _main in gpg_error-gpg-error.o
   "_strerror $ UNIX2003", referenced from:
       _gpg_strerror in libgpg-error.a (libgpg_error_la-strerror.o)
 ld: symbol (s) not found
 collect2: ld returned 1 exit status
 make [3]: *** [gpg-error] Error 1
 make [2]: *** [all] Error 2
 make [1]: *** [all-recursive] Error 1
 make: *** [all] Error 2

Any ideas on how to make this work? The software versions that I compile are:

  • libgpg-error: 1.7
  • libgcrypt: 1.4.4
  • libtasn1: 2.2
  • gnutls: 2.8.4

Please, help. Thanks.

Update

According to the initial feedback, each SDK has a copy of "libSystem.dylib" in "$ SDKROOT / usr / lib". There is no copy of libSystem in "$ DEVROOT / usr / lib", where:

  • $ DEVROOT = "/Developer/Platforms/iPhoneOS.platform/Developer"
  • $ SDKROOT = "$ DEVROOT / SDK / iPhoneOS $ VER.sdk"

The "libSystem" libraries contain regular, undecorated versions of each character, but do not contain the "$ UNIX2003" character variants. I suspect that GPG-ERROR defines "_POSIX_C_SOURCE", "_UNIX", or another UNIX function test macro, and that the rogue header adding "$ UNIX2003" to functions when these function check macros are present is included. Removing "$ DEVROOT / usr / include" from the list of included directories does not affect the removal of this error message.

As a last resort, I see that “ld” accepts the “-alias_list” parameter, which allows you to specify a file with entries such as “_fwrite _fwrite $ UNIX2003” to force these undefined characters for their unbound options. If possible, I would like to avoid this option as it seems hacky and potentially dangerous.

+4
source share
3 answers

The typically unresolved $ UNIX2003 symbol means that you are communicating with an older SDK than the one with which the existing object files were created .

One strange look includes the path to me and please note that I am only vaguely familiar with the development of Mac and not at all with the development of the iPhone, this is the way

/Developer/Platforms/iPhoneOS.platform/Developer/usr/include 

which is not actually in the SDK folder. Is it possible that you took rogue symbols, if any, from there? It seems unlikely since this happens later on the command line than the SDK includes paths.

Perhaps the characters are the expected versions of _fwrite and _strerror , and therefore gpg_error-gpg-error.o and libgpg-error.a are fine, and this is really a binding problem, although again unlikely, since you have

 /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr/lib 

as the -L option. I assume there is somewhere a libsystem dylib?

I assume the first thing to do is to check if the version of the UNIX2003 symbol is what you expect or not. I guess this is so, but as I said, I may be completely wrong. :)

Secondly, you can try to get verbose output from ld to see where it finds the characters. I'm sure there is an environment variable that you can set to make this happen, but I don't see any directions on the user manual page for ld . ( Update : two env variables: LD_TRACE_ARCHIVES and LD_TRACE_DYLIBS , but maybe they give the same thing as -t?).

Edit:

OK, so I was completely wrong with the UNIX2003 characters that were needed. lol.

When you built the libgpg error, I think it created the file

SRC / .deps / gpg_error-GPG-error.Po

which contains header dependencies (at least that was on my Linux system). This can give an idea of ​​where he got the wrong header when creating gpg_error-gpg-error.o.

By the way, it looks like the libgpg-error script configuration accepts the -isysroot and -arch . Can you use them instead of your own version of configure script?

Edit2:

Ok, let’s go again :) Here are some things to try, starting with a clean source folder:

  • use -isysroot instead of --sysroot
  • use -isysroot as well as --sysroot
  • temporarily make your regular system headers inaccessible, for example, renaming the folder. We hope that the assembly will fall if it does not find the header, and it will tell you for sure.
0
source

Try pre-processing gpg_error-gpg-error.c with -E, then find the missing characters. You should find where it comes from (for example, asm ("_" "nice", "UNIX2003"). Then change this header (for example, unistd.h to add #warning "HERE"). Now recompile, and you should find include stack.

0
source

The $ 2003 suffix is ​​generated by the compiler under certain circumstances, which you may find fully documented in manual input for compatibility.

man compat

I struggled with this for a while before finally fixing it by setting

-mmacosx-version-min=10.3

Any version prior to 10.4 will do the job. I suspect, given Troubadour's answer, I might be better off looking for erroneously linked libraries using the -t ld option

Hope this helps.

0
source

All Articles