Working Code of Creating .cubin file by explicitly calling nvcc windows command line

/* @ Auther :
 * Marco13
 * @ Edited by :
 * Jahanzeb Maqbool Hashmi (NUST-SEECS)
 *
 *
 * Working code of generating .cubin file using java (calling nvcc from command line)
 * Just compile and run the code like normal java code.
 * (dont forget to edit the directory paths according to your machine.
 *
 */
import java.io.*;

public class testCubin
{
	private static byte[] toByteArray(InputStream inputStream)
	{
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		byte buffer[] = new byte[1024];
		while (true)
		{
			try
			{
				int read = inputStream.read(buffer);
				if (read < 0)
					break;
				baos.write(buffer, 0, read);
			}
			catch (Exception e)
			{
				System.out.println(e);
			}
		}
		return baos.toByteArray();
	}

	public static void main(String[] args)
	{

		Process process = null;
		String cuFile = "JCudaCubinSample_kernel.cu";
		String cubinFileName = "createdCubin.cubin";
		
		// explicitly tell nvcc where the c compiler is.
		String ccbinPath = "C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\bin"; 

		try
		{

			String command = "nvcc -ccbin \"" + ccbinPath + "\" -cubin " +
				cuFile + " -o " + cubinFileName;

			System.out.println("Executing
" + command);

			process = Runtime.getRuntime().exec(command);

		}
		catch (IOException e)

		{

			throw new RuntimeException("Could not execute nvcc compiler", e);

		}

		String errorMessage = new String(toByteArray(process.getErrorStream()));

		String outputMessage = new String(toByteArray(process.getInputStream()));

		System.out.println("Error :" + errorMessage);
		System.out.println("output :" + outputMessage);

		int exitValue = 0;

		try
		{
			exitValue = process.waitFor();

		}
		catch (InterruptedException e)
		{

			Thread.currentThread().interrupt();
			throw new RuntimeException(
				"Interrupted while waiting for nvcc output", e);
		}

		System.out.println("nvcc process exitValue " + exitValue);

	}
}

Ah, just noticed this (and added the Java code tags).

As mentioned in the other thread, this will certainly be helpful for others.

When I have some time, I will try to create an example and possibly upload it to jcuda.org … and possibly continue with my OO-Layer project, which already contains this feature, but still is in a too early state to be published…