Reputation: 408
I installed gcc
on OSX via brew
. I need to use gcc instead of clang for a specific command which clang does not support. In shell screen, gcc example.c
command compiles example.c code with clang whereas gcc-9 example.c
command compiles the code with the original gcc (GNU C Compiler).
In QT, I need to use pipe()
function to get output of a GCC command. If I put a command string with gcc to the pipe function, it gives error because clang does not support the specific command I mentioned about in the beginning. If I put a command with gcc-9 to the pipe function, this time QT gives error like "gcc-9: not found".
Why does gcc-9
command works on shell screen but not in QT? How can I use gcc-9
command in QT?
The code piece is below:
std::string removeComments(const std::string &path)
{
std::array <char, 256> buffer;
std::string result, cmd = "gcc-9 -fpreprocessed -dD -E '" + path + "'";
std::unique_ptr <FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
if (!pipe)
throw std::runtime_error("popen() failed!");
fgets(buffer.data(), buffer.size(), pipe.get());
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
if (!skipLine(buffer.data()))
result += buffer.data();
return result;
}
Upvotes: 0
Views: 336
Reputation: 119877
The compiler you are using to compile your code has nothing to do with the compiler you are trying to call from your code. None of the compiler settings in your IDE are relevant. To avoid confusion, return them to their default values.
You need to either
PATH
environment variable such that /usr/local/bin
is included, and the command gcc-9
can be found by the shell; or "/usr/local/bin/gcc-9"
Upvotes: 1