mpv-player/mpv

configure failed on OS X with LuaJIT and workaround

191919 opened this issue · 11 comments

./waf configure failed on my OS X 10.9.4 with luajit-2.0.3.

The workaround is to configure with the following command line:

LDFLAGS="-pagezero_size 10000 -image_base 100000000" ./waf configure --lua=luajit

It is a LuaJIT issue when running on 64-bit OS X and is documented in http://luajit.org/install.html .

If you're building a 64 bit application on OSX which links directly or indirectly against LuaJIT, you need to link your main executable with these flags:

-pagezero_size 10000 -image_base 100000000

Also, it's recommended to rebase all (self-compiled) shared libraries which are loaded at runtime on OSX/x64 (e.g. C extension modules for Lua). See: man rebase

Does the OSX luajit .pc file contain these options?

$ cat /usr/local/lib/pkgconfig/luajit.pc
# Package information for LuaJIT to be used by pkg-config.
majver=2
minver=0
relver=3
version=${majver}.${minver}.${relver}
abiver=5.1

prefix=/usr/local
multilib=lib
exec_prefix=${prefix}
libdir=${exec_prefix}/${multilib}
libname=luajit-${abiver}
includedir=${prefix}/include/luajit-${majver}.${minver}

INSTALL_LMOD=${prefix}/share/lua/${abiver}
INSTALL_CMOD=${prefix}/${multilib}/lua/${abiver}

Name: LuaJIT
Description: Just-in-time compiler for Lua
URL: http://luajit.org
Version: ${version}
Requires:
Libs: -L${libdir} -l${libname}
Libs.private: -Wl,-E -lm -ldl
Cflags: -I${includedir}

Then I think luajit should add that to their .pc file. That's what these files are for, after all. (I was just afraid waf would filter out these flags.)

That's why I called it a workaround.

LuaJIT doesn't use autotools and the .pc file is fixed instead of generated. Those options are only for 64-bit OS X main executables.

FYI: You can take a look at the popular ngx_lua project (https://github.com/openresty/lua-nginx-module) which makes heavy use of LuaJIT. It detects the OS type and the lua engine then adds the needed LDFLAGS.

Yeah, that lua-nginx-module config script demonstrates exactly what we do not want. It hardcodes the possible installation paths on every platform. I'd argue LuaJIT should just either fix their .pc file, or their memory allocator code (which requires these options).

To make matters worse, you couldn't use a libmpv linked to luajit, because that would require the application using libmpv to know about these luajit options.

What's wrong with using plain Lua, btw.?

It hardcodes the possible installation paths on every platform.

PS: of course one problem is that official upstream Lua doesn't even have a .pc file (these are added by distros etc.), but so far relying on .pc worked relatively well.

What's wrong with using plain Lua, btw.?

Of course I can use the official lua, but I am a LuaJIT lover since I learned from it a lot.

Is there any plan to make mpv on OS X an app package so that I can open movies from Finder? And lua will make it more interesting when you can control it with a piece of lua script.

Is there any plan to make mpv on OS X an app package so that I can open movies from Finder

It is already, see the homebrew formula.

I just run the python script TOOLS/osxbundle.py.

$ python TOOLS/osxbundle.py build/mpv
Creating Mac OS X application bundle (version: git-1f4a74c)...
> copying bundle skeleton
> copying binary
> generating Info.plist
> bundling dependencies
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool: can't open file: libx265.32.dylib (No such file or directory)
Traceback (most recent call last):
  File "TOOLS/dylib-unhell.py", line 93, in <module>
    main()
  File "TOOLS/dylib-unhell.py", line 90, in main
    process_libraries(libs, binary)
  File "TOOLS/dylib-unhell.py", line 71, in process_libraries
    shutil.copy(src, dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 119, in copy
    copyfile(src, dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 82, in copyfile
    with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: 'libx265.32.dylib'
done.

I checked TOOLS/dylib-unhell.py, it doesn't check dylibs in /usr/local/lib where the user-compiled libraries are usually located. Another lame workaround:

diff --git a/TOOLS/dylib-unhell.py b/TOOLS/dylib-unhell.py
index 43fd111..1925c95 100755
--- a/TOOLS/dylib-unhell.py
+++ b/TOOLS/dylib-unhell.py
@@ -9,11 +9,13 @@ from functools import partial

 sys_re = re.compile("^/System")
 usr_re = re.compile("^/usr/lib/")
+usr_local_re = re.compile("^/usr/local/lib/")
 exe_re = re.compile("@executable_path")

 def is_user_lib(objfile, libname):
     return not sys_re.match(libname) and \
            not usr_re.match(libname) and \
+           not usr_local_re.match(libname) and \
            not exe_re.match(libname) and \
            not "libobjc." in libname and \
            not "libSystem." in libname and \

Then I run the generated mpv.app, everything is fine but mpv halts when I press Cmd+0/1/2 to zoom the window, F is ok. I tried to run mpv from terminal, the result is the same.

Closing, LuaJIT's .pc file should be fixed instead.

For reference: brew installed luajit does provide these flags now and compilation works so this is no longer an issue.

# Package information for LuaJIT to be used by pkg-config.
majver=2
minver=0
relver=5
version=${majver}.${minver}.${relver}
abiver=5.1

prefix=/usr/local/Cellar/luajit/2.0.5
multilib=lib
exec_prefix=${prefix}
libdir=${exec_prefix}/${multilib}
libname=luajit-${abiver}
includedir=${prefix}/include/luajit-${majver}.${minver}

INSTALL_LMOD=/usr/local/share/lua/${abiver}
INSTALL_CMOD=/usr/local/${multilib}/lua/${abiver}

Name: LuaJIT
Description: Just-in-time compiler for Lua
URL: http://luajit.org
Version: ${version}
Requires:
Libs: -pagezero_size 10000 -image_base 100000000 -L${libdir} -l${libname}
Libs.private: -Wl,-E -lm -ldl
Cflags: -I${includedir}

(However, it still doesn't work as mpv fails to initialize it for reasons I don't know yet.)