Gcov works, but Gcovr doesn't work - c

When I run gcov then the output says 87% covered... then I want to use gcovr, but it does never work. I tried to run from many directories, with lots of options. In some cases, a few files I get coverage but not the file I want to see.
My project consists of 3 files:
src\main.c
src\makefile
tst\test1.c
tst\test2.c
tst\makefile
tst\obj\all object files, gcno, gcda are stored here...
build\build.bat to make the project (windows)
Should I change the directory structure? How to see which version of gcov I should use?
I want to see the coverage for main.c, but only get the coverage for test1.c and test2.c and those are not relevant for coverage!!
Next to the test files, I have include directories on C:\compiler which are not required for coverage.
I tried Python27:
python c:\python27\scripts\gcovr -g --object-directory=. -r ..\..\..\ --html --html-details -o program.html -v
I tried Python36:
c:\python36\scripts\gcovr --use-gcov-files -v --object-dir=.
But never get the coverage for my device under test. Only gcov without gcovr works, so the files must be correct.

try add -f '' option. There bug in gcovr which is getting out when we build out of tree

I found several problems when running the GCOVR in Windows, especially concerning \ instead of / and using colon character : in the name like C:\file.c
When you use \ it needs to use 2 of them \ and somewhere in the gcovr it changes to \\ or \\\ ... this is not going well, at some point it tries to find the root of your source files by subtracting 2 paths. but it cannot find this, e.g.
\a\b\c\d it will not find in \a\b\c\d . So, look in : [github.com/barthoukes/gcovr][1]
THe solution is still very dirty, but it works for my projects in Windows. I think the gcovr people also are discussing this problem.
You only need the file: gcovr

Related

Valgrid v3.12 won't compile [duplicate]

I'm trying to install Valgrind on a Mac with Snow Leopard but am getting an error. This is what I'm typing into Terminal.
$ curl -O http://valgrind.org/downloads/valgrind-3.8.1.tar.bz2
$ md5sum valgrind-3.8.1.tar.bz2
$ tar -xjvf valgrind-3.8.1.tar.bz2
$ cd valgrind-3.8.1
$ ./configure
$ make
This is the error I get.
Making all in coregrind
make[2]: *** No rule to make target `/usr/include/mach/mach_vm.defs', needed by `m_mach/mach_vmUser.c'. Stop.
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
How can I correct this error?
Make sure to install the command line tools.
xcode-select --install
The best way to get valgrind compiled properly is to use the 'xcode-select --install' command as mentioned in the above answer.
However, as sub-optimal hack, you can get it compiled by downloading the following files from OSX /mach source into /usr/include/mach (create this directory):
mach_vm.defs
task.defs
thread_act.defs
vm_map.defs
It's a slightly dirty hack, but it should get you going if you really don't want to download/install the large Xcode original files.
Apparently, to compile on a Macintosh, valgrind needs the file /usr/include/mach/mach_vm.defs to be present. While I haven't been able to find specific references to mach_vm.defs being part of XCode specifically, it seems that most of the usual contents of /usr/include/mach are installed when XCode is.
If for some reason you can't install XCode on your machine, you can get most of the source files for that particular directory from this part of apple's open source website.
Ever since the System Integrity Protection system was put in place on OSX, the user, not even as root, can modify /usr. Thus, modifying /usr/include/mach to add the necessary files becomes impossible. The only alternative is now to edit the makefile itself.
The Makefile at hand should be located at coregrind/Makefile, and the mach files should be located near /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/ (replace MacOSX10.12.sdk with the appropriate version of OSX).
There should be a symbol named am__append_17 defined around line 160 or so (might be elsewhere for different versions).
It should look something like this:
am__append_17 = \
/usr/include/mach/mach_vm.defs \
/usr/include/mach/task.defs \
/usr/include/mach/thread_act.defs \
/usr/include/mach/vm_map.defs
Replace each instance of /usr/include with /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/, so that it looks like:
am__append_17 = \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/mach/mach_vm.defs \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/mach/task.defs \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/mach/thread_act.defs \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/mach/vm_map.defs
After this, valgrind should compile properly

Msys make in Powershell - No such file or directory

I installed the base package to compile C++ with MinGW Installer GUI and CMake. I created a simple file .c with hello world, and can use cmake . -G"MSYS Makefiles" normally. I added E:\Programmation\MinGW\bin and E:\Programmation\MinGW\msys\1.0\bin to my path.
Here is my CMakeLists.txt:
cmake_minimum_required (VERSION 3.3)
project (Prototype)
set (EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})
file (
GLOB_RECURSE
source_files
src/*
)
add_executable (
my_exe
${source_files}
)
Once the makefile is created however, when I use make I'll get the following error:
/bin/sh:/e/Users/MyName/Documents/GitHub/ProjectName/prototype/c/E:/Programmation/MinGW/msys/1.0/bin/make.exe: No such file or directory
make.exe": *** [all] Error 127
I can compile the file main.c just fine with gcc main.c and the exe it produces works, so the problem is with the make.exe.
If I use it in the msys.bat shell, located in E:\Programmation\MinGW\msys\1.0, it works as it should. So my guess is that the problem is with Powershell and the path. I'm thinking maybe it's because of the way hard drives are designated, since in the error I get it calls my E:\ disk /e/ first then E:/. When I work in msys.bat I have to write it this way: /e/Users/MyName...
This is PEBKAC. The problem is not with make.exe, but rather, in the way you are attempting to misuse it.
How many times must I say this? Using MSYS make.exe, (or indeed any of the MSYS tools), in any environment other that the MSYS shell, which is started by running msys.bat, is definitively unsupported by the MSYS Project maintainers.
Since you say you problem goes away, when you use make.exe as you are supposed to, (in the MSYS shell, invoked by running msys.bat), this is your problem, and your problem alone. It apparently does not work, when you attempt to use it improperly, (i.e. from PowerShell): that's tough luck; when you break free software, by misusing it, you get to keep all the pieces.
Contrary to the accepted answer, it is actually possible to do this using PowerShell:
sh.exe -c "cd ""$pathToMake""; make"
Make sure you sanitise backslashes for the shell before the call above.
$pathToMake = $pathToMake -replace "\\", "/"
Also the MSYS bin has to be in your path, which would typically look like this (your path maybe different):
$env:Path = "C:\GNUstep\msys\1.0\bin;$($env:Path)"

Compiling C code with external library references

I am on RHEL 6.0 and got hold of the source code for join command(hopefully from the right source!!). I rarely work on a C code and hence finding this difficult. I am trying to compile and run the C code for join, but running into compile time errors.
g++ join.c
join.c:19:20: error: config.h: No such file or directory
join.c:25:20: error: system.h: No such file or directory
join.c:27:25: error: hard-locale.h: No such file or directory
join.c:28:24: error: linebuffer.h: No such file or directory
join.c:29:24: error: memcasecmp.h: No such file or directory
join.c:30:19: error: quote.h: No such file or directory
join.c:31:21: error: stdio--.h: No such file or directory
join.c:32:22: error: xmemcoll.h: No such file or directory
join.c:33:21: error: xstrtol.h: No such file or directory
join.c:34:22: error: argmatch.h: No such file or directory
Since I am not aware of where to find these libraries(I did google for each one and they are spread all over different websites), can anyone please guide me as to how I can link these libraries together and compile the source code of join command?
This is not a linking problem as you suggest. Instead, you get these errors because g++ can't find these files: config.h, system.h, ..., that are #included (indirectly) by join.c.
What you could do is find these files on your system, and then add as many -I<directory> options behind the g++ as there were directories you found these files in. Do man g++ for more info.
You'll also need to find the where the libraries are you need to link against. So you'll need to specify more than -I's.
On the other hand, aren't there 'configure' or other package files? Normally you don't have to specify compiler flags (like this -I) by hand. Instead, it's common that for example Makefile's are generated from such a configuration file, after which you just have to type make.
I advise you to get someone that has done this before, because you don't seem to understand the basics of C program compilation. This can cost you a lot of your precious time without results. But good luck anyway!
Perhaps you don't have everything in place to compile your code. Try installing the build-essential package.
sudo yum install build-essential
On a relevant note, I'm not aware of the script join.c but if you are looking for a way to concatenate a bunch of files together, you can do cat FILE1 FILE2 FILE3 > BIG_FILE where FILE1 FILE2 FILE3 are the files you want to join them. Under RHEL 6.0, you can use asterisks too, if there is a pattern. For example, cat FILE.00* > BIG_FILE

Trying to adapt existing c project to CUDA, .cu files not found by Makefile

I'm trying to accelerate a key function in a c project (not c++) using CUDA.
For some reason, i can't get the Makefile's to recognise the .cu extension when I change the name of one of the files to .cu.
It's using a configure script and .am/.in/.deps files, which I don't really understand all that well, but basically I grepped references to file.c and changed them all to file.cu, but it produces a file.o: File Not Found error.
Top level make file
https://www.dropbox.com/s/g282qvbdu8pdas0/Makefile
Src folder makefile
https://www.dropbox.com/s/b4pq026od8gauqi/Makefile
The search command I used was
grep -R -i "file.c"
and I simply changed them all to file.cu, then re-ran configure, make clean, make all - result is File Not Found.
I suppose it must be something to do with extensions being ignored/accepted by the Makefile, but as it's been a long time since I've programmed in C and I've never used such complex Makefiles I don't know how to fix it.
Any ideas?
*PS Also, file.cu has compile errors at the moment, but the error message I'm getting is File Not Found, so I think that's not the problem.
You need to have a rule to build o file from a cu file:
cudafile.o: cudafile.cu
nvcc $(NVCC_FLAGS) -c %< -o $#
So you also need to specify the rule for the cu file, and use nvcc for compilation.
The following guide seems to cover it...
http://mcclanahoochie.com/blog/2011/02/automake-and-cuda/
Actually, most of the advice given in the link seems unnecessary for basic compilation, but for some reason I found that when I re-created the config file using autoconf it worked. No explanation comes to mind.

How to use FLEX in CMAKE

I am trying to figure out what I am doing wrong when trying to use just flex in a Cmake file to build a shared lib.
i basically have the following
find_package(FLEX)
FLEX_TARGET(Test ../src/test.l ../src/test.c)
set(SRC_FILES mysource.c ${FLEX_Test_OUTPUTS})
add_libary(testlib ${SRC_FILES})
target_link_libraries(testlib crypto c ${FLEX_LIBRARIES})
this is giving me a problem saying it cant find ../src/test.c
any ideas how I can make sure Lex ran first? secondly,how can i pass my -L and -d options to lex (like I am doing in my normal, pre-cmake version of this makefile)
Why do you want output file to be in the source dir?
I'd recommend using ${CMAKE_CURRENT_BINARY_DIR}:
FLEX_TARGET(Test ../src/test.l ${CMAKE_CURRENT_BINARY_DIR}/../src/test.c)
As for
any ideas how I can make sure Lex ran first?
you don't need to do it, CMake can guess this dependency by it's own. I think the problem is either in using source dir for output file, or the ../src dir doesn't exist before flex runs.
secondly,how can i pass my -L and -d options to lex
List them after the output parameter:
FLEX_TARGET(Test ../src/test.l ${CMAKE_CURRENT_BINARY_DIR}/../src/test.c -L -d)

Resources