https://github.com/miho/vtcc
Compile and Run C code from Java via embedded Compiler (Works on Linux, Windows and macOS)
https://github.com/miho/vtcc
Last synced: 9 months ago
JSON representation
Compile and Run C code from Java via embedded Compiler (Works on Linux, Windows and macOS)
- Host: GitHub
- URL: https://github.com/miho/vtcc
- Owner: miho
- License: bsd-2-clause
- Created: 2018-02-19T14:48:56.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-04-11T08:44:12.000Z (almost 4 years ago)
- Last Synced: 2025-03-22T04:51:18.547Z (10 months ago)
- Language: Java
- Size: 223 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VTCC
[  ](https://bintray.com/miho/TCC/VTCC/_latestVersion) [](https://ci.appveyor.com/project/miho/vtcc) [](https://travis-ci.org/miho/VTCC)
Compile and Run C code from Java via embedded [TCC](https://bellard.org/tcc/) Compiler (Works on Linux, Windows and macOS)
## Usage:
To execute C code, the following method can be used:
```java
// execute C code"
String code = "#include \n" +
"int main(int argc, char* argv[]) {\n" +
" printf(\"Hello, World!\\n\");\n"+
" return 0;\n"+
"}";
CInterpreter.execute(code);
```
To execute a specified C script, use:
```java
// execute main.c
CInterpreter.execute(new File("main.c"));
```
To print the output to given print streams, use the `print(...)` method:
```java
// execute main.c
CInterpreter.execute(new File("main.c")).print(System.out,System.err);
```
To wait until the execution has finished, use the `waitFor()` method:
```java
// execute main.c and wait until exution finishes"
CInterpreter.execute(new File("main.c")).waitFor();
```
The exit value can be accessed via:
```java
// execute main.c
CInterpreter.execute(new File("main.c")).getProcess().exitValue();
```
To destroy the current process, the `destroy()`method can be used:
```java
// execute main.c
CInterpreter.execute(new File("main.c")).destroy();
```
## How to Build VTCC
### Requirements
- Java >= 1.8
- Internet connection (dependencies are downloaded automatically)
- IDE: [Gradle](http://www.gradle.org/) Plugin (not necessary for command line usage)
### IDE
Open the `VTCC` [Gradle](http://www.gradle.org/) project in your favourite IDE and build it
by calling the `assemble` task.
### Command Line
Navigate to the [Gradle](http://www.gradle.org/) project (e.g., `path/to/VTCC`) and enter the following command
#### Bash (Linux/OS X/Cygwin/other Unix-like Shell)
sh gradlew assemble
#### Windows (CMD)
gradlew assemble