简体   繁体   English

为自制软件构建C ++公式

[英]Building a C++ formula for homebrew

I have very very little experience with Ruby and I was trying to build a simple homebrew formula. 我对Ruby的经验很少,我试图建立一个简单的自制公式。 I had a simple test project with the following structure 我有一个具有以下结构的简单测试项目

.
├── Makefile
└── test.cpp

0 directories, 2 files

And then I have the following .rb formula file 然后我有以下.rb公式文件

class Testbrew < Formula
  desc ""
  homepage ""
  url ""
  version ""
  head ""
  sha256 ""

  def install
    # system "make"
    # system("g++ -std=c++14 -O3 test.cpp -o testbrew")
    system "g++", "-std=c++14",
           "-O3",
           "-Wall",
           "-Werror",
           "-Wextra",
           "-pedantic",
           "-Wvla",
           "test.cpp",
           "-o testbrew"
    bin.install "testbrew"
    ohai("Done!")
  end
end

The confusing part here is that the first two commented lines of system work to install the package but the third does not, any idea why? 这里的混乱的部分是前两个注释行system工作,安装软件包,但第三个没有,任何想法,为什么? If I try the third line I get the error 如果我尝试第三行,我会收到错误消息

==> g++ -std=c++14 -O3 -Wall -Werror -Wextra -pedantic -Wvla test.cpp -o testbrew
Error: No such file or directory - testbrew

Also as a followup, are there certain things that the function call system() does not allow the user to do? 另外,作为后续操作,函数调用system()不允许用户执行某些操作吗? ie are there any security restrictions imposed (for example with ptrace )? 即是否有任何安全限制(例如ptrace )?

Your argument "-o testbrew" is wrong. 您的参数"-o testbrew"是错误的。 That parses as -o with the option " testbrew" including the space. 使用选项" testbrew" 包括空格)将其解析为-o This is only possible because system with mutiple arguments bypasses the normal shell parsing, you're directly responsible for correctly splitting arguments. 这仅是可能的,因为具有多个参数的system绕过常规的shell解析,您将直接负责正确拆分参数。

You've broken the other arguments out correctly. 您已经正确地分解了其他参数。 I'd recommend doing it that way: 我建议这样做:

"-o", "testbrew"

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

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