mihosoft.eu
Programming, Art, Linux, Free Software…
mihosoft.eu
Navigation
  • Home
  • VRL-Studio
  • SonoAir
  • Monochrome Wars
  • About
  • Impressum
  • Datenschutz
You are here: Home › C/C++ › Running C code from Java via VTCC

Running C code from Java via VTCC

February 20, 2018 | Filed under: C/C++, Featured, Java, Programming Languages, VRL and tagged with: ANTLR4, C, compiler, language modeling, VMF, VMF-Text, VRL, VRL-Studio

In one of our projects we transform C code via VMF & VMF-Text which is a powerful language modeling framework based on ANTLR4 grammars. It can parse and write (“unparse”) code that conforms to a specified grammar and provides a Java API for manipulating the model. In one of our applications we use this infrastructure to add source-based instrumentations to a subset of C.

The problem is running and testing C code without requiring a (manually installed) native Compiler. On macOS and Windows this can involve downloading several GB for Xcode and Visual Code. There are smaller alternatives. But even they require additional installation and path adjustments. For on-the-fly execution of C code this is overkill.

To test and execute the C code hassle-free, I worked on a small Java library VTCC which uses the TCC compiler to run C code directly from Java. To prevent the JVM from crashing the code runs in its own process (for now, JNI integration might follow at some point).

VTCC embedds a tiny C compiler (< 1MB) to compile and run the C code snippets (works for Linux, macOS and Windows on x86 & x64). The API is fairly simple. Here’s an example:

VTCC - run C code from Java

VTCC – run C code from Java

The code is hosted on GitHub: https://github.com/miho/VTCC/. Binary distributions with an embedded compiler for Linux, macOS and Windows are available via bintray (maven central&jcenter). For an out-of-the-box experience you need two dependencies, the VTCC library and the binary dependency.

VTCC:

Download VTCC

tcc-dist:

Download tcc-dist

Example (Gradle):


  dependencies {
      // core library
      compile 'eu.mihosoft.vtcc:vtcc:2018.1.3'
      // binary dependencies
      compile 'eu.mihosoft.vtcc.tccdist:tcc-dist:2018.1.3'
  }

We are also going to add this library as plugin for VRL-Studio to finally add C support (for a subset of C).

There are many features that could be implemented on top of this like JNI support or shared memory between the JVM and native processes. If you have ideas don’t hesitate to contact me!

Stay tuned and follow me on Twitter

Did you like this article? Share it with your friends!

Tweet

Written by admin

Visit my Website Follow me on Twitter

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pages

  • About
  • Datenschutz
  • Impressum
  • Seminar 2019

Categories

  • 3D Printing
  • Any-Key
  • Art
  • C/C++
  • Devoxx
  • Digital Painting
  • Featured
  • IoT
  • Java
  • JavaFX
  • Javakurs 2015
  • JavaOne
  • Linux
  • Linux on Apple Hardware
  • Linux: Daily Usage Tips
  • Mobile Apps
  • Mobile Devices
  • Programming Languages
  • Repair Things
  • Science
  • Sonos
  • Teaching
  • Uncategorized
  • Virtual Reality
  • VRL

Tags

3D 3D Printing 3d visualization AirSonos Apple Music Devoxx Devoxx 2013 gradle graph iOS Java Java 8 JavaFX JavaFX 8 JavaOne JavaOne 2013 jdk9 JFXtras JInternalFrame Linux MacBook MDI mobile apps OpenDive OpenJDK OpenJFX Open Source Performance scientific visualization SonoAir Sonos Ultimaker Virtual Reality Virtual World visual programming VPlot VRL VRL-Studio VWorkflows window control Window Node Window System workflow workflows X11

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

JavaOne Rockstar

JavaOne Rockstar
Follow @mihosoft

Recent Posts

  • Native JDK9 Application Bundles
  • Running C code from Java via VTCC
  • SonoAir finally supports macOS High Sierra!
  • JavaOne 2017 Community Keynote Artwork
  • The JGrounds App: better teaching apps for Java 9 [BOF5047]

Recent Comments

  • ¿Ventanas completamente personalizadas de JavaFX? - Fallosweb.com on VFXWindows
  • JavaFX entirely customized windows? – w3toppers.com on VFXWindows
  • Volel Mondesir on Adding Custom Icons to JFXtras Window Control (VFXWindows)
  • Volel Mondesir on Adding Custom Icons to JFXtras Window Control (VFXWindows)
  • Switching between different JDK versions in Windows - ErrorsFixing on JSelect: switch between different JDK versions

Archives

  • February 2018
  • October 2017
  • September 2017
  • February 2017
  • June 2016
  • May 2016
  • November 2015
  • September 2015
  • July 2015
  • March 2015
  • September 2014
  • March 2014
  • February 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • November 2010
  • February 2010
  • November 2009
  • October 2009
  • February 2009
  • August 2008
  • May 2008
  • April 2008
  • March 2008
Privacy & Cookies: this site uses cookies. By continuing to use this website, you agree to their use.
To find out more, see here: Impressum & Datenschutz

© 2025 mihosoft.eu