Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libiconv linker errors #373

Closed
Uncommon opened this issue Jun 7, 2014 · 21 comments
Closed

libiconv linker errors #373

Uncommon opened this issue Jun 7, 2014 · 21 comments
Labels

Comments

@Uncommon
Copy link
Contributor

Uncommon commented Jun 7, 2014

I'm synced to c2d3af2 (current master), and I've run the bootstrap script and tried cleaning, but I always get these linker errors when building the framework target:

Undefined symbols for architecture x86_64:
  "_libiconv", referenced from:
      _git_path_iconv in libgit2.a(path.c.o)
  "_libiconv_close", referenced from:
      _git_path_iconv_clear in libgit2.a(path.c.o)
  "_libiconv_open", referenced from:
      _git_path_iconv_init_precompose in libgit2.a(path.c.o)
@arrbee
Copy link
Member

arrbee commented Jun 7, 2014

Do you happen to have iconv installed via MacPorts or another alternative version of iconv?

@Uncommon
Copy link
Contributor Author

Uncommon commented Jun 8, 2014

Isn't it a standard library? I haven't installed it explicitly.

@arrbee
Copy link
Member

arrbee commented Jun 8, 2014

It is. One common source of problems is for people who are not using the standard version. What version of OS X are you running?

@arrbee
Copy link
Member

arrbee commented Jun 8, 2014

Oh, and are you using MacPorts even if you didn't install it explicitly?

@Uncommon
Copy link
Contributor Author

I've never used MacPorts. I'm on OS X 10.9.2.

@Uncommon
Copy link
Contributor Author

The way the Objective Git framework target is set up, it's linked using the linker build phase (rather than a linker flag), using libiconv.dylib as referenced in the project, which according to Xcode is coming from the 10.9 SDK.

@Uncommon
Copy link
Contributor Author

Also, Xcode 5.1.1.

@jspahrsummers
Copy link
Contributor

If you remove it from the Link Binaries With Libraries phase, and instead add -liconv to the linker flags, does it work then?

@Uncommon
Copy link
Contributor Author

Nope, same error. I also upgraded to 10.9.3, and tried a fresh clone (not as a submodule of my other repo).

@Uncommon
Copy link
Contributor Author

Also tried changing the base SDK to 10.8.

@Uncommon
Copy link
Contributor Author

I reinstalled Xcode in case the library was corrupted. No dice.

https://trac.macports.org/ticket/38851 seemed relevant, but the solution there did not help.

@Uncommon
Copy link
Contributor Author

I tried making a simple project, adding a call to iconv_open() to the command line tool template, and with the -liconv linker flag it builds just fine.

I noticed that the library search paths for ObjectiveGit are . and External, which doesn't explicitly include /usr/lib, but apparently that doesn't matter; adding it doesn't help. What else could be making the difference?

@jspahrsummers
Copy link
Contributor

Sorry for the radio silence—this is just super weird. We've still never seen this problem, on our machines or CI. 😕

You're using Xcode 5.1, right?

@Uncommon
Copy link
Contributor Author

Xcode 5.1.1 as noted above.

Yeah, it's pretty weird. I didn't have this problem on the other machines I've worked on.

@tqc
Copy link

tqc commented Sep 23, 2014

I'm getting the same issue building for iOS. The problem appears to be something to do with incompatible iconv versions - libgit2 is built using /opt/local/include/iconv.h (latest from macports), which contains

#define _LIBICONV_VERSION 0x010E 
#ifndef LIBICONV_PLUG
#define iconv_open libiconv_open
#endif
extern iconv_t iconv_open (const char* tocode, const char* fromcode);

When linking the app project in Xcode, it uses /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/iconv.h, which contains

#define _LIBICONV_VERSION 0x010B 
iconv_t iconv_open (const char* /*tocode*/, const char* /*fromcode*/);

Not sure where the proper place to define LIBICONV_PLUG is, but adding it to iconv.h seems to allow a successful build for arm64, which wasn't working previously. However, I then get other linker errors for x86_64 (iOS simulator for newer devices), and i386, which was previously working now fails.

@tqc
Copy link

tqc commented Sep 23, 2014

Adding the following to CMakeLists.txt seems to work

IF(${CMAKE_OSX_ARCHITECTURES} MATCHES "(arm64|x86_64)")
    ADD_DEFINITIONS(-DLIBICONV_PLUG)
ENDIF()

The other linker errors turned out to be the difference between running script/update_libgit2_ios from Xcode and the command line.

Now to see if it actually runs...

@Uncommon
Copy link
Contributor Author

That doesn't fix it for me. It looks like the header is being found at /opt/local/include/iconv.h, but the library is being linked from /usr/lib/libiconv.dylib, and the symbols are different. So what's the best way to ensure the correct header path?

@Uncommon
Copy link
Contributor Author

...and apparently /opt/local is a MacPorts thing, so I guess I'm using it after all. I don't remember installing it explicitly.

@Napoleon-BlownApart
Copy link

I'm not sure if you've solved this, but I've finally been able to build successfully. Haven't tested the result yet.

I noticed that the symlinks in the External folder were incorrectly pointing to "/usr/local/opt/".
So I deleted these and recreated them by pointing them to /opt/local/lib. I did this for:
libssl.a, libcrypto.a, and libiconv.a.

So, my "Other Linker Flags" for the Mac Target are as follows:

-lgit2
-force_load
/opt/local/lib/libssh2.a  (which I could have made a symlink in External like the others)
External/libssl.a
External/libcrypto.a
External/libgit2.a
External/libiconv.a

Hope this is correct and helps.

Cheers,
Nap

@soniccat
Copy link

I had the same problem. I noticed that after launching ./script/update_libgit2 I had this line:
-- Found Iconv: -L/opt/local/lib -liconv
it meant that it took wrong lib.
After deactivating the lib (sudo port -f deact libiconv), removing the wrong libgit2 and rebuilding it again I saw the right path
-- Found Iconv: -L/usr/lib -liconv
And then I didn't see these linking errors.

@joshaber
Copy link
Member

Pretty old and we've recently cleaned up the libgit2 building process: #483

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants