Is there a way to compile C code from the Delphi IDE as part of a Delphi project?

Is there a way to compile C code from a Delphi environment?

I would like to use some C code as part of a Delphi project (and would prefer not to put it in a DLL). So, in the Delphi IDE, can I compile C code? Perhaps I can use a keyword to indicate the start of code insertion (e.g. ASM )? Or put the C code in a separate device, but how can I call it from my Delphi code?

If it can be done, how can I do it? Thanks...


[Update] Although it seems that this can be done using the Free Bolrand Command Line C ++ Compiler I decided, in the end, to put the C code in the DLL and statically link this. I think any solution is acceptable)?)

+4
source share
1 answer

No, it is not possible to compile c code as part of a Delphi project.

You can compile c-code using C ++ Builder and use object files ( *.obj ) in Delphi applications by linking them to {$L file.obj} and then calling them just like any other Delphi function, but you must provide c-runtime library functions. (There are some crtl.pas available in the block ( System.Win.crtl.pas in XE2 / XE3), any that are not there, you need to write Delphi replacements for yourself).

For an example of how to do this, you can see how ZLib is used by looking at Zlib.pas ( System.ZLib.pas in XE2 / 3).

As mentioned in the comments on your question, you can configure the pre-build event to launch your compiler c immediately before your project is built, which will work; technically, I'm not sure if this is considered “compilation as part of your project” or not, as it actually starts the external process. However, the above information still applies in this case.

+11
source

All Articles