tsaarni / cpp-subprocess

popen() -like C++ library with iostream support for stdio forwarding
MIT License
88 stars 21 forks source link

Cannot get library to compile #4

Closed lufinkey closed 7 years ago

lufinkey commented 7 years ago

I tried compiling this library in the simplest form I could. I just created a popen object to run the command ls, wait for the return value, and then close it. This is the code I used:

int main()
{
    subprocess::popen process("ls", std::vector<std::string>());
    int retval = process.wait();
    process.close();
    return retval;
}

This is the output I get

cpp-subprocess/include/subprocess.hpp:68:19: error: expected ‘)’ before ‘->’ tok en
     std::ostream& stdin()  { return *in_stream;  };
tsaarni commented 7 years ago

Which compiler you use and what command you used to compile the test program?

This is what I used for successfully compiling the test program:

$ cat test.cpp
#include "subprocess.hpp"
int main()
{
    subprocess::popen process("ls", std::vector<std::string>());
    int retval = process.wait();
    process.close();
    return retval;
}
$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ -std=c++11 test.cpp -o test
$
lufinkey commented 7 years ago

I used clang++

On Oct 16, 2016 3:01 AM, "Tero Saarni" notifications@github.com wrote:

Which compiler you use and what command you used to compile the test program?

This is what I used for successfully compiling the test program:

$ cat test.cpp#include "subprocess.hpp"int main() { subprocess::popen process("ls", std::vectorstd::string()); int retval = process.wait(); process.close(); return retval; }$ g++ --versiong++ (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609 Copyright (C) 2015 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++ -std=c++11 test.cpp -o test$

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tsaarni/cpp-subprocess/issues/4#issuecomment-254031216, or mute the thread https://github.com/notifications/unsubscribe-auth/AHdTUUCeZeXfSCexBv74P3Oem50kvJxlks5q0cuvgaJpZM4KX0aA .

tsaarni commented 7 years ago

Ok, what version and what OS?

Clang works for me as well:

$ clang++ --version
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ clang++ -std=c++11 test.cpp -o test
$ ./test
$ echo $?
0

I don't seem to be able to reproduce the problem.

lufinkey commented 7 years ago

I'm compiling with cygwin's clang, so I guess it's an issue with cygwin. I'm on Windows 10 64-bit

tsaarni commented 7 years ago

I don't have cygwin available right now but I found this bug report which could explain the error. It says stdin is defined as macro on cygwin. That would mess up the method declarations in subprocess.hpp.

Try to renamestdin() and possibly also stdout()and stderr()methods in subprocess.hpp to something else.

lufinkey commented 7 years ago

I undefined them before including subprocess.hpp and that fixed it. Thanks!

Code for anyone who happens to stumble upon the same problem:

#ifdef stdin
    #undef stdin
#endif
#ifdef stdout
    #undef stdout
#endif
#ifdef stderr
    #undef stderr
#endif
#include "subprocess.hpp"