简体   繁体   English

Java的clang的`pkg-config`参数

[英]`pkg-config` argument for clang from Java

I'm trying to run a clang compile from a Java application. 我正在尝试从Java应用程序运行clang编译。 It works great until I try and pass a pkg-config argument. 在我尝试传递pkg-config参数之前,它非常有用。 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. 与该行相似的行从终端可以完美地运行,但是从Java失败。 Clang reports a 'no such file or directory: '`pkg-config --cflags --libs gtk+-2.0`' error. Clang报告“没有这样的文件或目录:”`pkg-config --cflags --libs gtk + -2.0`错误。

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? 有什么想法为什么可以在终端上正常工作,但是从Java调用时却完全相同的行失败了?

pkg-config is not a parameter, but a command that find the files you needed. pkg-config不是参数,而是找到所需文件的命令。

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运行它时,它首先运行命令pkg-config --cflags --libs gtk+-2.0 ,然后将输出作为参数传递给clang。

(bash do this when you wrap command in the char ` ) (将命令包装在char`中时,bash会执行此操作)

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. 我想Java并没有那么完善,因此请尝试在shell中手动运行该命令,并将输出作为所需参数写入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM