Skip to content

Commit

Permalink
Fixes gevent recipe on arm64-v8a arch
Browse files Browse the repository at this point in the history
Adding `libm.so` to the `arm64-v8a` build fixes undefined reference
errors. The (truncated) config.log errors were:
```
...
libpython3.7m.so: undefined reference to `hypot@LIBC'
libpython3.7m.so: undefined reference to `frexp@LIBC'
libpython3.7m.so: undefined reference to `cos@LIBC'
libpython3.7m.so: undefined reference to `pow@LIBC'
libpython3.7m.so: undefined reference to `atan2@LIBC'
libpython3.7m.so: undefined reference to `modf@LIBC'
libpython3.7m.so: undefined reference to `exp@LIBC'
libpython3.7m.so: undefined reference to `sin@LIBC'
libpython3.7m.so: undefined reference to `log@LIBC'
libpython3.7m.so: undefined reference to `fmod@LIBC'
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
...
```
Refs: #1722 (comment)
  • Loading branch information
AndreMiras committed Mar 22, 2020
1 parent 22eb6c9 commit 56a92b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pythonforandroid/recipes/gevent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
"""
- Moves all -I<inc> -D<macro> from CFLAGS to CPPFLAGS environment.
- Moves all -l<lib> from LDFLAGS to LIBS environment.
- Copies all -l<lib> from LDLIBS to LIBS environment.
- Fixes linker name (use cross compiler) and flags (appends LIBS)
"""
env = super(GeventRecipe, self).get_recipe_env(arch, with_flags_in_cc)
env = super().get_recipe_env(arch, with_flags_in_cc)
# CFLAGS may only be used to specify C compiler flags, for macro definitions use CPPFLAGS
regex = re.compile(r'(?:\s|^)-[DI][\S]+')
env['CPPFLAGS'] = ''.join(re.findall(regex, env['CFLAGS'])).strip()
Expand All @@ -24,6 +25,7 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
# LDFLAGS may only be used to specify linker flags, for libraries use LIBS
regex = re.compile(r'(?:\s|^)-l[\w\.]+')
env['LIBS'] = ''.join(re.findall(regex, env['LDFLAGS'])).strip()
env['LIBS'] += ' {}'.format(''.join(re.findall(regex, env['LDLIBS'])).strip())
env['LDFLAGS'] = re.sub(regex, '', env['LDFLAGS'])
info('Moved "{}" from LDFLAGS to LIBS.'.format(env['LIBS']))
return env
Expand Down
6 changes: 5 additions & 1 deletion tests/recipes/test_gevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ def test_get_recipe_env(self):
# checks the regex doesn't parse `python3-libffi-openssl` as a `-libffi`
'-L/path/to/python3-libffi-openssl/library3 '
)
mocked_ldlibs = ' -lm'
mocked_env = {
'CFLAGS': mocked_cflags,
'LDFLAGS': mocked_ldflags,
'LDLIBS': mocked_ldlibs,
}
with patch('pythonforandroid.recipe.CythonRecipe.get_recipe_env') as m_get_recipe_env:
m_get_recipe_env.return_value = mocked_env
Expand All @@ -53,11 +55,13 @@ def test_get_recipe_env(self):
' -L/path/to/library2'
' -L/path/to/python3-libffi-openssl/library3 '
)
expected_libs = '-lm -lpython3.7m'
expected_ldlibs = mocked_ldlibs
expected_libs = '-lm -lpython3.7m -lm'
expected_env = {
'CFLAGS': expected_cflags,
'CPPFLAGS': expected_cppflags,
'LDFLAGS': expected_ldflags,
'LDLIBS': expected_ldlibs,
'LIBS': expected_libs,
}
self.assertEqual(expected_env, env)

0 comments on commit 56a92b1

Please sign in to comment.