glob.h and glob.c for the Android NDK

5283 views
Skip to first unread message

Gabor Cselle

unread,
Mar 3, 2011, 3:09:20 PM3/3/11
to android-ndk
glob.h and glob.c are not included in the Android NDK, and a bunch of
posters have asked for them in the past, e.g.:
http://groups.google.com/group/android-ndk/browse_thread/thread/26bd9c02574aa033/
http://groups.google.com/group/android-ndk/browse_thread/thread/8f17b42525b9c3fa/

I massaged a FreeBSD glob.c/glob.h into something that compiles onto
Android. (Thx to David Turner who provided me with the original
files.)

You can find them here:
http://www.gaborcselle.com/open_source/android/ndk/glob/glob.c
http://www.gaborcselle.com/open_source/android/ndk/glob/glob.h

Hope you find these useful.

Gabor

JM Krishna

unread,
Mar 16, 2012, 12:53:39 AM3/16/12
to andro...@googlegroups.com
Hi,
I am not able to download glob.c and glob.h files.
Links provided are not working.Can u please provide the files.
Thanks in advance.
Regards,
JMKrishna

white_gecko

unread,
Mar 17, 2012, 2:24:14 PM3/17/12
to andro...@googlegroups.com
Hi,
I have adopted a version of glob.h and glob.c from FreeBSD to compile for Android. You can find them in my github:
https://github.com/white-gecko/TokyoCabinet

https://github.com/white-gecko/TokyoCabinet/raw/master/glob.c
and
https://github.com/white-gecko/TokyoCabinet/raw/master/glob.h

Nate

Yuri Andronachi

unread,
Oct 30, 2012, 6:10:43 AM10/30/12
to andro...@googlegroups.com
And where should i put them?

erik...@gmail.com

unread,
Aug 1, 2013, 6:02:29 AM8/1/13
to andro...@googlegroups.com
Just wanted to update this thread with some information on how I solved it for libxml2.
I downloaded glob.c/.h from white_gecko above and put them in my lib's top folder before compiling glob.c using the arm gcc compiler:

$ arm-linux-androideabi-gcc -c -I. glob.c

Then I changed the .o file to be world-executable (chmod +x glob.o) and added it to my LIBS env variable (export LIBS=/tmp/libxml2/glob.o).
I then ran ./configure again (according to http://mortoray.com/2012/08/21/android-ndk-cross-compile-setup-libpng-and-freetype/) and compiled it using "make".
Compiling and tests worked fine after this (before "runtests" would fail beacuse of missing glob.c/.h).

Thanks white_gecko for the glob files!

Regards,
Erik

Stephan Hagios

unread,
Oct 7, 2013, 8:09:56 AM10/7/13
to andro...@googlegroups.com
I also try to compile libxml2 for Android, but it doesn't work for me.
It stops at the configure part, saying that the C compiler isn't working.

Erik it would be nice if you can provide the compiled libxml2 binaries.

Greetings
Stephan

Jeffrey Walton

unread,
Oct 7, 2013, 1:30:02 PM10/7/13
to Android NDK List
On Mon, Oct 7, 2013 at 8:09 AM, Stephan Hagios
<stephan...@googlemail.com> wrote:
> I also try to compile libxml2 for Android, but it doesn't work for me.
> It stops at the configure part, saying that the C compiler isn't working.
Yeah, configure tries to execute the ARM binary (target) on my local
machine (host). That won't work.

Does anyone know how to make aututools recognize its a cross compile?
`./configure --host=arm` does not seem work as expected/advertised:

$ echo $PATH
/opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin:/opt/android-sdk-macosx/tools/:/opt/android-sdk-macosx/platform-tools/:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/MacGPG2/bin


$ echo $ANDROID_NDK_ROOT
/opt/android-ndk-r9


$ export CPP=arm-linux-androideabi-cpp
$ export CC=arm-linux-androideabi-gcc
...
$ export LD=arm-linux-androideabi-ld


$ echo $ANDROID_SYSROOT
--sysroot=/opt/android-ndk-r9/platforms/android-14/arch-arm
$ export CFLAGS="--sysroot=$ANDROID_SYSROOT"
$ export CXXFLAGS="--sysroot=$ANDROID_SYSROOT"
...


$ ./configure --host=arm
checking build system type... i386-apple-darwin12.5.0
checking host system type... arm-unknown-none
...
checking how to run the C preprocessor... arm-linux-androideabi-cpp
configure: error: in `/Users/jwalton/Desktop/libxml2-2.9.1':
configure: error: C preprocessor "arm-linux-androideabi-cpp" fails sanity check
See `config.log' for more details


$ cat config.log
...
configure:3612: checking whether we are cross compiling
configure:3620: arm-linux-androideabi-gcc -o conftest
--sysroot=/opt/android-ndk-r9/platforms/android-14/arch-arm
conftest.c >&5
configure:3624: $? = 0
configure:3631: ./conftest
./configure: line 3633: ./conftest: cannot execute binary file
configure:3635: $? = 126
configure:3642: error: in `/Users/jwalton/Desktop/libxml2-2.9.1':
configure:3644: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.

And sorry to jump in. I've been meaning to cross compile libxml for my
projects, and it seemed like a good time.

Jeff

erik...@gmail.com

unread,
Oct 7, 2013, 3:43:27 PM10/7/13
to andro...@googlegroups.com
Hi Stephan,

I don't have the binary available anymore. However, I think you might be able to follow the instructions (some reverse engineering of PATHs might be necessary) on the link below to compile libxml2 for Android.
Though, I haven't tested my self I am pretty sure the author got it working with the Android NDK.

Regards,
Erik

Stephan Hagios

unread,
Oct 8, 2013, 5:01:10 AM10/8/13
to andro...@googlegroups.com
Hey Erik,

thank you for the link, helped me a lot.
Now I was able to build libxml2 for Android.
I created a Script which worked for me.

Greetings
Stephan

Luca Weiss

unread,
Oct 9, 2016, 6:37:27 PM10/9/16
to android-ndk

xinfa tang

unread,
Aug 12, 2018, 8:48:27 PM8/12/18
to android-ndk
Update NDK to r17-beta2, set API Level to 28, glob's problem is fixed.

在 2011年3月4日星期五 UTC+8上午4:09:20,Gabor Cselle写道:

Dan Albert

unread,
Aug 13, 2018, 12:19:00 AM8/13/18
to android-ndk
But note that your minSdkVersion will then be 28.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/e3db19c0-dcc4-4ef6-9b73-c4ad2de64e6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Harindu Sugathadasa

unread,
Feb 20, 2019, 3:49:59 AM2/20/19
to android-ndk
I need to keep minSdkVersion as 22. However, this setting does not enable glob functionality. How do I figure out it?
I use Android SDK as 27 and NDK version as 19.

CONFIDENTIALITY NOTICE:

This e-mail, including any attachment, is confidential and may contain legally privileged information. If you are not the intended recipient, copying, distributing, disclosing or use of the information contained herein is strictly prohibited. Please e-mail the sender immediately and delete this message from your system.

John Dallman

unread,
Feb 20, 2019, 8:39:50 AM2/20/19
to andro...@googlegroups.com
What errors do you get compiling with API 22? 

If the glob code you have requires functions that aren't available at API 22, then the only recourse is to write a glob that does work with API 22's available functions. 

John


Harindu Sugathadasa

unread,
Feb 20, 2019, 9:56:08 AM2/20/19
to android-ndk
First I ran the code with use of #include<glob.h>. In my code, glob() and globfree() is used. However, after getting such functions cannot be accessed due to ANDROID API level is equal or greater than 28, I get third party glob.c and glob.h files and then used to build the project. In glob.c source file, the function "issetguid()" does not working and error in Android build terminal shows as like this; "warning: implicit declaration of function 'issetguid' is invalid in C99 [-Wimplicit-function-declaration] if (issetguid() != 0 ||". How do I figure out this issue? I could not able to find best answer from google. Does any function available to replace this function? Thanks in advance.

John Dallman

unread,
Feb 20, 2019, 10:36:38 AM2/20/19
to andro...@googlegroups.com
Could you post the glob.c and glob.h files? They aren't at the original links any more, and I can't find any references to "issetguid()" on the net - are you sure you transcribed the name correctly? 

John

Harindu Sugathadasa

unread,
Feb 20, 2019, 9:21:44 PM2/20/19
to android-ndk
Sure. I have attached both files and links that I found on here. The function I mentioned is under "globtilde()" function. 
Some of the #ifdef are removed by myself. Please look at the original links. Thanks in advance.
glob.c
glob.h

John Dallman

unread,
Feb 22, 2019, 8:26:29 AM2/22/19
to andro...@googlegroups.com
To make the situation explicit, the glob() and globfree() functions are available in Android API 28 and later, but the OP needs to run on API 22. The glob.c and glob.h files contain an implementation of glob and globfree based on the BSD implementation. However, that uses the issetugid() function, which Android API 22 lacks. Here's the BSD documentation for that function: https://www.freebsd.org/cgi/man.cgi?query=issetugid&sektion=2

The author of the glob.c and glob.h files said they'd been modified to compile on Linux, but I can't find any evidence that this has ever been a glibc function, although I'm not an expert. However, I have found something that looks useful for the OP's purposes:


This contains a trivial implementation of the function that claims to be adequate for bionic. Since Android basically doesn't use setuid/setgid facilities (https://source.android.com/security/enhancements/enhancements43), that claim seems plausible to me. So if you add the issetugid.c file from the link above to your project, create a header file called issetugid.h containing:

/* Declare issetugid */
extern int issetugid( void); 
/* End of issetugid.h */ 

and add it to your project, then insert the line 

#include "issetugid.h" 

into your glob.c file, between the #includes for unistd.h and wchar.h, thus:
#include <unistd.h>
#include "issetguid.h" /* Note quotes, not angle brackets */ 
#include <wchar.h>
Then you may well get some success. 

John

Reply all
Reply to author
Forward
0 new messages