[英]Generating object file to separate directory using g++ compiler - C++
I use the following code to compile a cpp file to object file.我使用以下代码将 cpp 文件编译为目标文件。
g++ -c main.cpp
Above code generates the .o fles in same directory where main.cpp resides.上面的代码在 main.cpp 所在的同一目录中生成 .o 文件。
Any help would be great任何帮助都会很棒
Suppose I have a folder named obj and need to generate the object files there, how do I write?假设我有一个名为 obj 的文件夹并且需要在那里生成目标文件,我该怎么写?
Use:采用:
g++ -c main.cpp -o obj/main.o
How can I see the compiler switches supported by g++ and it's usages?如何查看 g++ 支持的编译器开关及其用法?
If you are on a *nix system use:如果您使用的是 *nix 系统,请使用:
man g++
or use info g++
或使用info g++
If you type如果你输入
$man g++
Here's the man page online You'll probably get gobs of good information there.这是联机手册页您可能会在那里获得大量有用的信息。 You can also try你也可以试试
$g++ --help
To your question.对于你的问题。 If you used the -o switch, you can specify the output file to use.如果使用了 -o 开关,则可以指定要使用的输出文件。 So you could probably do something like所以你可能会做类似的事情
$g++ -c main.cpp -o obj/main.obj
问题 2 的另一个答案:有关编译器开关的更多信息可以在在线手册中找到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.