* GPS: Including C headers from paths which are not configured in Source_Dirs
@ 2015-10-08 14:32 Rego, P.
2015-10-08 15:29 ` Simon Wright
0 siblings, 1 reply; 5+ messages in thread
From: Rego, P. @ 2015-10-08 14:32 UTC (permalink / raw)
In a project I have Ada and C files, for example, ohmy.adb, and bla.c and bla.h, and some other files which are not listed in this Ada main project. For simplicity,
project Test is
for Languages use ("Ada", "C");
for Source_Dirs use (".");
for Main use ("ohmy.adb");
end Test;
In bla.c I have an include
#include "tools/mytool.h"
But directory 'tools' is not configured in Source_Dirs, so it does not find mytool.h. How can I configure GPS to understand this type of include "tools/mytool.h" (instead of including 'tools' in Source_Dirs and including the file using #include "mytool.h")?
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: GPS: Including C headers from paths which are not configured in Source_Dirs
2015-10-08 14:32 GPS: Including C headers from paths which are not configured in Source_Dirs Rego, P.
@ 2015-10-08 15:29 ` Simon Wright
2015-10-08 16:51 ` Rego, P.
0 siblings, 1 reply; 5+ messages in thread
From: Simon Wright @ 2015-10-08 15:29 UTC (permalink / raw)
"Rego, P." <pvrego@gmail.com> writes:
> project Test is
> for Languages use ("Ada", "C");
> for Source_Dirs use (".");
> for Main use ("ohmy.adb");
> end Test;
>
> In bla.c I have an include
> #include "tools/mytool.h"
>
> But directory 'tools' is not configured in Source_Dirs, so it does not
> find mytool.h. How can I configure GPS to understand this type of
> include "tools/mytool.h" (instead of including 'tools' in Source_Dirs
> and including the file using #include "mytool.h")?
package Compiler is
for Switches ("C") use ("-I/your/include/dir");
end Compiler;
But why are you using #include "tools/mytool.h" rather than #include
<tools/mytools.h>? (I've never understood why VxWorks uses this style).
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: GPS: Including C headers from paths which are not configured in Source_Dirs
2015-10-08 15:29 ` Simon Wright
@ 2015-10-08 16:51 ` Rego, P.
2015-10-08 18:11 ` Qun-Ying
2015-10-08 20:49 ` Simon Wright
0 siblings, 2 replies; 5+ messages in thread
From: Rego, P. @ 2015-10-08 16:51 UTC (permalink / raw)
On Thursday, October 8, 2015 at 12:29:32 PM UTC-3, Simon Wright wrote:
> package Compiler is
> for Switches ("C") use ("-I/your/include/dir");
> end Compiler;
It did not work, maybe I did wrong. I built a test code to analyze better.
--test.gpr
project Test is
for Languages use ("Ada", "C");
for Source_Dirs use (".");
for Main use ("ohmy.adb");
package Compiler is
for Switches ("C") use ("-Ioutsiders");
end Compiler;
end Test;
--ohmy.adb
procedure Ohmy is
procedure Put_Ohmy;
pragma Import (C, Put_Ohmy, "putOhmy");
begin
Put_Ohmy;
end Ohmy;
--bla.h
void putOhmy(void);
--bla.c
#include <bla.h>
#include "common/bla_other.h"
void putOhmy (void) {
putOhmyOther();
}
--outsiders/common/bla_other.h
void putOhmyOther();
--outsiders/common/bla_other.c
#include <bla_other.h>
#include <stdio.h>
void putOhmyOther(){
printf("Ohmy");
}
In this case, the built returns the error message:
> gprbuild -d -Ptest.gpr ohmy.adb
> gcc ohmy.o -o ohmy.exe
> libtest.a(bla.o):bla.c:(.text+0x7): undefined reference to `putOhmyOther'
> collect2.exe: error: ld returned 1 exit status
> gprbuild: link of ohmy.adb failed
> [2015-10-08 13:38:54] process exited with status 4, 100% (2/2), elapsed time: 03.94s
Realize that the folder 'outsiders' is included in project, so (I guess) its subfolders should be accessible by an include like '#include "common/bla_other.h"' (?) So what did I do wrong?
Thanks.
>
> But why are you using #include "tools/mytool.h" rather than #include
> <tools/mytools.h>? (I've never understood why VxWorks uses this style).
Actually I don't know. It's a (big) legacy code, so I'd rather not changing this (if possible).
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: GPS: Including C headers from paths which are not configured in Source_Dirs
2015-10-08 16:51 ` Rego, P.
@ 2015-10-08 18:11 ` Qun-Ying
2015-10-08 20:49 ` Simon Wright
1 sibling, 0 replies; 5+ messages in thread
From: Qun-Ying @ 2015-10-08 18:11 UTC (permalink / raw)
Rego, P. wrote:
> On Thursday, October 8, 2015 at 12:29:32 PM UTC-3, Simon Wright wrote:
>> package Compiler is
>> for Switches ("C") use ("-I/your/include/dir");
>> end Compiler;
>
> It did not work, maybe I did wrong. I built a test code to analyze better.
>
> --test.gpr
> project Test is
> for Languages use ("Ada", "C");
> for Source_Dirs use (".");
> for Main use ("ohmy.adb");
>
> package Compiler is
> for Switches ("C") use ("-Ioutsiders");
> end Compiler;
>
> end Test;
>
> --ohmy.adb
> procedure Ohmy is
> procedure Put_Ohmy;
> pragma Import (C, Put_Ohmy, "putOhmy");
> begin
> Put_Ohmy;
> end Ohmy;
>
> --bla.h
> void putOhmy(void);
>
> --bla.c
> #include <bla.h>
> #include "common/bla_other.h"
>
> void putOhmy (void) {
> putOhmyOther();
> }
>
> --outsiders/common/bla_other.h
> void putOhmyOther();
>
> --outsiders/common/bla_other.c
> #include <bla_other.h>
> #include <stdio.h>
>
> void putOhmyOther(){
> printf("Ohmy");
> }
>
> In this case, the built returns the error message:
>> gprbuild -d -Ptest.gpr ohmy.adb
>> gcc ohmy.o -o ohmy.exe
>> libtest.a(bla.o):bla.c:(.text+0x7): undefined reference to `putOhmyOther'
>> collect2.exe: error: ld returned 1 exit status
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Your program compile fine, it include your header file without problem,
but failed on linking.
As putOhmyOther is defined in common/bla_other.c, which is not compiled
in your project.
>> gprbuild: link of ohmy.adb failed
>> [2015-10-08 13:38:54] process exited with status 4, 100% (2/2), elapsed time: 03.94s
>
> Realize that the folder 'outsiders' is included in project, so (I guess)
> its subfolders should be accessible by an include like
> '#include "common/bla_other.h"' (?) So what did I do wrong?
If you are linking with 3rd party C lib, not only do you need to include
the header file, you also need to link with its lib.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: GPS: Including C headers from paths which are not configured in Source_Dirs
2015-10-08 16:51 ` Rego, P.
2015-10-08 18:11 ` Qun-Ying
@ 2015-10-08 20:49 ` Simon Wright
1 sibling, 0 replies; 5+ messages in thread
From: Simon Wright @ 2015-10-08 20:49 UTC (permalink / raw)
"Rego, P." <pvrego@gmail.com> writes:
> On Thursday, October 8, 2015 at 12:29:32 PM UTC-3, Simon Wright wrote:
>> package Compiler is
>> for Switches ("C") use ("-I/your/include/dir");
>> end Compiler;
>
> It did not work, maybe I did wrong. I built a test code to analyze better.
>
> --test.gpr
> project Test is
> for Languages use ("Ada", "C");
> for Source_Dirs use (".");
> for Main use ("ohmy.adb");
>
> package Compiler is
> for Switches ("C") use ("-Ioutsiders");
> end Compiler;
>
> end Test;
>
> --ohmy.adb
> procedure Ohmy is
> procedure Put_Ohmy;
> pragma Import (C, Put_Ohmy, "putOhmy");
> begin
> Put_Ohmy;
> end Ohmy;
>
> --bla.h
> void putOhmy(void);
>
> --bla.c
> #include <bla.h>
> #include "common/bla_other.h"
>
> void putOhmy (void) {
> putOhmyOther();
> }
This clearly worked as intended, because bla.c got compiled.
> --outsiders/common/bla_other.h
> void putOhmyOther();
>
> --outsiders/common/bla_other.c
> #include <bla_other.h>
> #include <stdio.h>
>
> void putOhmyOther(){
> printf("Ohmy");
> }
But ..
> In this case, the built returns the error message:
>> gprbuild -d -Ptest.gpr ohmy.adb
>> gcc ohmy.o -o ohmy.exe
>> libtest.a(bla.o):bla.c:(.text+0x7): undefined reference to `putOhmyOther'
>> collect2.exe: error: ld returned 1 exit status
>> gprbuild: link of ohmy.adb failed
>> [2015-10-08 13:38:54] process exited with status 4, 100% (2/2),
>> elapsed time: 03.94s
This is telling you that outsiders/common/bla_other.o never got included
in the link (probably never got compiled, either).
I take it that the outsiders directory corresponds to an
externally-built C library in your real application? Perhaps you could
represent it as a GPR of its own?
library project Outsiders is
for Library_Name use "outsiders";
for Library_Kind use "static";
for Library_Dir use project'Project_Dir & "src";
for Source_Dirs use project'Project_Dir & "include";
for Externally_Built use "true";
end Outsiders;
and then your test.gpr might say
with Outsiders;
project Test is
for Languages use ("Ada", "C");
for Source_Dirs use (".");
for Main use ("ohmy.adb");
package Compiler is
for Switches ("C") use ("-I" & Outsiders'Source_Dirs);
end Compiler;
end Test;
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-10-08 20:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-08 14:32 GPS: Including C headers from paths which are not configured in Source_Dirs Rego, P.
2015-10-08 15:29 ` Simon Wright
2015-10-08 16:51 ` Rego, P.
2015-10-08 18:11 ` Qun-Ying
2015-10-08 20:49 ` Simon Wright
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox