From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: Qun-Ying Newsgroups: comp.lang.ada Subject: Re: GPS: Including C headers from paths which are not configured in Source_Dirs Date: Thu, 8 Oct 2015 11:11:39 -0700 Organization: Aioe.org NNTP Server Message-ID: References: <8a324b12-4774-4a73-9e6e-c2b87d80f4e8@googlegroups.com> NNTP-Posting-Host: QG+sVfyUW3QoXBz9uF2CgQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0 SeaMonkey/2.38 X-Notice: Filtered by postfilter v. 0.8.2 X-Enigmail-Draft-Status: N1110 Xref: news.eternal-september.org comp.lang.ada:27941 Date: 2015-10-08T11:11:39-07:00 List-Id: 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 > #include "common/bla_other.h" > > void putOhmy (void) { > putOhmyOther(); > } > > --outsiders/common/bla_other.h > void putOhmyOther(); > > --outsiders/common/bla_other.c > #include > #include > > 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.