Recent

Author Topic: using a pascal library in my ARM embedded c project  (Read 5291 times)

marzl

  • Newbie
  • Posts: 1
using a pascal library in my ARM embedded c project
« on: January 08, 2018, 10:23:45 pm »
Hi fellows,
we got a PC pascal library, several thousand lines of code, which does a bunch of calculations, and we would like to use it in our c embedded ARM project ( cortex m7, no OS involved).
Can somebody give us a hint if it's recommendable to somehow use freepascal to compile the pascal sources and use them by the c project ( compiled by gcc)?
It would be simply fantastic if this would work out!
Thanks!
Mark

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: using a pascal library in my ARM embedded c project
« Reply #1 on: January 08, 2018, 10:58:48 pm »
I suppose of you were to compile all of that into a DLL,SO etc,.  you could link it in...

Just make sure you specify a calling standard on the exported functions.

The only true wisdom is knowing you know nothing

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: using a pascal library in my ARM embedded c project
« Reply #2 on: January 09, 2018, 01:34:58 am »
Recommendable ? .. that depends. Is it a "dll" library or a "unit" library ? (confusion of the word library in this context is possible).

In case the latter then you could perhaps have some work for you to do (as mentioned by jamie). Some types don't really mix between c and pascal, and your functions would have to be exported.

Other than that, yes in theory it is possible. A matter of how much time you would like to invest.

Some links here, and here, and i found this, this and this (not sure if the last ones are able to help though).

Just try some simple tests first and in case of issues, search/ask for help. It goes without saying that things like intel assembler code (assuming your unit was written for a platform like windows) does not compile for arm target (in case you have asm optimized functionality in your unit).
« Last Edit: January 09, 2018, 01:38:48 am by molly »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: using a pascal library in my ARM embedded c project
« Reply #3 on: January 09, 2018, 02:16:39 am »
there are two question to be answered here
1) does your c compiler support embedded assembly or not if yes then you could instruct FPC to export the assembly for the library and use that.
2) does the fpc chain support the obj format that your linker requires? if yes it might be easier to link against existing obj instead of the assembly as long as the fpc supports your embedded device.

In your position I would simple export the assembly and link it to my code it is more universal than trying to create and link binary libraries on a target that might not be supported by one of the compilers.

There is always a 3rd option, since you do not have any OS to help you, you could use the dll loader from WINE, but that will impose the same restrictions as the 2nd solution above, ee both compilers must support your embedded target
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018