CMake: suppress developer warnings - compiler-flags

Description:
I am using cmake-gui on Ubuntu to compile programs.
I often encountered warning messages for developpers ending by:
This warning is for project developers. Use -Wno-dev to suppress it.
I tried to insert this -Wno-dev flag in the CMAKE_CXX_FLAGS box but it doesn't suppress the warnings.
Questions:
I have now two very simple questions:
1) Where exactly should I insert this flag?
2) How to separate it from other existing flags (if any) ?

Probably does not solve your problem with the gui but adding the -Wno-dev from command line works.
The flag does not belong to the CMAKE_CXX_FLAGS that are specific for compiler not for CMAKE.
Instead you can suppress the message setting the cmake_policy

Related

WinDbg: Unable to verify checksum for EXE file

I realize a question with the exact title has already been answered, but the steps there requires running the compiler and linker manually, whereas I want to use cmake.
I am trying to debug a C program with WinDbg. But I'm getting this error:
*** WARNING: Unable to verify checksum for main.exe
Reading a mailing list thread1, I'm guessing I need to add a few flags, namely '/Zi' and '/Release'. But I'm building my project with cmake, and I don't know how to add those flags properly so that I can build my program using GNU toolchain with debug symbols too.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.00)
project(Hello LANGUAGES C)
add_executable(main src/main.c)
With the above cmake file, my program is built properly. Even a pdb file is generated, which is read by WinDbg no problem. But I can't see the line information with .lines and no source file is shown when debugging the EXE; only assembly commands are shown.
After the reading the mail thread (mentioned above), I checked the checksum value of my EXE. It's zero. Now I need to know how to set up a cmake file so it produces EXE with debug symbols with proper checksum.
The checksum-verification warning turned out not to be the issue (it was just a warning after all, not an error). WinDbg didn't load line information. Either it's the default (although I don't know why that would be) or I mistakenly turned it off myself. Whatever the case, here is how you turn it on:
.lines -e
After that, WinDbg was able to bring up the source window by its own accord when I started debugging.

CMake project in Visual Studio gives flag override warnings (Command line warning D9025: overriding '/W4' with '/w')

I have a CMake project, which I am building with Microsoft Visual Studio 2019. I am trying to fix and remove all warnings, but there is one type which I can't disable or fix.
All of them are of the type:
Command line warning D9025: overriding '/W4' with '/w'
Command line warning D9025: overriding '/W3' with '/W4'
I tried fixing them, but I can't find out what's causing all of them.
My question is:
How can I disable the warnings using CMake? Or is there a surefire way to find the underlying cause of them and fix them?
This issue has been raised (here and here), and depending on your CMake version there are a couple solutions.
When building for MSVC with CMake, the compiler warning flags (like /W3) are added by default. In CMake 3.15, CMake introduced a fix for this, and the compiler warning flags are no longer automatically added so the warning should no longer appear. From the docs:
CMake 3.15 and above prefer to leave out warning flags from the value of CMAKE_<LANG>_FLAGS by default.
Along with this fix, CMake introduced policy CMP0092, which allows you to switch back to the OLD behavior (adding the warning flags by default) if necessary.
If you are tied to a CMake version older than 3.15, you can manually manipulate the CMAKE_<LANG>_FLAGS variable to replace the warnings yourself using CMake's regular expressions. You can try something like this:
string(REGEX REPLACE "/W[3|4]" "/w" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
I had this problem even though I was using CMake 3.19. It was caused by having the project command before the cmake_minimum_required command.

Make interprets compiler options as shell command

I'm trying to compile fbsplash under Tiny Core Linux using autotools. In the middle of compilation it crashed saying "LD: attempted static link to dynamic object /usr/local/lib/libpng16.so"
I've got rid of that, commenting out option "-all-static" in the Makefile. Now it crashes after
/bin/bash: O2: not found
/bin/bash: w: not found
/bin/bash: DTARGET_KERNEL: not found
All of these options have dashes before them. It looks like:
fbcondecor_helper_CFLAGS = -O2 -w \...
fbcondecor_helper_CPPFLAGS = $(AM_CPPFLAGS) -DTARGET_KERNEL
But somehow my shell interprets them as commands without dashes.
What's wrong?
First, you are not using the autotools. You are using a configure script that was generated using the autotools. (If indeed you are running autoconf, or autoreconf, that is a different issue and there is (much) more room for error on your part.) In either case, you should never hand edit the generated Makefile. (So short answer to "What's wrong?" is, "you edited the Makefile".) Instead, add --disable-static when you run configure.

debugging Android NDK application problems

i had a problem in my native android application saying libc: Fatal signal 7 (SIGBUS) at 0x66f0001d (code=1), thread 30165 (xample.fft_test)
which i think is a memory problem on the device(nexus 4).
So, i tried to debug the application to know the source of this problem.
In eclipse, i get warning: Could not load shared library symbols for 94 libraries, e.g. /system/bin/linker.
Use the "info sharedlibrary" command to see the complete listing.
Do you need "set solib-search-path" or "set sysroot"?
warning: Unable to find dynamic linker breakpoint function.
GDB will retry eventurally. Meanwhile, it is likely
that GDB is unable to debug shared library initializers
or resolve pending breakpoints after dlopen().
what does that mean?
here's also the output of the allocation tracker in eclipse:
If your application.mk has flags:
APP_STL := gnustl_static
APP_OPTIM := debug
You have a problem with the compilation´s flags.
The warning means those libraries have not compiled with debug flags, and then, you have not debug info so you cannot debug. Maybe you can stop in breakpoints and follow step by step, but you cannot read in real time the value of the variables.
So, to solve the problem, you must re-compile the libraries that you want to read variables with debug information flags. In Cmake I usually use flag -d or -gdwarf-4 to crosscompile in Android.
I had the same issue and I solved it by using another phone.
I tested on a lot of phones. Finally, I find out that debug NDK on Nexus 6 is ok.
So I think maybe the issue is that the support for debugging NDK was removed on some phones.

How to debug a program compiled with 'make'?

Tutorials for gdb suggest compiling with 'gcc -g' to compile the program with debug symbols.
However, I want to debug a program compiled with make. How can I instruct make to compile with debugging symbols?
Thanks.
In order to change your compile options you need to edit the file 'Makefile' in the directory from which you run 'make'. Inside that file look for one of the following things:
The variable which defines you compiler, probably something like:
CC='gcc'
The actual line where your compiler gets called (more likely in hand-made Makefiles).
Variables called CFLAGS or CXXFLAGS
In the first two cases, just add '-ggdb' after 'gcc', in the third case it's even easier just add '-ggdb' like:
CFLAGS='-ggdb'
The makefiles I have to deal with (created by others) frequently don't make it easy to change the options to the compiler. Simply setting CFLAGS on the command line is easy but clobbers many other important compilation options. However, you can often deal with the issues by overriding the compiler macro on the make command line:
make CC="gcc -g" ...other arguments...
You need to ensure everything you're interested in debugging is compiled with the debug flag. You might use make cleanup or make clean to clear the debris, or you might resort to simpler measures (rm *.o *.a *.so or its equivalent). Or, if you have GNU Make, then use -B or --always-make to force it to rebuild everything.
If you have multi-directory builds, you need to do this in all the relevant directories.

Resources