Unknown pragma when compiling OpenMP with g++ - c++

I am working on C++ code which contains openmp pragmas. While trying to compile with g++, I am receiving the following error message:
ignoring #pragma omp parallel [-Werror=unknown-pragmas]
I understand that the error is from not using fopenmp flag with in the makefile. I have tried including the fopenmp flag to the CXXFLAGS. Still, it is not working.
Would anyone think of solutions to work around this issue?
Note: This question looks like a repeat question of similar question on same error and I have gone through and tried it too. Therefore, I would request this question not to be flagged as repeat question.

This is warning appears if you compile OpenMP code without the -fopenmp flag. The g++ man page tells us what -fopenmp does:
Enable handling of OpenMP directives "#pragma omp" in C/C++ and
"!$omp" in Fortran. When -fopenmp is specified, the compiler
generates parallel code according to the OpenMP Application Program
Interface v3.0 http://www.openmp.org/. This option implies
-pthread, and thus is only supported on targets that have support
for -pthread

Related

-mimplicit-it compiler flag not recognized

I am attempting to compile a C++ library for a Tegra TK1. The library links to TBB, which I pulled using the package manager. During compilation I got the following error
/tmp/cc4iLbKz.s: Assembler messages:
/tmp/cc4iLbKz.s:9541: Error: thumb conditional instruction should be in IT block -- `strexeq r2,r3,[r4]'
A bit of googling and this question led me to try adding -mimplicit-it=thumb to CMAKE_CXX_FLAGS, but the compiler doesn't recognize it.
I am compiling on the tegra with kernal 3.10.40-grinch-21.3.4, and using gcc 4.8.4 compiler (thats what comes back when I type c++ -v)
I'm not sure what the initial error message means, though I think it has something to do with the TBB linked library rather than the source I'm compiling. The problem with the fix is also mysterious. Can anyone shed some light on this?
-mimplicit-it is an option to the assembler, not to the compiler. Thus, in the absence of specific assembler flags in your makefile (which you probably don't have, given that you don't appear to be using a separate assembler step), you'll need to use the -Wa option to the compiler to pass it through, i.e. -Wa,-mimplicit-it=thumb.
The source of the issue is almost certainly some inline assembly - possibly from a static inline in a header file if you're really only linking pre-built libraries - which contains conditionally-executed instructions (I'm going to guess its something like a cmpxchg implementation). Since your toolchain could well be configured to compile to the Thumb instruction set - which requires a preceding it (If-Then) instruction to set up conditional instructions - by default, another alternative might be to just compile with -marm (and/or remove -mthumb if appropriate) and sidestep the issue by not using Thumb at all.
Adding compiler option:
-wa
should solve the problem.

GCC: Use -Werror but downgrade a specific error to a warning (in command-line)

An example: I'm using -Wall -Werror and -Werror. This means unused static functions break the build. Clearly (?) unused functions are Bad, but if I'm working on code and it's in an intermediate state, want to be able to leave unused code in there. I can turn off the error with -Wno-unused-function, but then there's a risk that I'll finish what I'm working on, commit the code, and forget to remove the now-unused function.
How can I set all warnings to errors with -Wall, but downgrade specific errors to warnings, without disabling them completely?
Use the -Wno-error= flags. In the example, the required flag would be -Wno-error=unused-function.
PS: There are also pragmas for this purpose: http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html (my original question was "How can I do what these pragmas do, but in the command-line flags?" but I worked it out as I was asking it).

max number of allowable warnings while compiling

Is it possible to 'tell' compiler that if total number of warnings (while compiling a C++ program) are more than say 10 then stop compiling further, and emit an error?
Or is it possible to hack a compiler like clang to provide this functionality.
GCC has two options together would achieve this, from gnu online docs:
-Werror
Make all warnings into errors.
-fmax-errors=n
Limits the maximum number of error messages to n, at which point GCC bails out rather than attempting to continue processing the source
code.
This would make a build with any warnings fail though, the options just define when to stop parsing.
I haven't seen this kind of feature in gcc or clang. You can certainly try to patch it into either of them, both are open source. There is also -Werror (accepted by both compilers) which simply treats warnings as errors.
How about using -Werror to make warnings into errors and -fmax-errors=n to set the limit.
(Also, perhaps making your code completely warning free would be a good thing).

llvm-g++-4.2 and C++ new-style type casting

I'm facing a weird problem. I looked around all over stackoverflow.com and elsewhere, but I didn't find an answer.
Here's some background: I'm writing a simple library; mostly for educational purposes and to understand C++ better. I'm using a MacBook Pro with Snow Leopard. I have an installation of Xcode 4.2 as well, however I use only VIM to edit my code. I recently finished implementing the GNU build system for whatever I have so far, so that I do not have to depend on Xcode anymore, and at the same time not have to write and maintain custom Makefiles. I'm using highest levels of warnings. Here're the flags I've got so far (but I keep adding on to them incrementally, understanding the reasons for each flag as I go): -Wall -Wmissing-field-initializers -Wno-trigraphs -Wreturn-type -Wnon-virtual-dtor -Woverloaded-virtual -Wmissing-braces -Wparentheses -Wswitch -Wunused-value -Wsign-compare -Waddress -Wsequence-point -Wshorten-64-to-32 -Wwrite-strings -Wold-style-cast, and finally, -Werror.
Now, I have a function which very simply returns a value:
wint_t weof() {
return static_cast<wint_t>(WEOF);
}
However, when I compile this code, I get the warning "use of old-style cast". I don't understand how static_cast<> can be "old-style". Could anybody explain to me why this is happening? I thought I'd find the answer by looking at the definition of WEOF, but on Mac it's defined to __DARWIN_WEOF and I can't seem to find the definition of that.
Thanks!
Most likely the __DARWIN_WEOF macro itself is using an old-style cast (doing some web searching, it seems the value is likely ((__darwin_wint_t)-1)). If you are using C-compatible headers, it's unlikely you'll be able to fully enable -Wold-style-cast.
As a workaround, you could try surrounding any offending code with an appropriate #pragma to disable this warning.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
// ... code goes here ...
#pragma GCC diagnostic pop
But this will probably get pretty tiresome/verbose after a while...

two fortran questions

Is there any way for gfortran to compile a f90 program but with a non-f90 extension, or even no file extension at all?
How to suppress pause statement warning used in a f90 program when compiled with gforTRan?
Many thanks.
gfortran -c sourfile.xyz does not work. I know the manpage explains these options, but I did not find one working.
I mean in my f90 program, I have a pause statement. If I compile it, I got a warning saying the use of pause is obsolete. I want to suppress this warning during compilation.
Suppress all warnings with -w option?