cpp program runs compile command, test only code
This commit is contained in:
parent
2b13f347bd
commit
8e1c4b53b8
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,5 +4,6 @@
|
||||
*.swp
|
||||
*.swo
|
||||
*.out
|
||||
*.so
|
||||
*.dSYM/
|
||||
memgraph
|
||||
|
1
dc/README.md
Normal file
1
dc/README.md
Normal file
@ -0,0 +1 @@
|
||||
## Dynamic Code
|
46
dc/test.cpp
Normal file
46
dc/test.cpp
Normal 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
2
dc/tmp/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/*
|
||||
!.gitignore
|
Loading…
Reference in New Issue
Block a user