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

configure failed on OS X with LuaJIT and workaround #1110

Closed
191919 opened this issue Sep 20, 2014 · 11 comments
Closed

configure failed on OS X with LuaJIT and workaround #1110

191919 opened this issue Sep 20, 2014 · 11 comments
Labels
down-upstream features and bugs that need to be implemented and fixed upstream os:mac

Comments

@191919
Copy link

191919 commented Sep 20, 2014

./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

@ghost
Copy link

ghost commented Sep 21, 2014

Does the OSX luajit .pc file contain these options?

@ghost ghost added the os:mac label Sep 21, 2014
@191919
Copy link
Author

191919 commented Sep 22, 2014

$ 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}

@ghost
Copy link

ghost commented Sep 22, 2014

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.)

@191919
Copy link
Author

191919 commented Sep 22, 2014

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.

@ghost
Copy link

ghost commented Sep 22, 2014

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.?

@ghost
Copy link

ghost commented Sep 22, 2014

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.

@191919
Copy link
Author

191919 commented Sep 23, 2014

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.

@pigoz
Copy link
Member

pigoz commented Sep 23, 2014

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.

@191919
Copy link
Author

191919 commented Sep 23, 2014

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.

@pigoz
Copy link
Member

pigoz commented Dec 2, 2014

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

@pigoz pigoz closed this as completed Dec 2, 2014
@pigoz pigoz added the down-upstream features and bugs that need to be implemented and fixed upstream label Dec 2, 2014
pigoz added a commit that referenced this issue Dec 2, 2014
LuaJIT ships with a broken .pc file on OS X (see #1110), and leaving
Lua52 last was done only to improve libquvi interoperability.
@Argon-
Copy link
Member

Argon- commented May 20, 2017

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
down-upstream features and bugs that need to be implemented and fixed upstream os:mac
Projects
None yet
Development

No branches or pull requests

3 participants