raboof / nethogs

Linux 'net top' tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

quad_t doesn't exist in ndk

Zackptg5 opened this issue · comments

When cross-compiling for android using android ndk, quad_t isn't defined so errors out on me. v0.8.6 worked fine (pre quad-t addition). Is there any other way to do this so it'll be compatible with android ndk? Or am I stuck at this point?
cui.cpp:160:9: error: use of undeclared identifier 'index' if (index(progname, FILE_SEPARATOR) != NULL) { ^ cui.cpp:161:18: error: use of undeclared identifier 'rindex' progname = rindex(progname, FILE_SEPARATOR) + 1; ^ inode2prog.cpp:229:8: error: unknown type name 'quad_t'; did you mean 'uid_t'? static quad_t get_ms() { ^~~~~~ uid_t /home/zack/build_script/android-ndk-r23c/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/sys/types.h:45:17: note: 'uid_t' declared here typedef __uid_t uid_t; ^ inode2prog.cpp:232:22: error: unknown type name 'quad_t'; did you mean 'uid_t'? return static_cast<quad_t>(ts.tv_sec) * 1000 + ts.tv_nsec / 1000000; ^~~~~~ uid_t /home/zack/build_script/android-ndk-r23c/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/sys/types.h:45:17: note: 'uid_t' declared here typedef __uid_t uid_t; ^ 2 errors generated. make[1]: *** [MakeApp.mk:54: cui.o] Error 1 make[1]: *** Waiting for unfinished jobs.... inode2prog.cpp:256:10: error: unknown type name 'quad_t'; did you mean 'uid_t'? static quad_t last_ms = 0; ^~~~~~ uid_t /home/zack/build_script/android-ndk-r23c/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/sys/types.h:45:17: note: 'uid_t' declared here typedef __uid_t uid_t; ^ inode2prog.cpp:257:3: error: unknown type name 'quad_t'; did you mean 'uid_t'? quad_t start_ms = 0; ^~~~~~ uid_t /home/zack/build_script/android-ndk-r23c/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/sys/types.h:45:17: note: 'uid_t' declared here typedef __uid_t uid_t; ^ 4 errors generated.

When cross-compiling for android using android ndk

Cool, I never realized anyone would do that :D

Is there any other way to do this so it'll be compatible with android ndk

I'm sure you could fall back to some other data type where quad_t is unavailable /cc @takeoverjp

Your errors also suggest index/rindex aren't available. Is that just a matter of missing an import of or is that really not available when compiling for Android? /cc @sgtcortez

index** and rindex are part of strings.h header.
Which I have added on commit.

Perhaps, android does not provide those functions at all, or provide something similar with another name.
If not available, we might create header guards to check for the platform, and, if not present, create those functions.
They are not difficult at all.

_i_ndex** and rindex are part of strings.h header. Which I have added on commit.

Perhaps, android does not provide those functions at all, or provide something similar with another name. If not available, we might create header guards to check for the platform, and, if not present, create those functions. They are not difficult at all.

index and rindex aren't present in ndk strings.h header (or anywhere else in include) so they'll need created. Adding:
char *index(const char *, int); char *rindex(const char *, int);
Seemed to fix the index/rindex compile error. quad_t looks like it'll be more complicated

_i_ndex** and rindex are part of strings.h header. Which I have added on commit.
Perhaps, android does not provide those functions at all, or provide something similar with another name. If not available, we might create header guards to check for the platform, and, if not present, create those functions. They are not difficult at all.

index and rindex aren't present in ndk strings.h header (or anywhere else in include) so they'll need created. Adding: char *index(const char *, int); char *rindex(const char *, int); Seemed to fix the index/rindex compile error.

Hmm, you didn't need to provide an implementation? That's slightly scary :)

quad_t looks like it'll be more complicated

Perhaps you can use some #if to detect systems that don't have this type, and then use #define to provide a replacement type?

Perhaps you can use some #if to detect systems that don't have this type, and then use #define to provide a replacement type?

Not sure, might be easier to write a function with other name, and use it.

And, would be nice to add ci to make this types of builds to make sure that a commit will works for different systems.

Update on this issue. Haven't found a fix for quad_t other than removing the garbage collecting stuff altogether. However, found that just defining index like I did didn't work. What I did find was that android ndk, while not having index or rindex, does have strchr and strrchr so just replacing them accordingly was all I needed there. Could you do the same since index is legacy?

NDK doesn't have strings.h but newer string.h

void* memcpy(void* restrict s1, const void* restrict s2, size_t n);
void* memmove(void* s1, const void* s2, size_t n);
char* strcpy (char* restrict s1, const char* restrict s2);
char* strncpy(char* restrict s1, const char* restrict s2, size_t n);
char* strcat (char* restrict s1, const char* restrict s2);
char* strncat(char* restrict s1, const char* restrict s2, size_t n);
int memcmp(const void* s1, const void* s2, size_t n);
int strcmp (const char* s1, const char* s2);
int strncmp(const char* s1, const char* s2, size_t n);
int strcoll(const char* s1, const char* s2);
size_t strxfrm(char* restrict s1, const char* restrict s2, size_t n);
const void* memchr(const void* s, int c, size_t n);
      void* memchr(      void* s, int c, size_t n);
const char* strchr(const char* s, int c);
      char* strchr(      char* s, int c);
size_t strcspn(const char* s1, const char* s2);
const char* strpbrk(const char* s1, const char* s2);
      char* strpbrk(      char* s1, const char* s2);
const char* strrchr(const char* s, int c);
      char* strrchr(      char* s, int c);
size_t strspn(const char* s1, const char* s2);
const char* strstr(const char* s1, const char* s2);
      char* strstr(      char* s1, const char* s2);
char* strtok(char* restrict s1, const char* restrict s2);
void* memset(void* s, int c, size_t n);
char* strerror(int errnum);
size_t strlen(const char* s);