CFLAGS="-g -O0" ./configure
How's CFLAGS="-g -O0" picked up in configure?
Anyone knows this?
Here, you're setting CFLAGS as an environment variable to be passed into ./configure. You can set any number of environment variables this way if you happen to need more than one.
-g:
C compilation options which relate to optimization or debugging (usually just -g or -O). Usually this wouldn't include -I options to specify the include directories, because then you
couldn't override it on the command line easily as in the above example.
For more information, you can refer this url.
http://makepp.sourceforge.net/1.19/makepp_tutorial.html
Related
I am building Android AOSP on my server running Ubunty 16.04. I have all dependencies installed and the build completes fine. However, I get many Warnings from the make command each time. Is there a way to inhibit those from the console output (eg. via a parameter passed into the command). I have tried with some gcc flags in an attempt but the compiler either ignored them or threw errors due to unrecognised parameters.
Thank you for the kind help.
Lorenzo
gcc has the -w option which suppresses all warnings. The warning has to be put after any other compiler flags. How you do that depend on the makefile recipes. A late CXXFLAGS += -w might work. Put the -w behind a by default empty variable and you can override from the make invocation.
Makefile:
...
EXTRA_FLAGS ?=
# CXXFLAGS is a convention, your flag variables may be named differently
CXXFLAGS += $(EXTRA_FLAGS)
Make invocation
make my_target EXTRA_FLAGS="-w"
You can also set the environment variable EXTRA_FLAGS to set implicitly for each invocation:
export EXTRA_FLAGS="-w"
make my_target
export EXTRA_FLAGS=""
make my_target
Caveats include conflict with -Werror but guessing you are not using that since it compiles with warnings.
While testing code posted on SO, it's very helpful to turn the -Wall option on. I was able to do so by creating a Makefile whose contents are:
CFLAGS=-Wall
CXXLAGS=-Wall
I understand that one can use
make CFLAGS=-Wall <target>
make CXXFLAGS=-Wall <target>
as well.
Is this, setting CFLAGS/CXXFLAGS, the only way to turn compiler flags on by default?
Is there any configuration file(s) where one can enable/disable any of the compiler options?
if you are running bash
export CFLAGS="-Wall"
in your .bashrc is also a good place to set defaults. On BSD (Mac OSX) /etc/make.conf can be used to set default flags if you always use make. Or you can alias 'gcc' to 'gcc -Wall'. One of these should be the one you are looking for.
Say I have compiled a project (not my own) with autotools and passed some flags to configure. Now I want to compile this same project again, but with slightly different configure flags. Is there a way to tell the configure script to use the old flags, but update them with some additional ones?
I would love to see an easier approach, but to simply add flags you can do:
sed -i '/^ac_configure_extra_args=/s/$/--new-flag --other-flag/' config.status
./config.status --recheck
Normally, I manually edit config.status to do this, and not all sed support -i, but you get the idea. Change the original flags as they are defined in config.status to be the flags you want.
Another option is to cut-n-paste the original configure invocation out of the top of config.log and edit it.
GCCFilter is a neat perl script that allows to color the output of GCC and thus makes debugging much more fun and, more important, faster.
You can use GCCFilter with a CMake generated Makefile by calling
gccfilter -a -c make
However, this approach has some drawbacks: Delayed output of CMake status infos, no color in the CMake commands are the most obvious.
The question: Is there a way to write some CMake module that searches for gccfilter if the compiler is gcc, checks if, say COLOR_CXX is set (rather easy up to here) and then tells CMake to replace all calls to gcc by gccfilter -a -c gcc.
CMake offers the variable CMAKE_CXX_COMPILER, but changing this one will disallow CMake to find correct include paths and the like. Is there some variable we may change after the project() command that is prefixed before each call to gcc?
You can make CMake use gccfilter by pointing the RULE_LAUNCH_COMPILE property to a wrapper script which invokes gccfilter with the desired options.
Create an executable shell script named gccfilter_wrap in the outermost CMake project directory with the following contents:
#!/bin/sh
exec gccfilter -a -c "$#"
Be sure to set the file's executable bit. Then in your CMakeLists.txt, set the RULE_LAUNCH_COMPILE directory property before adding targets:
project (HelloWorld)
set_directory_properties(PROPERTIES RULE_LAUNCH_COMPILE
"${PROJECT_SOURCE_DIR}/gccfilter_wrap")
add_executable(HelloWorld HelloWorld.cpp)
The generated makefile rules will then prefix each compiler invocation with the gccfilter_wrap script. Alternatively the RULE_LAUNCH_COMPILE property can also be set as a target property or as global property.
The RULE_LAUNCH_COMPILE property only works for Makefile-based CMake generators.
Edit by Thilo
This is how I finally solved the problem - basically a rephrased version of this solution:
# GCCFilter, if appliciable
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCPP)
option(COLOR_GCC "Use GCCFilter to color compiler output messages" ON)
set(COLOR_GCC_OPTIONS "-c -r -w" CACHE STRING "Arguments that are passed to gccfilter when output coloring is switchend on. Defaults to -c -r -w.")
if(COLOR_GCC)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${PROJECT_SOURCE_DIR}/cmake/gccfilter ${COLOR_GCC_OPTIONS}")
endif()
endif()
Just like we specify input flags in the settings of the project in Xcode
Can I make few flags like -O3 or -fopenmp as default flags in command line when I use Terminal.
So that I dont have to type them everytime I compile some c++ fies. Is there a file in the installed gcc or C++ that I can edit to make them default.
Please let me know
thanks
For situations like this you'd probably use a makefile if it's project specific (or other similar automated build management like scons or cmake).
If you want it always on the terminal, you can alias your command to always specify those options, i.e.
alias g++='g++ -O3 -fopenmp'
Note that you said 'terminal' so I assume this is a type of *nix. If that is the case you can also set this into your terminal profile, like ~/.bashrc if you use bash, or ~/.zshrc if you use zsh, etc.