c header files

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
RSrole
User
User
Posts: 71
Joined: Fri Apr 29, 2022 8:27 pm

c header files

Post by RSrole »

Just a thought, since the backend is now gcc, would it be possible to support c header (.h) files? Or is there a conversion utility that will convert them to pb syntax?
Quin
Addict
Addict
Posts: 1122
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: c header files

Post by Quin »

There sadly isn't native support for this in the compiler yet, although I would love to see it ,but Idle has written this to do it; https://www.purebasic.fr/english/viewtopic.php?p=633581
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

Re: c header files

Post by Mijikai »

+1
PB would become extremely powerful.
So easy access to C libs would be awesome.
User avatar
idle
Always Here
Always Here
Posts: 5835
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: c header files

Post by idle »

Currently the problem is if you !#include file.h; it gets added to the main function output in the generated c and you don't want it there as it will try to compile it rather than just adding the symbols.

The solution is easy enough but we need the c headers of the gcc tool chain used added to the SDK directory

Add a copy of the c system headers to the sdk directory
Tell the gcc compiler where to find the c system headers on the command line "-I path_to_c_includes"
when the compiler sees !#include somlib.h in your code it deletes it and adds it to the command line "-include path_to_somelib.h"
or add it to a pboutput.h then, include pboutput.c in the .h at the end of the parse and pass the .h to the gcc compiler probably simpler

Then we have access to the c lib with inline c and it's easy enough to wrap in PB functions or macros.

Automatically Importing c headers to PB is actually far from trivial. I tried c-tags, u-tags and castXML which is the most promising of them but it's a whole llvm tool chain and it generates an XML tree that's still difficult to parse but it has most of the info that's needed to output a PB Include file, the rest of the info can be queried from the gcc compiler.
Post Reply