libiconv not linking to iOS project

2019-02-07 20:17发布

问题:

I'm trying to compile MailCore into an iOS app I'm making, and the linker keeps complaining that libiconv isn't linked in. At least that's what I think it's complaining about. This is what it spits out:

Undefined symbols for architecture i386:
  "_iconv", referenced from:
      _mail_iconv in libmailcore.a(charconv.o)
  "_iconv_open", referenced from:
      _charconv in libmailcore.a(charconv.o)
      _charconv_buffer in libmailcore.a(charconv.o)
  "_iconv_close", referenced from:
      _charconv in libmailcore.a(charconv.o)
      _charconv_buffer in libmailcore.a(charconv.o)
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

(This is building for the simulator. Building for my iPhone gives the same error, but s/i386/armv7/).

I've tried adding libiconv.dylib to "Link Binary with Libraries", but it doesn't change the errors at all.

Any idea what could be wrong here? I've been trying to Google this error, but I can't find any information about how to link in libiconv. Since it's part of the iOS SDK, you would think I shouldn't need to compile it myself?

回答1:

As extra confirmation that the lib is included in your target, select the lib in the file list in the left pane of Xcode (assuming you've added it to your Target / Project, you should see the framework listed under frameworks), and show the Assistant Editor view on the right pane (View -> Assistant Editor -> Show Assistant Editor).

Then, with the relevant lib selected on the left, you will see 'Target Membership' for that lib shown as a list of checkboxes on the right.

You should see App Target Listed, and the checkbox should be checked for that target.

You could try unchecking and rechecking it, to nudge it into your project?



回答2:

You need add libiconv.dylib via "add framework". SRC is available from this discussion.