I want to compile some C code with GCC but having problems with linking the necessary files.
I have a simple .c file that includes 3 header files from other repo projects that I have downloaded and put in my working folder. The -I command lets me add folders to the compilation but it fails on one of the repos because it seems like the command is not recursively looking through subfolders.
How do I tell the compiler that he has to look for includes in all subfolders of my current working directory ?
Related
I am here with the problem, not getting an cpp files in gcovr output. Actually my main project consist of many sub cpp files but, they are located in different directory paths.
Directory layout:
D:\selv_ar\GCovTest\ado\cic\rc_actuator_switch\ulf\src (source directory)
test\devices\puu_driver\sw (main project directory)
core\devices\puu_driver (sub files)
test\testtools (sub files)
test\devices\puu_driver (workspace)
I have a simple hello world program with the files main.cpp, helloworld.h, and helloworld.cpp in the same directory.
Notes:
I am compiling to the embedded target debgcov_qnx660_qcc_x86 and copy the gcda files into the same directory as the source files.
I am running gcovr from the main project directory.
Questions:
When I create a coverage report for the hello world program, why doesn't it show the helloworld.h file?
When I create a coverage report for my actual software, it shows coverage for files in the main project directory. Why doesn't it show coverage for the sub files?
From which directory should I run gcvor? The main directory? The source directory? The workspace?
Where should I put the gcda files? Into the main project directory? Into the sub file directories?
When I create a coverage report for the hello world program, why doesn't it show the helloworld.h file?
Gcovr only reports a file if it contains executable code. Header files usually only contain declarations, but not function definitions. You can check whether that file was seen by running gcovr in `--verbose`` mode.
Some GCC versions have a bug so that files with zero coverage are not reported, even if they contain executable code. See the gcvor FAQ[1] for compiler versions that fix this.
[1]: sorry, the main gcovr.com website is down at the moment.
When I create a coverage report for my actual software, it shows coverage for files in the main project directory. Why doesn't it show coverage for the sub files?
Gcovr tries to filter out coverage data that is irrelevant for your project, for example coverage data for the standard library.
Gcovr only keeps the coverage data if the file path is matched by a -f/--filter.
If no filters are given, the path must be within the -r/--root directory.
If no --root is explicitly provided, the current working directory is used.
So when you run gcovr without arguments like --filter or --root, gcovr will only show coverage for files within the current working directory.
To fix this, give a root path that contains all the directories for which you want coverage, like --root ../ or --root D:/selv_ar/GCovTest/ado/cicrc_actuator_switch/ulf/src.
Or, you can provide filters that match all files where you are interested in coverage. Note that filters are regexes, so you need to escape special characters like .. Also, use forward slashes for paths in the regex. Example in shell syntax:
$ gcovr --root . \
-f 'D:/selv_ar/GCovTest/ado/cicrc_actuator_switch/ulf/src/(test|core)/devices/puu_driver/' \
-f 'D:/selv_ar/GCovTest/ado/cicrc_actuator_switch/ulf/src/test/testtools/'
Make sure that you are using gcovr version 4 or later for filters to work correctly on Windows. If you want to use --root ../ style paths, you should use gcovr 4.2 (not yet released, install the development version from GitHub in the meanwhile).
From which directory should I run gcvor? The main directory? The source directory? The workspace?
Where possible, gcovr should be run in the same directory where GCC runs. This typically means your build directory. If GCC runs in multiple directories, try to use a parent directory of all of these. Use the --root, --filter, and search path arguments to provide suitable paths to the source code and to the gcda files.
Where should I put the gcda files? Into the main project directory? Into the sub file directories?
The .gcda files must be placed next to the corresponding .o object files and .gcno files that the compiler generates. This is important so that the correct source files can be found.
If you're using cross-compilation, collecting coverage data that works can be more complicated. If you encounter problems read about GCOV_PREFIX in the “Cross-Profiling” chapter of the GCC docs and gcovr issue #259.
Gcovr searches for the gcda files in the search paths: any (unnamed) parameters you pass to gcovr. For example, gcovr --root foo bar qux specifies two search paths bar and qux. By default, gcovr searches all subdirectories of the current working directory.
I am looking for a bunch of code lines to compile a firmware project by using command prompt. I found for compiling just a .c file it's enough to write gcc -o filename.c.
However my project is a folder with a number of .c files .h files and 3 other formats and I have no idea how to run and compile the whole folder by cmd.
Here is content of project:
Would you give me some advice on what are related commands for this?
Thanks
I'm using c. And I have a include folder inside my project myProject/include and inside I have all the header files from the SDK I downloaded from the Internet. So my question is how can I tell the gcc to look for the header files inside the include folder?
You can use the -I option with gcc to tell the path where to look for the header files.
From online gcc manual
-Idir
Add the directory dir to the head of the list of directories to be searched for header files. This can be used to override a system header file, substituting your own version, since these directories are searched before the system header file directories. [...]
You can use this option multiple times,
[...] If you use more than one -I option, the directories are scanned in left-to-right order; the standard system directories come after.
I have done the following:
Create new c project (Makefile Project with Existing Code)
Added a build variable that my Makefile complained about
Now my source .c file complains about #include files because it does not know where the lib folder is,I tried adding lib folder to library path (DID NOT WORK).
How can I link my project to an external lib folder so that my .c source file can read the .h files needed for the #include?
I added the library path to Paths and Symbols->Includes BUT when I go back to the project it only shows the root folder and nothing inside it. Do I also have to add each individual .so lib file?
Answered here : How do you add libraries to Eclipse CDT? (No such file or directory)
#cyfur01 has the best answer :
What to add depends on what you are trying to include. In the case of
Boost, there are a number of header-only libraries, and there are some
libraries that require linking in static/shared-object libraries
(e.g., serialization). Header-Only Libraries
For header-only libraries, you just need to include the base directory
of all the header files. With gcc, you add the directory using the -I
flag (e.g., -I C:/path/to/boost_52_0). With a managed makefile project
in Eclipse, you can accomplish the same using Properties > C/C++ Build
Settings > Tool Settings > GCC C++ Compiler > Directories Static/Shared-Object Libraries
For static/shared-object libraries, you have to specify two options:
-l --> The name of the library, less the 'lib' prefix and the file suffix (e.g., libboost_serialization.dll -> boost_serialization
-L --> The directory to look for the library file in. This is only needed if the library is on a non-standard path.
As #Chris pointed out, for a managed makefile project, both of these
options can be set through Properties > C/C++ Build > Settings > Tool
Settings > GCC C++ Linker > Libraries
ok so I figured it out:
(1) At the start I had a source.c and a MAKEFILE
(2) Create new c project (Makefile Project with Existing Code)
(3) MAKEFILE complained about a variable so I added it to environment variable
(4) #include files complained so I added external library like so
(a) I located my library path and found that there is a folder before /lib called include
(b) The include folder had a list of header files
(c) So I added the path to the include folder NOT the lib folder under paths and symbols include
WORKED LIKE A CHARM!
I'm using QTCreator as a code editor for my C++ project, not using the real features of the qmake compilation process.
My project has several subdirectories, in all of which I ran qmake -project to create a duummy .pro file that simply lists the source and header files in the directory.
In my root folder, I simply created a "main.pro" file that includes all these "subdir/subdir.pro" files.
So it looks like this:
./
main.pro
subdir1/
/include
/src
subdir1.pro
subdir2/
/include
/src
subdir2.pro
Now my problem is, I use some files that have a special file extension (say, .ccp), which are actually some C code but are used in a different step of my compilation process.
They are naturally ignored by the qmake -project command and do not appear in my project.
I read here that I could use the qmake setting QMAKE_EXT_CPP to tell it to gather my files as a C-code file, but it doesn't seem to be working.
If I run qmake -query QMAKE_EXT_CPP, I get .cpp::.c::.ccp (which I set right before), but when running a new qmake, it doesn't take my .ccp files in account.
So, three questions:
Is it possible to make qmake take some special extensions as a C++ file, when building the .pro file?
If yes, is it correct to use the QMAKE_EXT_CPP setting?
If yes, what should be the syntax of the QMAKE_EXT_CPP setting? (mine inspired by this forum post, but it might be bogus).
You cannot change QMAKE_EXT_CPP with -project option. The list of cpp extensions used at this stage is hardcoded into qmake. However after initial creation of .pro file you can edit it to extend with support for other extensions:
in test.pro
QMAKE_EXT_CPP += .ccp
SOURCES += test.ccp
You have to add new files manually.