Java 中 clang 的 `pkg-config` 参数
我正在尝试从 Java 应用程序运行 clang 编译。它工作得很好,直到我尝试传递 pkg-config 参数。例如:
clang -I/usr/lib/gcc/x86_64-linux-gnu/4.6/include `pkg-config --cflags --libs gtk+-2.0` -o file.o main.c
与此类似的一行在终端中可以完美运行,但在 Java 中却失败。 Clang 报告“没有这样的文件或目录:'`pkg-config --cflags --libs gtk+-2.0`”错误。
我正在使用以下代码来启动编译器:
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]));
...
有什么想法为什么它在终端上工作正常,但从 Java 调用时完全相同的行却失败了?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pkg-config
不是一个参数,而是一个查找您需要的文件的命令。当您从 bash 运行它时,它首先运行命令
pkg-config --cflags --libs gtk+-2.0
,然后将输出作为参数传递给 clang。(当你将命令包装在 char ` 中时,bash 会执行此操作)
我猜 Java 没有这个功能,所以尝试在 shell 中手动运行该命令,并将输出写入你需要的参数。
pkg-config
is 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.