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

macOS: Undefined symbols for architecture arm64: "_libiconv", referenced from: (anonymous namespace)::convertStringCharsetIconv #1903

Closed
clanmills opened this issue Sep 14, 2021 · 2 comments

Comments

@clanmills
Copy link
Collaborator

clanmills commented Sep 14, 2021

Apple M1 processors are failing to link the iConv library distributed in macOS SDK 11.3. The full message is:

[ 47%] Building CXX object src/CMakeFiles/exiv2lib.dir/bmffimage.cpp.o
[ 48%] Linking CXX shared library ../lib/libexiv2.dylib
Undefined symbols for architecture arm64:
  "_libiconv", referenced from:
      (anonymous namespace)::convertStringCharsetIconv(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, char const*, char const*) in convert.cpp.o
  "_libiconv_close", referenced from:
      (anonymous namespace)::convertStringCharsetIconv(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, char const*, char const*) in convert.cpp.o
  "_libiconv_open", referenced from:
      (anonymous namespace)::convertStringCharsetIconv(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, char const*, char const*) in convert.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libexiv2.0.27.5.2.dylib] Error 1
make[1]: *** [src/CMakeFiles/exiv2lib.dir/all] Error 2
make: *** [all] Error 2
565 rmills@rmillsm1:~/gnu/github/exiv2/foo/0.27-maintenance/build $ 

The work-around is:

diff --git a/cmake/findDependencies.cmake b/cmake/findDependencies.cmake
index ec3a43f5..625f825a 100644
--- a/cmake/findDependencies.cmake
+++ b/cmake/findDependencies.cmake
@@ -53,6 +53,15 @@ if (EXIV2_ENABLE_NLS)
 endif( )
 
 find_package(Iconv)
+# Don't use Iconv on macOS M1.  Linker fails because SDK libiconv not been built for arm64
+if ( APPLE )
+       EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE )
+       if ( ${ARCHITECTURE} STREQUAL arm64 )
+       set(ICONV_FOUND 0)
+       message ( "-- ICONV ignored on Apple M1 processor" )
+       endif()
+endif()
+
 if( ICONV_FOUND )
     message ( "-- ICONV_INCLUDE_DIR : " ${Iconv_INCLUDE_DIR} )
     message ( "-- ICONV_LIBRARIES : " ${Iconv_LIBRARY} )

When this patch is applied, the outputfrom cmake is:

-- Performing Test Iconv_IS_BUILT_IN
-- Performing Test Iconv_IS_BUILT_IN - Failed
-- Found Iconv: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/lib/libiconv.tbd  
-- ICONV ignored on Apple M1 processor

I don't think this code should be added permanently as it would disable libiconv permanently on the M1. Presumably Apple will fix the SDK. I haven't reported this to Apple. So let's leave this issue open and "never fix" as the issue should disappear in time.

@clanmills
Copy link
Collaborator Author

Here's another work-around. Delete the file in the SDK that doesn't work, rerun cmake and build!

540 rmills@rmillsm1:~/gnu/github/exiv2/0.27-maintenance/build $ sudo rm -rf /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/lib/libiconv.tbd 
541 rmills@rmillsm1:~/gnu/github/exiv2/0.27-maintenance/build $ cd .. ; rm -rf build ; mkdir build ; cd build
542 rmills@rmillsm1:~/gnu/github/exiv2/0.27-maintenance/build $ cmake .. -DEXIV2_ENABLE_BMFF=1
543 rmills@rmillsm1:~/gnu/github/exiv2/0.27-maintenance/build $ make
.......
544 rmills@rmillsm1:~/gnu/github/exiv2/0.27-maintenance/build $ 

I'm going to close this. The issue has been record in the project history. It's not an Exiv2 issue.

@clanmills
Copy link
Collaborator Author

Apple's SDK works. Building libiconv from source and installing it in /usr/local/lib is causing this linking issue. See: #1915 (comment)

This was referenced Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant