Skip to content

sorribas/tcc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tcc

Godoc

Go bindings for libtcc.

Usage

Here's how to compile a C program in memory and run it.

package main

import "github.com/sorribas/tcc"

func main () {
	program := `
	extern int printf(char* c,...);
	int main () {
		printf("Hello world!\n");
		return 0;
	}
	`
	tcc := NewTcc()
	defer tcc.Delete()
	tcc.SetOutputType(OUTPUT_MEMORY)

	// tcc must contain the libtcc1.a file that includes the TCC runtime.
	tcc.SetLibPath("/path/to/tcc")
	err := tcc.CompileString(program)
	if err != nil {
		// compilation error
	}
	// run the program
	i := tcc.Run([]string{})
}

You can use this library as a backend for a compiler or simply to compile and run dynamically generated code.

To build a project using this library, you need to have libtcc installed. You can download from the official tcc website

License

MIT License

About

Go bindings for libtcc.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published