C/C++ relative #includes

2,525 views
Skip to first unread message

Mark Sibly

unread,
Aug 19, 2016, 11:23:34 PM8/19/16
to android-ndk
Hi,

I'm used to c/c++ compilers #including headers relative to the 'current' file, ie: the file that contains the #include.

However, this doesn't seem to be the case in the NDK. Stuff that compiles fine with mingw can't find all it's includes unless I make them all absolute.

What's the story here? Should I avoid relative #include altogether? Or is it perhaps #including stuff relative to the C/C++ file being compiled, and not the current header file?

Bye!
Mark

J Decker

unread,
Aug 20, 2016, 1:05:31 AM8/20/16
to andro...@googlegroups.com
I've never had such problems

#include "local.h"  // relative path to the current C/H file
#include <local.h> // skips locla path and checks -I paths...

-I specifies additional directories to check...


--
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+unsubscribe@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/11e93845-a3d9-42c5-beb5-c0721aee9f6f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Sibly

unread,
Aug 20, 2016, 4:08:06 PM8/20/16
to android-ndk
Ok, played around with this a bit more and there's definitely something going on, perhaps with the filename length. Here's my ndk-build output:

-------------------------------
D:\dev\monkey2\bananas\gridshooter\gridshooter.buildv1.0.3x\android_debug_windows
> ndk-build
[armeabi-v7a] Install        : libSDL2.so => libs/armeabi-v7a/libSDL2.so
[armeabi-v7a] Compile++ thumb: mx2_gridshooter <= gridshooter_gridshooter.cpp
cc1plus.exe: warning: command line option '-std=gnu99' is valid for C/ObjC but not for C++
In file included from jni/../src/../include/../../../../../modules/mojo/mojo.buildv1.0.3x/android_debug_windows/include/mojo_app_2wind
ow.h:9:0,
                 from jni/../src/../include/gridshooter_src_2renderwindow.h:10,
                 from jni/../src/../include/gridshooter_gridshooter.h:9,
                 from jni/../src/gridshooter_gridshooter.cpp:2:
jni/../src/../include/../../../../../modules/mojo/mojo.buildv1.0.3x/android_debug_windows/include/mojo_app_2view.h:9:95: fatal error:
../../../../monkey/monkey.buildv1.0.3x/android_debug_windows/include/monkey_types.h: No such file or directory
 #include "../../../../monkey/monkey.buildv1.0.3x/android_debug_windows/include/monkey_types.h"
                                                                                               ^
compilation terminated.
make: *** [obj/local/armeabi-v7a/objs-debug/mx2_gridshooter/__/src/gridshooter_gridshooter.o] Error 1
-------------------------------

...The file with the #include causing the problem is therefore here:

-------------------------------
> dir jni\..\src\..\include\..\..\..\..\..\modules\mojo\mojo.buildv1.0.3x\android_debug_windows\include\mojo_app_2view.h
 Volume in drive D is New Volume
 Volume Serial Number is 08F9-EDB9

 Directory of D:\dev\monkey2\modules\mojo\mojo.buildv1.0.3x\android_debug_windows\include

21/08/2016  07:26 AM             5,842 mojo_app_2view.h
               1 File(s)          5,842 bytes
               0 Dir(s)  876,724,064,256 bytes free
-------------------------------

Concatenting the relative #include path gives us:

-------------------------------
> dir jni\..\src\..\include\..\..\..\..\..\modules\mojo\mojo.buildv1.0.3x\android_debug_windows\include\..\..\..\..\monkey\monkey.buildv1.0.3x\android_debug_windows\include\monkey_types.h
The filename or extension is too long.
-------------------------------

Aha! Dos gives a 'filename or extension is too long' error here - but it's only 180-ish bytes, so it's a bit weird. This missing file is definitely there, and it all compiles fine on mingw/macos/linux/emscripten.

So I think this is either a bug or limitation of NDK, not that it doesn't work like c++. I think I'll rework the #include system - it's all a bit convoluted because it's transpiler output.

Another thing - how do I set '-std=-gnu99' for c files only without getting a warning? If I use CFLALGS, I get the above warning 'this only works with C', but if I use CPP_FLAGS it wont be used with C files at all.

Bye!
Mark
                                                                                                                                                             
On Saturday, August 20, 2016 at 5:05:31 PM UTC+12, J Decker wrote:
I've never had such problems

#include "local.h"  // relative path to the current C/H file
#include <local.h> // skips locla path and checks -I paths...

-I specifies additional directories to check...

On Fri, Aug 19, 2016 at 8:23 PM, Mark Sibly <blitz...@gmail.com> wrote:
Hi,

I'm used to c/c++ compilers #including headers relative to the 'current' file, ie: the file that contains the #include.

However, this doesn't seem to be the case in the NDK. Stuff that compiles fine with mingw can't find all it's includes unless I make them all absolute.

What's the story here? Should I avoid relative #include altogether? Or is it perhaps #including stuff relative to the C/C++ file being compiled, and not the current header file?

Bye!
Mark

--
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.
Reply all
Reply to author
Forward
0 new messages