There is another way to check for input. I don't remember the specifics, but there is an offset from the 0 descriptor entry that can be tested. I'll see if I can poke thru the Linux source to locate it. I never used it because select() has worked on every unix platform I have tried...wgarvin wrote:My guess is that "select" is a socket function, and I guess Ares is trying to use it to detect if there is input available to be read.
But the uCLinux platform that compiler is for has been stripped down, and perhaps it does not include that function.
[Edit: the things removed from uCLinux are mostly things that can't be implemented without an MMU. Such as fork(). Sockets could probably be supported, but I don't know if it does.]
Compiling C++ for Android: select command
Moderator: Ras
-
bob
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: Compiling C++ for Android: select command
-
Jim Ablett
- Posts: 2453
- Joined: Fri Jul 14, 2006 7:56 am
- Location: London, England
- Full name: Jim Ablett
Re: Compiling C++ for Android: select command
CRoberson wrote:It is testing for input on stdin.wgarvin wrote:My guess is that "select" is a socket function, and I guess Ares is trying to use it to detect if there is input available to be read.
But the uCLinux platform that compiler is for has been stripped down, and perhaps it does not include that function.
[Edit: the things removed from uCLinux are mostly things that can't be implemented without an MMU. Such as fork(). Sockets could probably be supported, but I don't know if it does.]
If this can't be accomplished then that explains all the missing functionality in Android based Chess programs compared to the PC Chess programs.
Hi Charles,
I compiled Garbochess successfully for Android using the Codesourcery toolchain on Windows. Here is the code where Garbochess checks for input (and uses select).
Did you miss including <stdlib.h> ?
Code: Select all
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdio.h>
#include "garbochess.h"
/* Non-windows version */
bool CheckForPendingInput()
{
fd_set readfds;
struct timeval timeout;
FD_ZERO(&readfds);
FD_SET(fileno(stdin), &readfds);
/* Set to timeout immediately */
timeout.tv_sec = 0;
timeout.tv_usec = 0;
select(16, &readfds, 0, 0, &timeout);
return (FD_ISSET(fileno(stdin), &readfds));
}
-
abik
- Posts: 843
- Joined: Fri Dec 01, 2006 10:46 pm
- Location: Mountain View, CA, USA
- Full name: Aart Bik
Re: Compiling C++ for Android: select command
The NDK-based Android compiler has no issues with the select method either. Is the source of Ares available?
-
CRoberson
- Posts: 2096
- Joined: Mon Mar 13, 2006 2:31 am
- Location: North Carolina, USA
Re: Compiling C++ for Android: select command
Hi Jim,
I tried this example. It did not compile with the C++ compiler (it stated select not declared in this scope). When I changed test.cpp to test.c, it did compile with the C compiler. However, it did not link. The link error was can not find -lpthread and can not find -ldl. I took out lpthread and it still said can not find -ldl.
According to the getting started manual, you have to use a -T option to get it to link using some scripts. You didn't show that as needed in the "Dirty on Android" thread.
Here is the command line and the example.
arm-none-eabi-cc.exe -o test test.c -fomit-frame-pointer
-fexceptions -fstrict-aliasing -march=armv5te -O3
-Wno-deprecated -pipe -funroll-all-loops
-ffast-math -static -s -Wl,--whole-archive
-Wl,--no-whole-archive -lc -lm -ldl
I tried this example. It did not compile with the C++ compiler (it stated select not declared in this scope). When I changed test.cpp to test.c, it did compile with the C compiler. However, it did not link. The link error was can not find -lpthread and can not find -ldl. I took out lpthread and it still said can not find -ldl.
According to the getting started manual, you have to use a -T option to get it to link using some scripts. You didn't show that as needed in the "Dirty on Android" thread.
Here is the command line and the example.
arm-none-eabi-cc.exe -o test test.c -fomit-frame-pointer
-fexceptions -fstrict-aliasing -march=armv5te -O3
-Wno-deprecated -pipe -funroll-all-loops
-ffast-math -static -s -Wl,--whole-archive
-Wl,--no-whole-archive -lc -lm -ldl
Code: Select all
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdio.h>
int
main(void) {
fd_set rfds;
struct timeval tv;
int retval;
/* Watch stdin (fd 0) to see when it has input. */
FD_ZERO(&rfds);
FD_SET(0, &rfds);
/* Wait up to five seconds. */
tv.tv_sec = 5;
tv.tv_usec = 0;
retval = select(1, &rfds, NULL, NULL, &tv);
/* Don't rely on the value of tv now! */
if (retval == -1)
perror("select()");
else if (retval)
printf("Data is available now.\n");
/* FD_ISSET(0, &rfds) will be true. */
else
printf("No data within five seconds.\n");
return 0;
}
-
Michel
- Posts: 2292
- Joined: Mon Sep 29, 2008 1:50 am
Re: Compiling C++ for Android: select command
It seems you are using the bare metal toolchain. This means you have to implement everything yourself.arm-none-eabi-cc.exe
Normally people use the arm-linux toolchain.
-
trojanfoe
- Posts: 65
- Joined: Sun Jul 31, 2011 11:57 am
- Location: Waterlooville, Hampshire, UK
Re: Compiling C++ for Android: select command
poll()? It's basically a better select() but uses an array of file-descriptors and input/output event descriptors.bob wrote:There is another way to check for input. I don't remember the specifics, but there is an offset from the 0 descriptor entry that can be tested. I'll see if I can poke thru the Linux source to locate it. I never used it because select() has worked on every unix platform I have tried...wgarvin wrote:My guess is that "select" is a socket function, and I guess Ares is trying to use it to detect if there is input available to be read.
But the uCLinux platform that compiler is for has been stripped down, and perhaps it does not include that function.
[Edit: the things removed from uCLinux are mostly things that can't be implemented without an MMU. Such as fork(). Sockets could probably be supported, but I don't know if it does.]
-
Jim Ablett
- Posts: 2453
- Joined: Fri Jul 14, 2006 7:56 am
- Location: London, England
- Full name: Jim Ablett
Re: Compiling C++ for Android: select command
CRoberson wrote:Hi Jim,
I tried this example. It did not compile with the C++ compiler (it stated select not declared in this scope). When I changed test.cpp to test.c, it did compile with the C compiler. However, it did not link. The link error was can not find -lpthread and can not find -ldl. I took out lpthread and it still said can not find -ldl.
According to the getting started manual, you have to use a -T option to get it to link using some scripts. You didn't show that as needed in the "Dirty on Android" thread.
Here is the command line and the example.
arm-none-eabi-cc.exe -o test test.c -fomit-frame-pointer
-fexceptions -fstrict-aliasing -march=armv5te -O3
-Wno-deprecated -pipe -funroll-all-loops
-ffast-math -static -s -Wl,--whole-archive
-Wl,--no-whole-archive -lc -lm -ldl
Code: Select all
#include <stdlib.h> #include <unistd.h> #include <sys/time.h> #include <stdio.h> int main(void) { fd_set rfds; struct timeval tv; int retval; /* Watch stdin (fd 0) to see when it has input. */ FD_ZERO(&rfds); FD_SET(0, &rfds); /* Wait up to five seconds. */ tv.tv_sec = 5; tv.tv_usec = 0; retval = select(1, &rfds, NULL, NULL, &tv); /* Don't rely on the value of tv now! */ if (retval == -1) perror("select()"); else if (retval) printf("Data is available now.\n"); /* FD_ISSET(0, &rfds) will be true. */ else printf("No data within five seconds.\n"); return 0; }
Sorry Charles, Michael is right when he says you should be using the arm-linux toolchain. I gave incorrect example.
1. Download & install the correct Codesourcery toolchain for windows which is 'arm-2011.03-41-arm-none-linux-gnueabi.exe'
2. use 'arm-none-linux-gnueabi-g++.exe' or arm-none-linux-gnueabi-gcc.exe'
Jim.