cppsp란 무엇인가?
발행: (2025년 12월 30일 오후 05:38 GMT+9)
4 min read
원문: Dev.to
Source: Dev.to
요구 사항
- C++ 컴파일러가 설치되어 있고 해당 폴더가 시스템 PATH(환경 변수)에 추가되어 있어야 합니다.
- 생성된 실행 파일을 위해 64‑bit C++ 컴파일러가 필요합니다.
- (선택) 생성된
exe/elf/mach‑o파일이 있는 폴더를 PATH에 추가합니다. cppsp_compiler가 정상적으로 동작하도록_mac/_linux디렉터리를 삭제합니다.- (선택)
cppsp_compiler.exe(또는cppsp_compiler)의 이름을 원하는 대로 바꿔 컴파일 명령을 변경할 수 있습니다(예:cppsp,abcdef등).
설치
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
사용법
명령줄에서 .cppsp 스크립트를 컴파일합니다:
# 컴파일러가 PATH에 있는 경우
cppsp_compiler script.cppsp
# PATH에 없을 경우, 상대 경로나 절대 경로를 사용
.\cppsp_compiler.exe script.cppsp
# 또는
c:\path\to\cppsp_compiler.exe script.cppsp
C++ include / library 폴더 설정
컴파일러와 같은 디렉터리에 두 개의 .ini 파일을 생성합니다:
-
include.ini – 포함 디렉터리들의 콤마(,) 구분 목록
C:\path\to\include1,C:\path\to\include2 -
lib.ini – 라이브러리 디렉터리들의 콤마(,) 구분 목록
C:\path\to\lib1,C:\path\to\lib2
기능
print("hello world")만 포함된 스크립트도 컴파일할 수 있습니다.import를 통해 거의 모든 C++ 헤더를 가져올 수 있습니다.@inject와@function을 사용해 원시 C++ 코드를 삽입할 수 있습니다.- 들여쓰기와 다중 라인 문장을 지원합니다(버전 1.3부터 사용 가능).
키워드
| Keyword | Description |
|---|---|
#useclang / #usegcc | 기본 컴파일러로 clang++ 또는 g++를 선택합니다. |
@command("…") | 컴파일 명령에 사용자 정의 플래그를 추가합니다(예: -Os, -m64). |
#overwrite | 기본 컴파일 명령을 교체합니다. 예: @command("g++ -Os -m64 -nostdlib -shared -o dll.dll dll.cpp"). |
import | C++ 헤더를 가져옵니다. 예: import iostream,cstdio,vector. |
@function> | int main() 앞에 임의의 C++ 코드(함수, using 문, #define 등)를 삽입합니다. |
@inject(…) | int main(){…} 내부에 코드를 직접 삽입합니다. |
print() | 콘솔에 값을 출력합니다. 예: print("12\n", " ", 1, " ", 2.1, true, false). |
input() | 변수를 읽어들입니다(변수는 @inject를 통해 선언되어야 함). |
// | 한 줄 주석. |
경고 ⚠️
- v1.2 이전: 키워드 앞에 공백/빈 문자를 넣을 수 없습니다.
- v1.3 이전: 다중 라인 문장은 지원되지 않습니다.
@command()자체는 여러 줄에 걸쳐 나눌 수 없으며, 필요하면 별도의@command()호출을 사용하십시오.
예시
@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)
간단한 DLL 예시
#overwrite
@command("g++ -Os -m64 -nostdlib -shared -o dll.dll dll.cpp")
@function>