f



Can I get rid of C libraries dependencies?

Okey, so I wrote this code:

pragma No_Run_Time;

with Interfaces.C.Strings;
use  Interfaces.C.Strings;
with Interfaces.C;
use  Interfaces.C;

procedure Main is
   procedure cputs(str:Char_Array);
   pragma Import(C, cputs, "puts");
   
   procedure cexit(code:Integer);
   pragma Import(C, cexit, "exit");
begin
   cputs("Hello World!");
   cexit(0);
end Main;

What I want to achive is a tiny 2kb binary executable 
with a single function called as entry point (which is 
defined in Ada and called Main procedure). The pragma 
on top let me get rid of the huge RTL code that is written
in Ada. However I'm still getting a lot of code linked 
in from C libraries, so...

1) Can I get rid of the C code linked in?
2) What is implemented in thoose C libraries?
3) Can I use Ada's RTL library without the C 
   support code, if I use some Restrictions?
0
Leff
9/16/2015 12:55:23 PM
comp.lang.ada 8774 articles. 2 followers. Post Follow

5 Replies
320 Views

Similar Articles

[PageSpeed] 1

On 2015-09-16, Leff Ivanov <droiddermo@gmail.com> wrote:
>
> What I want to achive is a tiny 2kb binary executable 
> with a single function called as entry point (which is 
> defined in Ada and called Main procedure). The pragma 
> on top let me get rid of the huge RTL code that is written
> in Ada. However I'm still getting a lot of code linked 
> in from C libraries, so...
>
> 1) Can I get rid of the C code linked in?
> 2) What is implemented in thoose C libraries?
> 3) Can I use Ada's RTL library without the C 
>    support code, if I use some Restrictions?

The basic problem here is that the C API _is_ considered to be the
interface to the OS for this kind of thing on Linux/Unix and
(these days) probably Windows as well[*].

Unless you call the operating system services directly then at
some level either you, or the Ada RTL acting on your behalf, has
to call the C API.

It is possible to call the OS services directly (once you understand
how the interface is implemented for each OS and architecture
combination), but is this really a road that it's wise to do down ?

Simon.

[*] I have a VMS background and it's a lot easier to do this kind
of thing there. Unfortunately, I doubt you are running VMS. :-)

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world
0
Simon
9/16/2015 1:44:25 PM
On 16.09.15 14:55, Leff Ivanov wrote:
> 3) Can I use Ada's RTL library without the C
>     support code, if I use some Restrictions?

Maybe, depending on the restrictions. Also, depending on how
the object code is to be installed: there is a documented
way to use a C main, not an Ada main; if this, in spite
of mentioning C, can mean that you just call the object
code using C conventions, then linking need not be done at
the Ada tools chain's end. If your object code is guaranteed
not to require Ada RT support, it should work, I think.

Some bits of a reduced RTS may be ready for inspection
with implementations of GNAT for smaller computers
(incl. no OS, IIRC). I'd start by looking for ARM, Cortex,
STM32, Atmega, ...

0
G
9/16/2015 2:20:56 PM
Leff Ivanov <droiddermo@gmail.com> writes:

> What I want to achive is a tiny 2kb binary executable 

Can you tell us a little more about why you need to do this, what OS
you're using ...
0
Simon
9/16/2015 4:13:09 PM
=D1=81=D1=80=D0=B5=D0=B4=D0=B0, 16 =D1=81=D0=B5=D0=BD=D1=82=D1=8F=D0=B1=D1=
=80=D1=8F 2015 =D0=B3., 19:13:11 UTC+3 =D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=
=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C Simon Wright =D0=BD=D0=B0=D0=BF=D0=B8=
=D1=81=D0=B0=D0=BB:
> Leff Ivanov <droiddermo@gmail.com> writes:
>=20
> > What I want to achive is a tiny 2kb binary executable=20
>=20
> Can you tell us a little more about why you need to do this, what OS
> you're using ...

I'm using windows and want to write tiny tools in Ada like I can=20
write one in C/C++ using -nostdlib flag and directly linking to
OS specific libraries. The same can be applied to Linux and Mac
OSX as well, but currently I'm focusing on Windows.

If I do "gnatmake -a -f -nostdlib main.adb" I can see that GNAT
actually recompiles a lot of stuff from RTS, like a-except.adb,
s-secsta.abd and etc. So the No_Run_Time pragma cuts off only
a part of Ada RTS, but leaves the rest.

Gnatlink tool with -nostdlib returns a lot of undefined references
to C code, which I want to get rid off. It seems that mostly it is
functions that implements exceptions, like _Unwind_SjLj_Register,
__gnat_personality_sj0 and etc.=20

Undefined references to stuff like memmove and memcmp I can simply
fix by linking directly with libmsvcrt.a, so theese functions would
be taked from standard windows msvcrt.dll library. But there's also=20
undefined reference to __chkstk_ms, this function seem to check if=20
the stack is full. This function is MinGW specific and there is no implemen=
tation in standard windows libraries.
0
Leff
9/17/2015 8:13:47 AM
On Thu, 17 Sep 2015 01:13:47 -0700, Leff Ivanov wrote:

> среда, 16 сентября 2015 г., 19:13:11 UTC+3 пользователь Simon Wright
> написал:
>> Leff Ivanov <droiddermo@gmail.com> writes:
>> 
>> > What I want to achive is a tiny 2kb binary executable
>> 
>> Can you tell us a little more about why you need to do this, what OS
>> you're using ...
> 
> I'm using windows and want to write tiny tools in Ada like I can write
> one in C/C++ using -nostdlib flag and directly linking to OS specific
> libraries. The same can be applied to Linux and Mac OSX as well, but
> currently I'm focusing on Windows.
> 
> If I do "gnatmake -a -f -nostdlib main.adb" I can see that GNAT actually
> recompiles a lot of stuff from RTS, like a-except.adb,
> s-secsta.abd and etc. So the No_Run_Time pragma cuts off only a part of
> Ada RTS, but leaves the rest.
> 
> Gnatlink tool with -nostdlib returns a lot of undefined references to C
> code, which I want to get rid off. It seems that mostly it is functions
> that implements exceptions, like _Unwind_SjLj_Register,
> __gnat_personality_sj0 and etc.

There are pragmas to restrict the use of exceptions : these should reduce 
the undefined references.
 
> Undefined references to stuff like memmove and memcmp I can simply fix
> by linking directly with libmsvcrt.a, so theese functions would be taked
> from standard windows msvcrt.dll library.  But there's also undefined
> reference to __chkstk_ms, this function seem to check if the stack is
> full. 

One way is to specify your own RTS, with the "--RTS=path/to/rts" option. 
Then you would need to create your own RTS, which in this case would be 
your wrapper that handles anything you can't link directly like memcpy 
etc. You can get a handle on how this works by studying the AVR-Ada 
microcontroller port, which is quite capable of generating executables 
down to a couple of hundred bytes.

-- Brian
0
Brian
9/17/2015 10:25:23 AM
Reply:

Similar Artilces:

Can someone who doesn't know C ever hope to write thick bindings for a C library to Ada?
Okay, so I *sort of* know C, but I'm by no means an expert or proficient in= it. I sort of know it in that I can kinda sort follow well commented C cod= e. Earlier I posted about thick SDL bindings, and another person asked if i= t were possible to utilize C2Ada without knowing C, my question is sort of = in between. Is it possible to write thick bindings from auto-generated C bi= ndings (using GNAT) without really knowing C very well? On Sunday, September 29, 2013 2:28:45 PM UTC-6, Kevin Keith wrote: > Okay, so I *sort of* know C, but I'm by no means an expert or profici...

where can i get the c library source code
Hi , can any one please help me to get the source code of the c library ( stdio.h , stdlib.h ....) .... Thanks in advance Prashanth ( Man who saw the end of war ) Prashanth Badabagni wrote: > Hi , > can any one please help me to get the source code of the c library > ( stdio.h , stdlib.h ....) .... > > Thanks in advance > Prashanth ( Man who saw the end of war ) There is no such thing as *the C library*; there are, however, several implementations. If you work with an open source platform, there's no problem -- just Google for it. If you don't, you&#...

Where can i get a opensource C++ NeuralNetwork library?
hi, there. i want to write a neuralnet program in c++, where can i get a opensource c++ neural net library to facilitate it? thank you in advance. wenming freeia@163.com wenming wrote: > hi, there. i want to write a neuralnet program in c++, where can i get a opensource c++ neural net library to facilitate it? > thank you in advance. > > > > wenming > freeia@163.com Hi, I would recommend the fann library which is a C library that can easily be used from C++ http://fann.sf.net (I am the project administr...

How can I get rid of #define in my generated C code ...?
Folk, I am using lex and yacc for a project I am working on, wondering if there is any switch I can specify ANYWHERE, including the C compiler, that would take the .c files that these utilities generate, and get rid of all the #defines in the generated code. (when I say get rid of, I don't mean to simply delete, I mean to recognize: Oh yes, this is defined and here is what I want to do.) The y.tab.c and lex.yy.c files that these utilities produce are infested with #define, a lot conditional, making them impossible to read, and modify (e.g. yes, I need to make some changes to them) Any s...

Ada library, interfacing ADA with C
Hello everybody !!! I have to interface ADA with C and I would like to create an ADA library. I read the gnat manual and it is said that i can use gnatmake and a project library. So I use gnatmake: $ gnatmake -Pmy_lib.gpr I get the following message: powerpc-eabispe-gnatbind -n -o b~lib.adb -Llib prog1.ali prog2.ali powerpc-eabispe-gcc -c b~lib.adb building static library for project my_lib powerpc-eabispegnatmake: powerpc-elf-ar not found in path. In fact I haven't powerpc-elf-ar on my computer, so i created a link to it with : ln -s powerpc-eabispe-ar powerpc-elf-ar But the pr...

Can't load library TCL.tmp This library or a dependent Library could not be found in library path
I'm receiving a bizzare error message on the Windows 2003 platform. This runs fine on XP and Windows 2000. I'm executing a tclkitsh with my kit and it's failing with: Couldn't load library "C:/DOCUME~1\username\LOCALS~1\Temp\1\TCL1.tmp": this library or a dependent library could not be found in library path. I have attached a listing of the directory structure. Thank you in advance. Mike Hi Mike, >I'm executing a tclkitsh with my kit and it's failing with: >Couldn't load library "C:/DOCUME~1\username\LOCALS~1\Temp\1\TCL1.tmp": >this...

What can I use instead of C/C++ Math Library?
As far as I can understand, the C/C++ library is no longer being devloped or supported, and is only available in earlier versions. This change was not very well publicised by Mathworks. The good thing about the C++ library was that one could write C++ that looked pretty much like Matlab (and of course Fortran). I have been looking for open-source C++ libraries that do pretty much the same thing, the priorities being Support for matrix objects, with operations that call BLAS and LAPACK Support for sparse matrix objects with performance comparable with Matlab, with calls to ARPACK and SuperLU...

[GNAT] Importing a C/C++ library from within Ada?
Hi, I was wondering, is there an efficient way to import a C/C++ library withing Ada on Linux platform using GNAT. I simply like to be able to access the functions/methods from Ada. Thanks in advance, -Conrad The GNAT manual should describe the CPP interface package and associated pragmas to support imported C++ code. My advice is to RTFM (Read The Fantastic Manual). <conradwt@runbox.com> wrote in message news:1114026742.256627.5450@g14g2000cwa.googlegroups.com... > Hi, I was wondering, is there an efficient way to import a C/C++ > library withing Ada on Linux platform usi...

How can I get the IP address from domain?Is any C/C++ API for it?
hi, now I encounter a problem that is when I received the domain how I can translation it into IP address.Is there any C/C++ API for it? In java ,it seems to deal with it.any hints? Thank you very much ,in advance. "Alan" <pluscore@gmail.com> writes: > hi, > now I encounter a problem that is when I received the domain how I > can translation it into IP address.Is there any C/C++ API for it? gethostbyname -- M�ns Rullg�rd mru@inprovide.com ...

Can I include ROOT (Cern) libraries in C/C++ programs
Hi, I want to use the plot and fit functions of the ROOT libraries. Can I include them directly in my C code and compile it and how can I do that? If this is not possible are there any other possibilities? I use WindowsXP, compiler: Dev-C++ or VC++ Thanks Florian [cross-posting deleted] flohudelist@web.de wrote: > I want to use the plot and fit functions of the ROOT libraries. Can I > include them directly in my C code and compile it and how can I do > that? If this is not possible are there any other possibilities? > I use WindowsXP, compiler: Dev-C++ or VC++ I don't know ...

where exactly c++,c fail and Ada gets thru'
we are developing safety critical software.my seniors say that c and c++ are not suitable for safety critical software development and ada is very much safe.NASA aslo uses Ada.at what point c++ or c turns to be not suitable for devleloping flight software. i may be wrong also. can any one give some more justifications for telling "ADA is safe" thanks in advance Ananth the Boss wrote: > we are developing safety critical software.my seniors say that c and > c++ are not suitable for safety critical software development and ada > is very much safe.NASA aslo uses Ada.at what po...

Where can get PAT( Principal Axis Tree) c/c++ code?
Dear all, I'm looking for a algorithm about nearest neighbor,called PAT. Does anybody know where can get the c/c++ code or example about PAT? Thanks a lot. Best Regards, Cylin. ...

where can i get the free download of boreland c/c++ 2.0
hi friends, please help me to send the url's of the free dowload of c/c++ regards. deepu deepu kerala wrote: > hi friends, > > please help me to send the url's of the free dowload of c/c++ > > regards. > > deepu Since it was posted in clc before, I'll post it again: http://community.borland.com/museum/ Once you click a link, you may find it hard to discern the color of links (e.g., for download) from regular text. -- jay I'm a chinses student ,This is the first time I join in this area,I want create a friendship with you,If you agree,p...

Can I get a JAVA GUI library that can be make winxp style well.
Can I get a JAVA GUI library that can be make winxp style well. help me.... Evicn.Tam wrote: > Can I get a JAVA GUI library that can be make winxp style well. Since Java 1.4.2, the Sun Windows L&f supports Windows XP. Sun has improved the the precision and overall qualitiy of this L&f with every release. A significant amount of changes has been made to the Java 6 version; I think some important changes will be included in the Java 6 build 80 or so. I provide the JGoodies Windows L&f that is based on the Sun Windows L&f and brings some of the patches made in most recent...

Web resources about - Can I get rid of C libraries dependencies? - comp.lang.ada

List of countries and dependencies by population - Wikipedia, the free encyclopedia
A map of world population. Gray-scale legend: 0 to 50 M to 400 M to 1,336 M (million), 2011. This is a list of countries and dependent territories ...

List of countries and dependencies by area - Wikipedia, the free encyclopedia
This is a list of the world's sovereign states and their dependent territories by area, ranked by total area. Entries in this list are based ...

Link: Dependencies are Evil by Mike Cottmeyer
Learn more about transforming people, process and culture with the Real Agility Program Great article by Mike Cottmeyer: Dependencies are Evil ...

3 Thinking Tools for Minimizing Dependencies Between Products
... work together in an integrated fashion. Each of these smaller products have a backlog, a […] The post 3 Thinking Tools for Minimizing Dependencies ...

Google Play Services 6.5 Rolling Out Now With Granular SDK Dependencies And New Features In Fit, Maps ...
Most of us don't want to think of Android without Google Play services. There's a good reason for that, without all of the tools Google offers, ...

Codea Is Now More Dependable With Project Dependencies And Other New Coding Features
... If you can’t see the video embedded above, please click here . This time, the latest update to Codea introduces support for project dependencies. ...

Article: Cut off wrong dependencies in your .NET code
Today, we got published the article Cut off wrong dependencies in your .NET code on InfoQ. I re-introduce there the two ideas of namespaces as ...

Interface vs. Implementation Dependencies in Java
I often use the notion of interface and implementation dependencies, where interface dependencies are mostly always smaller. I think this is ...

Identifying Agile Impediments, Relationships, and Dependencies
Identifying Agile Impediments, Relationships, and Dependencies

For your app-roval: My horrifying digital dependencies
For your app-roval: My horrifying digital dependencies

Resources last updated: 1/25/2016 5:51:28 AM