Java 中 clang 的 `pkg-config` 参数

发布于 2024-12-28 18:06:17 字数 710 浏览 1 评论 0原文

我正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

徒留西风 2025-01-04 18:06:17

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文