Cross-compiling application and gcc using headers

2019-08-02 03:54发布

问题:

I'm attempting to cross-compile for an arm7 board using a toolchain on x86-64 Ubuntu. The headers I need are on the filesystem here:

.../include/<libdir1>
.../include/<libdir2>
[more]
.../include/<libdirN>

but the .../include directory contains incompatible standard headers (for reasons I can't control). Using -I option causes gcc to use these incompatible standard headers rather than the ones it should. Including all the compatible standard header paths with -I options prior to this also does not work.

I want to use the same source paths for when I'm compiling natively and also for the arm7 board:

#include <libdir1/lib1.h>
#include <libdir2/lib2.h>
...
#include <libdirN/libN.h>

Is there a way to do this using the filesystem as it currently exists or do I need to copy the lib1, lib2, ... libN header files somewhere else entirely?

回答1:

You could use the -iquote option for this:

Add the directory dir to the head of the list of directories to be searched for header files only for the case of #include "file"'; they are not searched for#include ', otherwise just like -I.

So you would include your custom headers with "" style include directives:

#include "libdir1/lib1.h"
#include "libdir2/lib2.h"

But the standard headers with <> style:

#include <stdlib.h>

And then add the directory with -iquote rather than -I:

-iquote../include