[fpc-pascal] [semi-off-topic] some C questions arising while using h2pas

Sven Barth pascaldragon at googlemail.com
Fri Jul 15 14:08:36 CEST 2011

Am 15.07.2011 13:43, schrieb Bernd:
> I am just trying to convert some openssl headers to Pascal (I know
> that there is an openssl unit in the fpc packages but it is missing
> the ECDSA functions which I will need later and which is main reason I
> am starting to look into openssl).
> To get used to this entire thing I am beginning with something much
> more simple, I will try to get some sha hashing functions from openssl
> imported (I will also need them, so it would not hurt to start with
> them).
> I am referring to the header file /usr/include/openssl/sha.h (pastebin
> here: http://pastebin.com/dS8DY2z9 )
> After appyling h2pas i have the following: http://pastebin.com/v3S3vtFR
> If I want to import functions in Pascal I would either declare them
> external and explicitly tell it the name of the library binary (this
> seems straightforward to me, I see no problems with this) or I load it
> dynamically at runtime and then ask for the addresses of the functions
> that I need and assign them to procedure variables (I have also done
> this already on some occasions and it is equally easy to understand
> and also raises no questions).
> I am confused about something else:
> When looking at the .h file and also when looking at the generated .pp
> file it seems that nowhere in the header there was any information
> about which .so (or .dll) to load or link against. It created empty
> bodies with { you must implement this function }. Now the question
> (and I am intentionally asking this on a Pascal list and not a C list
> to get an answer that better fits into my Pascal brain) how would the
> C compiler or linker know from where exactly to import these
> functions? Where is this information, how are these C folks doing
> these things, what kind of magic have they going on?

You missed some options of h2pas.

1. Did you give a name to the "-l" option? I don't know which library 
the functions reside in, but you should then use something like "-l 
2. Using the options you passed you did not generate code for external 
functions, but basically a normal Pascal unit. For the first you need to 
use either the "-d" or the "-D" parameter. The first one will only add 
an "external;" to declarations while the second one will add "external 
libname name 'name of the declaration';" (where libname is the name you 
gave with "-l"). If you use the first one you need to add a "{$linklib 
thelibraryname}" (e.g. "{$linklib ssh}") in the second case it should 
work already.

I hope this helps, if not, feel free to ask :)


More information about the fpc-pascal mailing list