我正在尝试使用您的标准 g++ 编译器编译一些 C++ 代码。 但是,不是从文件编译:
主要.cpp:
#include <iostream>
int main(){
std::cout << "Hello World!\n";
return 0;
}
我更愿意做类似的事情
g++ ... "#include <iostream>\n int main(){ std::cout << \"Hello World!\n\"; return 0;}"
上一个post从 stackoverflow 显示
echo "int main(){}" | gcc -Wall -o testbinary -xc++ -
有效,但我想知道它是如何工作的,如果有一种方法可以做到这一点而不需要通过管道传递内容,我想知道它是如何工作的,并且会更好。
编辑:
我正在执行运行时代码生成,我需要生成一个共享库并加载创建的函数。
我以为会有一个标志告诉编译器“嘿,我给你的是源代码而不是文件”。
再次感谢您的帮助!
最佳答案
echo "int main(){}" | gcc -Wall -o testbinary -xc++ -
works but I would like to know how it works and better yet, if there is a way to do this without the need to pipe the contents.
或者你可以说(例如在 shell 脚本中):
gcc -Wall -o testbinary -xc++ - << EOF
int main(){}
EOF
关于c++ - 在没有文件的情况下编译 C++ 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17702982/