What is cppsp?
Source: Dev.to
Requirements
- A C++ compiler installed and its folder added to the system PATH (environment variable).
- A 64‑bit C++ compiler (required for the generated executable).
- (Optional) Add the folder containing the generated
exe/elf/mach‑oto the PATH. - Delete the
_mac/_linuxdirectories so thatcppsp_compilerworks correctly. - (Optional) Rename
cppsp_compiler.exe(orcppsp_compiler) to any name you prefer to change the compile command (e.g.,cppsp,abcdef, …).
Installation
Windows
curl -L -o cppsp_compiler.exe https://github.com/user19870/cppsp/raw/refs/heads/First/cppsp_compiler.exe
Linux
curl -L -o cppsp_compiler https://github.com/user19870/cppsp/raw/refs/heads/First/cppsp_compiler_linux.delete_linux
macOS
curl -L -o cppsp_compiler https://github.com/user19870/cppsp/raw/refs/heads/First/cppsp_compiler_mac.delete_mac
Usage
Compile a .cppsp script from the command line:
# If the compiler is in PATH
cppsp_compiler script.cppsp
# If not in PATH, use a relative or absolute path
.\cppsp_compiler.exe script.cppsp
# or
c:\path\to\cppsp_compiler.exe script.cppsp
Setting C++ include / library folders
Create two .ini files in the same directory as the compiler:
-
include.ini – comma‑separated list of include directories
C:\path\to\include1,C:\path\to\include2 -
lib.ini – comma‑separated list of library directories
C:\path\to\lib1,C:\path\to\lib2
Feature
- Can compile a script that contains only
print("hello world"). - Allows importing almost any C++ header via
import. - Enables embedding raw C++ code with
@injectand@function. - Supports indentation and multi‑line statements (available from version 1.3).
Keywords
| Keyword | Description |
|---|---|
#useclang / #usegcc | Select clang++ or g++ as the underlying compiler. |
@command("…") | Append custom flags to the compile command (e.g., -Os, -m64). |
#overwrite | Replace the default compile command. Example: @command("g++ -Os -m64 -nostdlib -shared -o dll.dll dll.cpp"). |
import | Import C++ headers, e.g., import iostream,cstdio,vector. |
@function> | Inject arbitrary C++ code (functions, using statements, #defines, etc.) before int main(). |
@inject(…) | Insert code directly inside int main(){…}. |
print() | Output values to the console, e.g., print("12\n", " ", 1, " ", 2.1, true, false). |
input() | Read values into variables (variables must be declared via @inject). |
// | Single‑line comment. |
Warning ⚠️
- Before v1.2: No spaces/blank characters are allowed before a keyword.
- Before v1.3: Multi‑line statements are not supported.
@command()itself cannot be split across multiple lines; use separate@command()calls if needed.
Example
@command("-mtune=native -fomit-frame-pointer -static-libgcc -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--as-needed -s -Wl,--strip-all -Os -m64")
import iostream,vector
@function>
print("12\n"," ",1," ",2.1,true,false," ")
print("abc")
print(1,"\n") // comment
//print(1.1)
@inject(int x=1; int y=2; int z=3;
auto is_bool = [](const std::string& s){ return s == "true" || s == "false"; };)
input(x,y,z)
@function cars = {"Volvo","BMW","Ford","Mazda"}; };>>
print(x+y+z)
Simple DLL Example
#overwrite
@command("g++ -Os -m64 -nostdlib -shared -o dll.dll dll.cpp")
@function>