La carpeta cruzada de C ++ incluye fallas
Frecuentes
Visto 166 veces
1
I've got a project which has two source folders (main and lib). It produces a shared library and an executable. It is currently built as so:
- copy all files from both folders into a new temp folder
- run lib_makefile
- run main_makefile
- copy binaries out
- delete temp folder
This struck me as being a weird way to do things, so I tried building each in-place by adding -I../main
to lib_makefile (and vice-versa). Unfortunately, this doesn't seem to work.
Illustrative example: foo.cpp (in lib) includes bar.h (in main), which includes baz.h (back in lib).
When I try to compile the shared lib, it correctly locates bar.h in main/, but then bails out with "no such file or directory" claiming it cannot find baz.h, even though baz.h is in the same directory as lib_makefile!
All includes are in the format #include "xxx.h" (i.e no relative paths in the include statements).
Is there a way to get this to work? I feel like I must be missing something obvious..
(nb: I can't modify the #includes because other people still build this the copy-everything-across way)
1 Respuestas
5
Deberías agregar algo como -I../lib
(or whatever your library path is) to the makefile for the library as well.
The reason for this is that the pre-processor looks for include-files relative to the directory the corriente file is in, not from where the empresas de confitería el archivo está en formato.
Respondido 28 ago 12, 09:08
O simplemente -I.
since that's the same as -I../lib
cuando en el lib
dir- jonathan wakely
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c++ include or haz tu propia pregunta.
Have you tried also adding something like
-I../lib
to the library makefile too? - Some programmer dudeIt does include 'this directory' but when processing a file in
../main
that is 'this directory', not the one you ran make from - Jonathan Wakely