CPas
                                
                                 CPas copied to clipboard
                                
                                    CPas copied to clipboard
                            
                            
                            
                        Static C Libraries for Delphi

CPas
Static C Libraries for Delphi
Current list of static C libraries available. More will be added by myself and hopfully other people in the community. If you wish to contribute, submit a PR. Follow the project format in this repo.
| Name | Latest Version | Category | Description | 
|---|---|---|---|
| miniaudio | 0.11.21 | Audio | An audio playback and capture library | 
| 1.0.0 | Console | Print colored text to the console | |
| SQLite | 3.46.0 | Database | Local SQL database library | 
 Utilizing C code in Delphi app
 Utilizing C code in Delphi app
From Delphi 12.1 onwards compiled C code can be incorporated into Delphi EXE without the need to use or include a DLL.
In short
- Including the .ofile from C++ Builder{$L Unit1.o}.
- Exposing all the calls the C code relies on, and referencing them in Delphi (long list already exists, figuring out more is easy). See CPas.CRuntime unit.
- Defining Delphi headers for the actual C routines in the .ofile.
Explanation
- The trick is to build a CRuntimeunit to reference all the missing functions the C code needs.
- C++ Builder's Win64 Modern platform is Clang based and links against the UCRT runtime, making a dll/exe in C, with TDUMPto show all the C runtime routines it references.
- It is ‘trivial’ to add to the CRuntimeunit and build up a unit of routines in Delphi.
- Since Win64 Modern platform links only to the dynamic UCRT, only the routine address is needed, not a proper definition. i.e. procedure wprintf; external ucrt;is enough since the host app does not need to call it directly. As long as the code in the.ocan referencewprintf, it will compile.
Instructions
- Compile the project with C++ builder, take the .ofile and add it to the Delphi wrapper unit{$L Unit1.o}, with reference toCRuntimeunit.
- Any C library that one would normally have to use via a .dll, can be attempted to be compiled in C++Builder Win64 Modern, and if so, then it's likely possible to statically link that into Delphi without having a DLL.
For example:
- Compile sqlite3.cand take thesqlite3.o.
- In the uses section add CRuntimeunit, used by the C runtime routines.
- In a sqlite3unit, declare all the routines insidesqlite3.o.
- Add {$L sqlite3.o}in the implementation section.
- Add this sqlite3unit to your project and compile.
sqlite3 C lib is now statically linked inside your Delphi EXE.
Prerequisites and other notes
- RAD Studio 12.1 or higher.
- ~~__chkstk_msis needed, which is located not inapi-ms-win-crt-stdio-l1-1-0.dllbut inkernalbase.dlland it is not namedchkstk_msinside that DLL, but only aschkstk, while the code inside the.ofile references it as__chkstk_msand is solved byprocedure _chkstk_ms; stdcall; external kernelbase name 'chkstk';.~~ This has been added toCPas.CRuntimeunit.
- All these things must be "visible" in Delphi in order for the project to compile.
Expanding
- May work with other clang based compilers, but using C++ Builder to compile the C sources will work best with Delphi.
- Adding more references:
Imports from api-ms-win-crt-convert-l1-1-0.dll:
_strtod_l
_strtoi64_l
_strtoui64_l
atof
atoi
atol
mbrtowc
mbsrtowcs
strtof
strtol
strtoll
strtoul
strtoull
wcrtomb
wcrtomb_s
- Take all those references and go to ChatGPTand say: “Create a Delphi unit calledCRuntimeand export these routines fromapi-ms-win-crt-stdio-l1-1-0.dlldefine as a const ucrt:” and paste the above references. => ChatGPT will generate a CRuntime unit.
- If for example wprintfinUCRTcomplain that_wprintfis not found, an underscore prefix will help, it’s a c linkage thing.
- Target 64 bit
- CPas.CRuntimeunit exists in the repo, just add any new references to it.
 Support
 Support
Our development motto:
- We will not release products that are buggy, incomplete, adding new features over not fixing underlying issues.
- We will strive to fix issues found with our products in a timely manner.
- We will maintain an attitude of quality over quantity for our products.
- We will establish a great rapport with users/customers, with communication, transparency and respect, always encouraging feedback to help shape the direction of our products.
- We will be decent, fair, remain humble and committed to the craft.
 Links
 Links
 License
 License
CPas is a community-driven project created by tinyBigGAMES LLC.
BSD-3-Clause license - Core developers:
 Acknowledgments
 Acknowledgments
CPas couldn't have been built without the help of wonderful people and great software already available from the community. Thank you!
People
- John Claw
- Robert Jalarvo
Contributors