I’m trying to run a clang compile from a Java application. It works great until I try and pass a pkg-config argument. For example:
clang -I/usr/lib/gcc/x86_64-linux-gnu/4.6/include `pkg-config --cflags --libs gtk+-2.0` -o file.o main.c
A line similar to this line works perfectly from the terminal but fails from Java. Clang reports a ‘no such file or directory: ‘`pkg-config –cflags –libs gtk+-2.0`’ error.
I am using the following code to launch the compiler:
List<String> cmd = new LinkedList<String>();
cmd.add("clang");
cmd.add("-I/usr/lib/gcc/x86_64-linux-gnu/4.6/include");
cmd.add("`pkg-config --cflags --libs gtk+-2.0`");
cmd.add("-o");
cmd.add("file.o");
cmd.add("main.c");
Process proc = Runtime.getRuntime().exec(cmd.toArray(new String[0]));
...
Any ideas why it works fine from the terminal but the exact same line fails when being called from Java?
pkg-configis not a parameter, but a command that find the files you needed.When you run it from bash, it first run the command
pkg-config --cflags --libs gtk+-2.0, and then pass the output as a parameter to clang.(bash do this when you wrap command in the char ` )
I guess that Java has not that feauter, so try run that command handly in shell, and write the output as the parameter you need.