PHP compile fails with undefined symbols for architecture x86_64, libiconv on macOS Sierra
Asked Answered
R

3

9

I have upgraded a Mac to macOS 10.12.0 Sierra, and am trying to upgrade PHP to version 7.0.9, but 'make test' fails with:

Undefined symbols for architecture x86_64:
  "_libiconv", referenced from:
      _zif_iconv_substr in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _php_iconv_string in iconv.o
      __php_iconv_strlen in iconv.o
      __php_iconv_strpos in iconv.o
      __php_iconv_appendl in iconv.o
      _php_iconv_stream_filter_append_bucket in iconv.o
      ...
  "_libiconv_close", referenced from:
      _zif_iconv_substr in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _php_iconv_string in iconv.o
      __php_iconv_strlen in iconv.o
      __php_iconv_strpos in iconv.o
      __php_iconv_mime_decode in iconv.o
      _php_iconv_stream_filter_factory_create in iconv.o
      ...
  "_libiconv_open", referenced from:
      _zif_iconv_substr in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _php_iconv_string in iconv.o
      __php_iconv_strlen in iconv.o
      __php_iconv_strpos in iconv.o
      __php_iconv_mime_decode in iconv.o
      _php_iconv_stream_filter_factory_create in iconv.o
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libs/libphp7.bundle] Error 1

I compiled it with:

./configure --prefix=/usr/local/php5 --mandir=/usr/share/man --infodir=/usr/share/info --sysconfdir=/etc --with-config-file-path=/etc --with-zlib --with-zlib-dir=/usr --with-openssl=/usr/local --enable-exif --enable-ftp --enable-mbstring --enable-mbregex --enable-sockets --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-apxs2=/usr/local/apache2/bin/apxs --enable-zip --with-curl

and have tried adding different '--with-iconv-dir=' options but always get the same undefined symbols error.

I have downloaded and compiled libiconv to no avail. Even configured the compile with:

CFLAGS='-arch x86_64' CCFLAGS='-arch x86_64' CXXFLAGS='-arch x86_64' ./configure

but that made no difference. Any suggestions?

Any help would be much appreciated.

Rosaleerosaleen answered 21/10, 2016 at 2:15 Comment(2)
As a compilation problem, did you also make sure to ask on the appropriate PHP mailing list? (php.net/mailing-lists.php, probably the "Installation issues and problems" list)Vacant
Thanks Mike. Will do.Rosaleerosaleen
O
9

This might solve the problem

vim Makefile
find EXTRA_LDFALGS and EXTRA_LDFLAGS_PROGRAMS
remove L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/lib 
Overcome answered 20/4, 2018 at 12:37 Comment(4)
Can you clarify what "this" is and how to use it?Plateau
Is there a way to make a fix in the ./configure command? How can we exclude the MacOSX library without manually editing the Makefile?Triumphant
Yes, this did it for me, too. I didn't eliminate that line but simply moved it after "-L / usr/local/iconv/lib" (which is my compiled-from-source iconv lib) in each line where I found a reference to the Xcode path (note that there are also -rpath references to -L.... and change those to be at the end of the line as wellReames
Actually, I ran into this same thing in a different way compiling git and it caused me to go deep and figure out what was really going on and solve it. I created a post to explain why this is happening with iconv.Reames
B
4
  1. brew install libiconv (libiconv will install in /usr/local/opt/libiconv/)
  2. find EXTRA_LIBS variable in MakeFile.
  3. change -liconv to /usr/local/opt/libiconv/lib/libiconv.dylib

Here is the reason:

  • Mac os has its own libiconv.dylib in dir/usr/lib/libiconv.dylib, which do not contains _libiconv _libiconv_close . founctions. Update to a new libiconv version and reference to it will solve the case
Beals answered 8/3, 2019 at 9:24 Comment(0)
L
-1

I'll teach you. That's caused due to broken symbol during your php source code compilation process.

Since OS X uses llvm toolchain based clang, and the php original source code is based on GNU libraries in which it's compatible for gcc only rather than clang you're already familiar with.

**

Their architectures seem to be incompatible somehow.

**

In one word, original libiconv source code was definitely not compatible with OS X. Installing by the command in OS X resolved the issues:

brew install libiconv.

taehwanjeoung@taehwanui-MacBookAir ~ % brew install libiconv

Updating Homebrew... ==> Auto-updated Homebrew! Updated 1 tap (homebrew/core). ==> New Formulae ghz ==> Updated Formulae ammonite-repl contentful-cli gwt libwebsockets salt angular-cli detekt homeassistant-cli mapserver stress-ng ask-cli ethereum katago php topgrade bazel exploitdb lerna [email protected] borgmatic fastlane libdeflate [email protected] conan gatsby-cli libmypaint pidgin

Warning: libiconv 1.16 is already installed and up-to-date To reinstall 1.16, run brew reinstall libiconv

Because it'll be installing OS X-compatible library with complete x86-64bit symbol.

I had same issue yesterday when I was about to practicing php 5 earlier version. I compiled successfully on OS X - the latest version "Mac OS X 10.15.4, Catalina."

I'm advising you that you do not use the latest version of every development toolchain as always. In a way, you would be conflicting less, it directly means less time consuming when you're doing more important tasks.

and you even need to edit Makefile before you command "make" to compile on OS X.

Mac developer often uses "nano command line tool instead of vi":

nano Makefile

and then find EXTRA_LIBS environment variable change -liconv to /usr/local/opt/libiconv/lib/libiconv.dylib - where it is location for Mac OS X compatible library is installed by homebrew. Because -liconv's default path is somewhere else: /usr/lib/ - which the incompatible with broken architecture symbol resides.

So where can you see the diffs between linux kernel system and OS X system: .so file exension for linux one and dylib for mac os one?

The names imply their compiling architecture and the structure inside are a little bit different.

I added more reasonable details for you beside the answer snippet above to explain clearly.

So let me explaining at one point:

It is the issue of broken architecture symbols during your GNU source code compilation which is not compatible to OS X Unix system environment. Because OS X is more BSD system alike than is linux kernel alike.

  • I'm developing hobbyist. so I don't even know all. you'll need to learn everyday also. good luck.

I would like to recommend you read the book "The Software Craftsman - written by Sandro Mancuso." It is more suitable method(not a tool anyway) for developing and debugging spaces I personally can think of. Someone else denies that somehow.

Leyte answered 15/5, 2020 at 4:33 Comment(1)
I'm trying help myself and moreover I headed even to stack overflow to help others sometimes.Leyte

© 2022 - 2024 — McMap. All rights reserved.