简体   繁体   English

GCC - 定义我自己的命令行选项,添加选项列表

[英]GCC - define my own command line option that adds a list of options

Using GCC to compile C++ code: there's a big list of options (warnings, optimisations etc) I want to always compile with. 使用GCC编译C ++代码:我想要总是编译的选项列表(警告,优化等)。 It's tiresome to keep pasting them into the command line. 将它们粘贴到命令行中是很烦人的。 Can I do something like 我能做点什么吗

g++ test.cpp -o test.o -myoptions

where "-myoptions" would enable a list of options like 其中“-myoptions”将启用一个选项列表,如

-pedantic
-Wall
-O2
-Wshadow
-...

that I've defined somewhere? 我已经定义了某个地方?

I've tried searching but couldn't find a guide for this. 我试过搜索但找不到这方面的指南。 Is it possible or do I have to use make files? 是否可以或者我必须使用make文件? System is windows 7 if that's relevant. 如果相关,系统是Windows 7。 Thanks 谢谢


edit: in case someone searches for this in the future, windows specific answer: go to control panel -> system -> advanced system settings -> environment variables, create new system variable named "myoptions" and value "-option1 -option2 -option3 ...". 编辑:如果将来有人搜索这个,windows具体答案:转到控制面板 - >系统 - >高级系统设置 - >环境变量,创建名为“myoptions”的新系统变量和值“-option1 -option2 -option3 ...“。 Then compile with "g++ test.cpp -o test.o %myoptions%" 然后用“g ++ test.cpp -o test.o%myoptions%”编译

You can set an environment variable: 您可以设置环境变量:

export CXXFLAGS="-Wall -O3 -std=c++11"

and use 并使用

g++ $CXXFLAGS test.cc -o test

Note that some variables are more-or-less standardized and when you set them, several build system will automatically use them. 请注意,某些变量或多或少是标准化的,当您设置它们时,多个构建系统将自动使用它们。 Among others, google for CFLAGS , CPPFLAGS , CXXFLAGS , ... 其中,谷歌的CFLAGSCPPFLAGSCXXFLAGS ,...

Here's also a starting point on SO. 这也是SO的起点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 gcc 命令行中定义字符串文字? - How to define a string literal in gcc command line? gcc:错误:无法识别的命令行选项“ -combine” - gcc: error: unrecognized command line option ‘-combine’ GNU MAKE-从我自己的Makefile创建getoptpp库或为C ++建议命令行选项库 - GNU MAKE - create getoptpp library from my own Makefile or suggest command line options library for c++ GCC #pragma 或命令选项 - GCC #pragma or command options gcc:错误:无法识别的命令行选项'-fforce-mem' - gcc: error: unrecognized command line option '-fforce-mem' gcc-7:错误:无法识别的命令行选项“-m64” - gcc-7: error: unrecognized command line option ‘-m64’ 在brew install gcc之后,OS X Yosemite gcc无法识别的命令行选项'mdll' - OS X Yosemite gcc unrecognized command line option 'mdll' after brew install gcc 无法识别的命令行选项'-stdlib = libc ++'gcc(Homebrew gcc 5.3.0)5.3.0 - unrecognized command line option '-stdlib=libc++' gcc (Homebrew gcc 5.3.0) 5.3.0 检查我的头文件中的命令行选项 - Check for command line option in my header file 如何通过预处理器指令而不是命令行选项启用 GCC 编译器标志? - How to enable GCC compiler flags via preprocessor directives, rather than command line options?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM