cpp program runs compile command, test only code

This commit is contained in:
Marko Budiselic 2015-10-22 00:17:40 +02:00
parent 2b13f347bd
commit 8e1c4b53b8
4 changed files with 50 additions and 0 deletions

1
.gitignore vendored
View File

@ -4,5 +4,6 @@
*.swp
*.swo
*.out
*.so
*.dSYM/
memgraph

1
dc/README.md Normal file
View File

@ -0,0 +1 @@
## Dynamic Code

46
dc/test.cpp Normal file
View File

@ -0,0 +1,46 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <iterator>
#include <cstdlib>
// TODO: clang++ file.cpp -o file.so -shared -fPIC
using namespace std;
void write(const std::string& path, const std::string& content)
{
ofstream stream;
stream.open (path.c_str());
stream << content;
stream.close();
}
std::string join(const std::vector<std::string>& strings, const char *separator)
{
std::ostringstream oss;
std::copy(strings.begin(), strings.end(),
std::ostream_iterator<std::string>(oss, separator));
return oss.str();
}
template<typename... Args>
std::string prints(const Args&... args)
{
std::vector<std::string> strings = {args...};
return join(strings, " ");
}
int main()
{
string tmp_file_path = "tmp/tmp.cpp";
string tmp_so_path = "tmp/tmp.so";
string for_compile = "#include <iostream>\nint main() { std::cout << \"test\" << std::endl; return 0; }";
write(tmp_file_path, for_compile);
string test_command = prints("clang++", tmp_file_path, "-o", "test.out");
system(test_command.c_str());
return 0;
}

2
dc/tmp/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/*
!.gitignore