Can't compile with clock_gettime() fcn on Android

I’m trying to use the clock function in c++ code. I include time.h, and this doesn’t produce any error, but trying to use clock() or clock_gettime() produces this error when building for Android. This should be part of the NDK, does anybody know why it is failing?

[4527.23][878]MainFrameActions: Packaging (Android (ETC2)): UnrealBuildTool: C:/Users/Will/Source/Myproject/Source/Rift411/TCPConnection.cpp(47,2) :  error: use of undeclared identifier 'clock_gettime'
[4527.23][878]MainFrameActions: Packaging (Android (ETC2)): UnrealBuildTool: clock_gettime(CLOCK_REALTIME, &res);
[4527.24][879]MainFrameActions: Packaging (Android (ETC2)): UnrealBuildTool:         ^

Hello,

  • What version of the NDK are you currently using?
  • Does this occur in other versions as well, or is it only occurring in the Master branch? If you have not tested, please give that a shot and let me know.

NDK version is 11c, and I have NDK API level set to ‘android-19’ In the project settings.

I’m not really on the master branch, I’m in a modified 4.12 branch in a fork of the engine from the start of June, (the github master branch seemed like the closest option I could pick) and, because of some things I’ve added, I won’t be able to compile if I switch branches.

Is it possible that it’s including the (quite bare) “time.h” found in ‘android-ndk-r11c\sources\android\support\include’ and ignoring the ones in ‘android-ndk-r11c\platforms’ ?

Have you tried specifically including the time.h that is located in the platforms file path by including the file path instead of just the filename?

I’m still investigating this issue, but I just wanted to offer that suggestion in the meantime.

It does work if I specify the full path of time.h I want.

but both the time.h in platforms and the one in support are directly below their respective include folders, so I don’t know if I can specify one or the other without using a full path

It shouldn’t be an issue if you include both. Using the full path won’t cause you any issues, so you should be good to go.

Let me know if you have any other issues.

I found the cause of the trouble after some searching; I had a ‘time.h’ inside of my project’s Thirdparty, which I didn’t realize, and it didn’t have “#include_next time.h” in it. Sorry for the trouble