[pypy-commit] pypy default: Merged in larstiq/pypy/osx-shared (pull request #293)
fijal
noreply at buildbot.pypy.org
Wed Dec 31 07:59:55 CET 2014
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch:
Changeset: r75184:3f1e8d12f774
Date: 2014-12-31 08:59 +0200
http://bitbucket.org/pypy/pypy/changeset/3f1e8d12f774/
Log: Merged in larstiq/pypy/osx-shared (pull request #293)
--shared support on OSX
diff --git a/pypy/doc/embedding.rst b/pypy/doc/embedding.rst
--- a/pypy/doc/embedding.rst
+++ b/pypy/doc/embedding.rst
@@ -97,12 +97,18 @@
return res;
}
-If we save it as ``x.c`` now, compile it and run it with::
+If we save it as ``x.c`` now, compile it and run it (on linux) with::
fijal at hermann:/opt/pypy$ gcc -o x x.c -lpypy-c -L.
fijal at hermann:/opt/pypy$ LD_LIBRARY_PATH=. ./x
hello from pypy
+on OSX it is necessary to set the rpath of the binary if one wants to link to it::
+
+ gcc -o x x.c -lpypy-c -L. -Wl,-rpath -Wl, at executable_path
+ ./x
+ hello from pypy
+
Worked!
.. note:: If the compilation fails because of missing PyPy.h header file,
diff --git a/rpython/translator/c/test/test_standalone.py b/rpython/translator/c/test/test_standalone.py
--- a/rpython/translator/c/test/test_standalone.py
+++ b/rpython/translator/c/test/test_standalone.py
@@ -1386,6 +1386,8 @@
ext_suffix = '.so'
if cbuilder.eci.platform.name == 'msvc':
ext_suffix = '.dll'
+ elif cbuilder.eci.platform.name.startswith('darwin'):
+ ext_suffix = '.dylib'
libname = cbuilder.executable_name.join('..', 'lib' +
cbuilder.modulename + ext_suffix)
lib = ctypes.CDLL(str(libname))
diff --git a/rpython/translator/platform/darwin.py b/rpython/translator/platform/darwin.py
--- a/rpython/translator/platform/darwin.py
+++ b/rpython/translator/platform/darwin.py
@@ -10,10 +10,11 @@
so_ext = 'dylib'
DEFAULT_CC = 'clang'
+ rpath_flags = ['-Wl,-rpath', '-Wl, at executable_path']
def _args_for_shared(self, args):
return (list(self.shared_only)
- + ['-dynamiclib', '-undefined', 'dynamic_lookup']
+ + ['-dynamiclib', '-install_name', '@rpath/$(TARGET)', '-undefined', 'dynamic_lookup']
+ args)
def _include_dirs_for_libffi(self):
diff --git a/rpython/translator/platform/posix.py b/rpython/translator/platform/posix.py
--- a/rpython/translator/platform/posix.py
+++ b/rpython/translator/platform/posix.py
@@ -14,6 +14,7 @@
relevant_environ = ('CPATH', 'LIBRARY_PATH', 'C_INCLUDE_PATH')
DEFAULT_CC = 'gcc'
+ rpath_flags = ['-Wl,-rpath=\'$$ORIGIN/\'']
def __init__(self, cc=None):
self.cc = cc or os.environ.get('CC', self.DEFAULT_CC)
@@ -158,6 +159,7 @@
('CC', self.cc),
('CC_LINK', eci.use_cpp_linker and 'g++' or '$(CC)'),
('LINKFILES', eci.link_files),
+ ('RPATH_FLAGS', self.rpath_flags),
]
for args in definitions:
m.definition(*args)
@@ -181,7 +183,7 @@
'int main(int argc, char* argv[]) '
'{ return $(PYPY_MAIN_FUNCTION)(argc, argv); }" > $@')
m.rule('$(DEFAULT_TARGET)', ['$(TARGET)', 'main.o'],
- '$(CC_LINK) $(LDFLAGS_LINK) main.o -L. -l$(SHARED_IMPORT_LIB) -o $@ -Wl,-rpath=\'$$ORIGIN/\'')
+ '$(CC_LINK) $(LDFLAGS_LINK) main.o -L. -l$(SHARED_IMPORT_LIB) -o $@ $(RPATH_FLAGS)')
return m
More information about the pypy-commit
mailing list