Building a C++ formula for homebrew

109 views Asked by At

I have very very little experience with Ruby and I was trying to build a simple homebrew formula. 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

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? 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? i.e. are there any security restrictions imposed (for example with ptrace)?

1

There are 1 answers

0
tadman On BEST ANSWER

Your argument "-o testbrew" is wrong. That parses as -o with the option " testbrew" including the space. This is only possible because system with mutiple arguments bypasses the normal shell parsing, you're directly responsible for correctly splitting arguments.

You've broken the other arguments out correctly. I'd recommend doing it that way:

"-o", "testbrew"