I am building puredata via libpd on Android (a fork off 0.51/d5766fd0). I am doing this by loading the libpd CMakeLists.txt from my own CMakeLists invoked from gradle and then linking libpd in my Android app.
When it gets to the step of building libpd.so, it prints:
libpd/CMakeFiles/libpd.dir/pure-data/src/x_text.c.o: In function `text_define_sort':
/path/to/repo/deps/libpd/pure-data/src/x_text.c:552: undefined reference to `qsort_r'
I asked around about this, and was told a few things: * Sometimes this kind of Android error magically goes away if you fiddle with compileSdkVersion in gradle. * There is a list in this git repo:
https://android.googlesource.com/platform/bionic/+/master/libc/libc.map.txt Of which libc symbols wind up in which binary in Android. However, in current Android master, qsort_r is not in this list at all. Only qsort. * qsort_r is not a standard C function, it is a GNU thing, so it's possible Android really just doesn't have it. If Android really doesn't provide quicksort, it *might* be possible to fake qsort_r by adding a single C++ file which wraps std::sort (this was added in C++03 so Android *probably* has it), which doesn't have standard C qsort's reentrancy problem.
I found I was able to make it compile with the following patch:
*diff --git a/src/x_text.c b/src/x_text.c*
*index 44bf9521..18f3d9de 100644*
*--- a/src/x_text.c*
*+++ b/src/x_text.c*
@@ -474,9 +474,9 @@ equal:
found in msvcrt (which indeed it isn't in). Rather than waste more time
on this, just call qsort if we're Microsoft and single-instance. I hope nobody
will try to compile multi-instance Pd for 32-bit windows, but if they
do, they might run into my qsort_s problem again. */
-#if defined(_WIN32) && !defined(PDINSTANCE)
+#if (defined(_WIN32) || defined(__ANDROID__)) && !defined(PDINSTANCE)
#define MICROSOFT_STUPID_SORT
static void *stupid_zkeyinfo;
static int stupid_sortcompare(const void *z1, const void *z2) {
return (text_sortcompare(z1, z2, stupid_zkeyinfo)); }
So although I'm not exactly sure what x_text.c is doing here, I am unblocked, I can proceed with my project as long as I don't need multi-instance. But, I'd like to know, is this a known problem? I find many references to people building PureData on Android but no one seems to have hit this issue. If there is a known working configuration for PureData on Android, what git revision of PureData was it building and what NDK compileSdkVersion? Alternately, is it possible the problem is not with my configuration, but with the libpd CMakeLists, and this problem would go away if I added the right #define or -l link argument?
And if this is a new problem: Would a patch to address this be welcome, and what approach would be preferred? Should I just submit a patch triggering MICROSOFT_STUPID_SORT when __ANDROID__ is present?
(I understand libpd is a different project from puredata and apologize if this is the wrong place to ask given I'm building libpd. However this seems (?) like a problem in the pure-data part of the code.)
Hi Andi,
On 27/10/2020 15:49, Andi McClure wrote:
I am building puredata via libpd on Android (a fork off 0.51/d5766fd0). I am doing this by loading the libpd CMakeLists.txt from my own CMakeLists invoked from gradle and then linking libpd in my Android app.
When it gets to the step of building libpd.so, it prints:
libpd/CMakeFiles/libpd.dir/pure-data/src/x_text.c.o: In function `text_define_sort':
/path/to/repo/deps/libpd/pure-data/src/x_text.c:552: undefined reference to `qsort_r'
I ran into this compiling libpd to run in the browser with Emscripten, ended up writing my own qsort_r that wraps qsort. I haven't tested it much though. There are a couple of follow-up commits so this diff isn't quite the whole story:
https://github.com/claudeha/pure-data/commit/e8023866ef8be3475cc101cfb1656f5...
https://github.com/pure-data/pure-data/issues/675 is an issue with a pull request, that's probably a bit nicer than my patched branch that is way behind upstream...
Maybe other systems than Emscripten and Android are broken, anyone using a BSD or Linux which doesn't use glibc for example?
I asked around about this, and was told a few things:
- Sometimes this kind of Android error magically goes away if you
fiddle with compileSdkVersion in gradle.
- There is a list in this git repo:
https://android.googlesource.com/platform/bionic/+/master/libc/libc.map.txt Of which libc symbols wind up in which binary in Android. However, in current Android master, qsort_r is not in this list at all. Only qsort.
- qsort_r is not a standard C function, it is a GNU thing, so it's
possible Android really just doesn't have it. If Android really doesn't provide quicksort, it *might* be possible to fake qsort_r by adding a single C++ file which wraps std::sort (this was added in C++03 so Android *probably* has it), which doesn't have standard C qsort's reentrancy problem.
Claude
And now that I see it I think Claude's solution is equivalent to what I'm suggesting.
cheers Miller
On Tue, Oct 27, 2020 at 05:17:55PM +0000, Claude Heiland-Allen wrote:
Hi Andi,
On 27/10/2020 15:49, Andi McClure wrote:
I am building puredata via libpd on Android (a fork off 0.51/d5766fd0). I am doing this by loading the libpd CMakeLists.txt from my own CMakeLists invoked from gradle and then linking libpd in my Android app.
When it gets to the step of building libpd.so, it prints:
libpd/CMakeFiles/libpd.dir/pure-data/src/x_text.c.o: In function `text_define_sort':
/path/to/repo/deps/libpd/pure-data/src/x_text.c:552: undefined reference to `qsort_r'
I ran into this compiling libpd to run in the browser with Emscripten, ended up writing my own qsort_r that wraps qsort. I haven't tested it much though.?? There are a couple of follow-up commits so this diff isn't quite the whole story:
https://urldefense.com/v3/__https://github.com/claudeha/pure-data/commit/e80...
https://urldefense.com/v3/__https://github.com/pure-data/pure-data/issues/67... is an issue with a pull request, that's probably a bit nicer than my patched branch that is way behind upstream...
Maybe other systems than Emscripten and Android are broken, anyone using a BSD or Linux which doesn't use glibc for example?
I asked around about this, and was told a few things:
- Sometimes this kind of Android error magically goes away if you fiddle
with compileSdkVersion in gradle.
- There is a list in this git repo:
https://urldefense.com/v3/__https://android.googlesource.com/platform/bionic... ?? ??Of which libc symbols wind up in which binary in Android. However, in current Android master, qsort_r is not in this list at all. Only qsort.
- qsort_r is not a standard C function, it is a GNU thing,??so it's
possible Android really just doesn't have it. If Android really doesn't provide quicksort, it *might* be possible to fake qsort_r by adding a single C++ file which wraps std::sort (this was added in C++03 so Android *probably* has it), which doesn't have standard C qsort's reentrancy problem.
Claude
https://urldefense.com/v3/__https://mathr.co.uk__;!!Mih3wA!W-VdJNWZkwWeADXyv...
Pd-dev mailing list Pd-dev@lists.iem.at https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!...
Hey, I've just updated the PR to also use "STUPID_SORT" on Android.
Christof
On 27.10.2020 18:17, Claude Heiland-Allen wrote:
Hi Andi,
On 27/10/2020 15:49, Andi McClure wrote:
I am building puredata via libpd on Android (a fork off 0.51/d5766fd0). I am doing this by loading the libpd CMakeLists.txt from my own CMakeLists invoked from gradle and then linking libpd in my Android app.
When it gets to the step of building libpd.so, it prints:
libpd/CMakeFiles/libpd.dir/pure-data/src/x_text.c.o: In function `text_define_sort':
/path/to/repo/deps/libpd/pure-data/src/x_text.c:552: undefined reference to `qsort_r'
I ran into this compiling libpd to run in the browser with Emscripten, ended up writing my own qsort_r that wraps qsort. I haven't tested it much though. There are a couple of follow-up commits so this diff isn't quite the whole story:
https://github.com/claudeha/pure-data/commit/e8023866ef8be3475cc101cfb1656f5...
https://github.com/pure-data/pure-data/issues/675 is an issue with a pull request, that's probably a bit nicer than my patched branch that is way behind upstream...
Maybe other systems than Emscripten and Android are broken, anyone using a BSD or Linux which doesn't use glibc for example?
I asked around about this, and was told a few things:
- Sometimes this kind of Android error magically goes away if you
fiddle with compileSdkVersion in gradle.
- There is a list in this git repo:
https://android.googlesource.com/platform/bionic/+/master/libc/libc.map.txt
Of which libc symbols wind up in which binary in Android. However, in current Android master, qsort_r is not in this list at all. Only qsort.
- qsort_r is not a standard C function, it is a GNU thing, so it's
possible Android really just doesn't have it. If Android really doesn't provide quicksort, it *might* be possible to fake qsort_r by adding a single C++ file which wraps std::sort (this was added in C++03 so Android *probably* has it), which doesn't have standard C qsort's reentrancy problem.
Claude
OK, just replace
static void *stupid_zkeyinfo;
with
static PERTHREAD void *stupid_zkeyinfo;
and I think it's OK.
M
On Tue, Oct 27, 2020 at 06:35:34PM +0100, Christof Ressi wrote:
Hey, I've just updated the PR to also use "STUPID_SORT" on Android.
Christof
On 27.10.2020 18:17, Claude Heiland-Allen wrote:
Hi Andi,
On 27/10/2020 15:49, Andi McClure wrote:
I am building puredata via libpd on Android (a fork off 0.51/d5766fd0). I am doing this by loading the libpd CMakeLists.txt from my own CMakeLists invoked from gradle and then linking libpd in my Android app.
When it gets to the step of building libpd.so, it prints:
libpd/CMakeFiles/libpd.dir/pure-data/src/x_text.c.o: In function `text_define_sort':
/path/to/repo/deps/libpd/pure-data/src/x_text.c:552: undefined reference to `qsort_r'
I ran into this compiling libpd to run in the browser with Emscripten, ended up writing my own qsort_r that wraps qsort. I haven't tested it much though.?? There are a couple of follow-up commits so this diff isn't quite the whole story:
https://urldefense.com/v3/__https://github.com/claudeha/pure-data/commit/e80...
https://urldefense.com/v3/__https://github.com/pure-data/pure-data/issues/67... is an issue with a pull request, that's probably a bit nicer than my patched branch that is way behind upstream...
Maybe other systems than Emscripten and Android are broken, anyone using a BSD or Linux which doesn't use glibc for example?
I asked around about this, and was told a few things:
- Sometimes this kind of Android error magically goes away if you
fiddle with compileSdkVersion in gradle.
- There is a list in this git repo:
https://urldefense.com/v3/__https://android.googlesource.com/platform/bionic...
?? ??Of which libc symbols wind up in which binary in Android. However, in current Android master, qsort_r is not in this list at all. Only qsort.
- qsort_r is not a standard C function, it is a GNU thing,??so it's
possible Android really just doesn't have it. If Android really doesn't provide quicksort, it *might* be possible to fake qsort_r by adding a single C++ file which wraps std::sort (this was added in C++03 so Android *probably* has it), which doesn't have standard C qsort's reentrancy problem.
Claude
Pd-dev mailing list Pd-dev@lists.iem.at https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!...
It won't be thread-safe, which I believe you need to worry about in Android which is shot through with Java crappiness. I _think_ you can make MICROSOFT_STUPID_SORT work in a hreaded environment by declaring stupid_zkeyinfo as static per-thread.
But I wonder how on earth people are supposed to do this without wierd workarounds like that....
cheers Miller
On Tue, Oct 27, 2020 at 11:49:29AM -0400, Andi McClure wrote:
I am building puredata via libpd on Android (a fork off 0.51/d5766fd0). I am doing this by loading the libpd CMakeLists.txt from my own CMakeLists invoked from gradle and then linking libpd in my Android app.
When it gets to the step of building libpd.so, it prints:
libpd/CMakeFiles/libpd.dir/pure-data/src/x_text.c.o: In function `text_define_sort':
/path/to/repo/deps/libpd/pure-data/src/x_text.c:552: undefined reference to `qsort_r'
I asked around about this, and was told a few things:
- Sometimes this kind of Android error magically goes away if you fiddle
with compileSdkVersion in gradle.
- There is a list in this git repo:
https://urldefense.com/v3/__https://android.googlesource.com/platform/bionic... Of which libc symbols wind up in which binary in Android. However, in current Android master, qsort_r is not in this list at all. Only qsort.
- qsort_r is not a standard C function, it is a GNU thing, so it's possible
Android really just doesn't have it. If Android really doesn't provide quicksort, it *might* be possible to fake qsort_r by adding a single C++ file which wraps std::sort (this was added in C++03 so Android *probably* has it), which doesn't have standard C qsort's reentrancy problem.
I found I was able to make it compile with the following patch:
*diff --git a/src/x_text.c b/src/x_text.c*
*index 44bf9521..18f3d9de 100644*
*--- a/src/x_text.c*
*+++ b/src/x_text.c*
@@ -474,9 +474,9 @@ equal:
found in msvcrt (which indeed it isn't in). Rather than waste more time
on this, just call qsort if we're Microsoft and single-instance. I hope nobody
will try to compile multi-instance Pd for 32-bit windows, but if they
do, they might run into my qsort_s problem again. */
-#if defined(_WIN32) && !defined(PDINSTANCE)
+#if (defined(_WIN32) || defined(__ANDROID__)) && !defined(PDINSTANCE)
#define MICROSOFT_STUPID_SORT
static void *stupid_zkeyinfo;
static int stupid_sortcompare(const void *z1, const void *z2) {
return (text_sortcompare(z1, z2, stupid_zkeyinfo)); }
So although I'm not exactly sure what x_text.c is doing here, I am unblocked, I can proceed with my project as long as I don't need multi-instance. But, I'd like to know, is this a known problem? I find many references to people building PureData on Android but no one seems to have hit this issue. If there is a known working configuration for PureData on Android, what git revision of PureData was it building and what NDK compileSdkVersion? Alternately, is it possible the problem is not with my configuration, but with the libpd CMakeLists, and this problem would go away if I added the right #define or -l link argument?
And if this is a new problem: Would a patch to address this be welcome, and what approach would be preferred? Should I just submit a patch triggering MICROSOFT_STUPID_SORT when __ANDROID__ is present?
(I understand libpd is a different project from puredata and apologize if this is the wrong place to ask given I'm building libpd. However this seems (?) like a problem in the pure-data part of the code.)
Pd-dev mailing list Pd-dev@lists.iem.at https://urldefense.com/v3/__https://lists.puredata.info/listinfo/pd-dev__;!!...
FYI, this is now fixed on current master via https://github.com/pure-data/pure-data/commit/afb43ee827ee84ac79e1f03c56384d....
Christof
On 27.10.2020 16:49, Andi McClure wrote:
I am building puredata via libpd on Android (a fork off 0.51/d5766fd0). I am doing this by loading the libpd CMakeLists.txt from my own CMakeLists invoked from gradle and then linking libpd in my Android app.
When it gets to the step of building libpd.so, it prints:
libpd/CMakeFiles/libpd.dir/pure-data/src/x_text.c.o: In function `text_define_sort':
/path/to/repo/deps/libpd/pure-data/src/x_text.c:552: undefined reference to `qsort_r'
I asked around about this, and was told a few things:
- Sometimes this kind of Android error magically goes away if you
fiddle with compileSdkVersion in gradle.
- There is a list in this git repo:
https://android.googlesource.com/platform/bionic/+/master/libc/libc.map.txt https://android.googlesource.com/platform/bionic/+/master/libc/libc.map.txt Of which libc symbols wind up in which binary in Android. However, in current Android master, qsort_r is not in this list at all. Only qsort.
- qsort_r is not a standard C function, it is a GNU thing, so it's
possible Android really just doesn't have it. If Android really doesn't provide quicksort, it *might* be possible to fake qsort_r by adding a single C++ file which wraps std::sort (this was added in C++03 so Android *probably* has it), which doesn't have standard C qsort's reentrancy problem.
I found I was able to make it compile with the following patch:
*diff --git a/src/x_text.c b/src/x_text.c*
*index 44bf9521..18f3d9de 100644*
*--- a/src/x_text.c*
*+++ b/src/x_text.c*
@@ -474,9 +474,9 @@equal:
found in msvcrt (which indeed it isn't in).Rather than waste more time
on this, just call qsort if we're Microsoft and single-instance.I hope nobody
will try to compile multi-instance Pd for 32-bit windows, but if they
do, they might run into my qsort_s problem again. */
-#if defined(_WIN32) && !defined(PDINSTANCE)
+#if (defined(_WIN32) || defined(__ANDROID__)) && !defined(PDINSTANCE)
#define MICROSOFT_STUPID_SORT
static void *stupid_zkeyinfo;
static int stupid_sortcompare(const void *z1, const void *z2) {
return (text_sortcompare(z1, z2, stupid_zkeyinfo)); }
So although I'm not exactly sure what x_text.c is doing here, I am unblocked, I can proceed with my project as long as I don't need multi-instance. But, I'd like to know, is this a known problem? I find many references to people building PureData on Android but no one seems to have hit this issue. If there is a known working configuration for PureData on Android, what git revision of PureData was it building and what NDK compileSdkVersion? Alternately, is it possible the problem is not with my configuration, but with the libpd CMakeLists, and this problem would go away if I added the right #define or -l link argument?
And if this is a new problem: Would a patch to address this be welcome, and what approach would be preferred? Should I just submit a patch triggering MICROSOFT_STUPID_SORT when __ANDROID__ is present?
(I understand libpd is a different project from puredata and apologize if this is the wrong place to ask given I'm building libpd. However this seems (?) like a problem in the pure-data part of the code.)
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev