cppcheck --includes-file option does not work - cppcheck

cppcheck --includes-file=<filename> --enable=all --check-config <source code directory> does not work. Cppcheck says unable to find the header files.
<filename> has the directory where the header file is located.
If I give the same command as follows:
cppcheck -I <path to header file> --enable=all --check-config <source code directory>, then it works fine.
I find this very strange. Any suggestions?

sounds strange. I recommend that you upgrade cppcheck, your version is quite old. latest cppcheck version is 1.68.

Related

Setting Up Neovim for C++ with CMAKE

I'm using coc for code-completion and ale for linting my c++ files, this works fine when I have all my headers and source files in the same directory, however when I have a CMake project with the typical include & src directories (for headers and .cpp files respectively) this setup fails to realize that my headers are in the include directory and so the linting and code completion dont work.
Any help in configuring my neovim setup to handle this project structure, or suggestions of different plugins which would do what I want would be much appreciated.
Please check CMake's documentation regarding CMAKE_EXPORT_COMPILE_COMMANDS.
Here is part of my .nvimrc for example:
nnoremap <F5> :wa <bar> :set makeprg=cd\ build\ &&\ cmake\ -DCMAKE_BUILD_TYPE=debug\ -DCMAKE_EXPORT_COMPILE_COMMANDS=1\ ../view\ &&\ cmake\ --build\ . <bar> :compiler gcc <bar> :make <CR>
This generates the compile_commands.json file which is read by the various ALE Supported Languages and Tools.
There is a nice Plugin cmake4vim which works really fine.
You can e.g. set the name of the build path, run/edit config (incl. the ccmake tool), build within vim, jump to next error, ...

Modifying the "priorities" between include directories within a Makefile

To make it simple, I want to use the OpenCV libs within my embedded ElinOS system, while programming on my Windows machine.
To do so, I downloaded OpenCV sources for Linux on the website and I'm trying to compile it using cygwin and cmake to generate the Makefile. However, I have an error occuring during the "make" step, which is /usr/include/wchar.h:41:25: fatal error : bits/wchar.h : No such file or directory
I understand the problem, which is basically that cygwin should use /opt/elinos-6.0/cdk/x86/x86_64/eglibc-2.17/x86_64-unkown-linux-gnu/include instead of /usr/include but I have basically no idea how to change that.
That far, I added those two lines to the CMakeLists.txt
set(CMAKE_INCLUDE_DIRECTORIES_BEFORE ON)
include_directories(BEFORE C:/sysgo/opt/elinos-6.0/cdk/x86/x86_64/eglibc-2.17/x86_64-unkown-linux-gnu/include/)
and this line to the builded Makefile:
INC = -I/cygdrive/c/sysgo/opt/elinos-6.0/cdk/x86/x86_64/eglibc-2.17/x86_64-unknown-linux-gnu/include/
But it didn't work, I still got the same error. Any help is welcome, and I would be glad if an explanation comes with the magic command line(s) that will help.
Thanks in advance!
one way for you might be to clear the standard include path completly:
first delete standard path with -nostdinc and then put your own directories in it.
you might not want loose all of them, here is a way to see which are used in the standard include path: echo "//" | gcc -xc++ -E -v - (works also with clang)
Here is a fine article for this for gcc :
http://commandlinefanatic.com/cgi-bin/showarticle.cgi?article=art026
here you can read it works with clang too:
http://clang.llvm.org/docs/CommandGuide/clang.html

Clang-Tidy can't find my header files

new to clang and clang-tidy here.
I have a project with this type of structure:
project/
- build/
- cmake/
- component1/
- src/
- someFile.cpp
- someFile2.cpp
- someFile.hpp
- someFile2.hpp
- component2/
- etc...
-
When I use clang-tidy to go through all the files in project/component1/ with this command: clang-tidy project/component1/src/* -checks=-*,clang-analyzer-*,-clang-analyzer-alpha*
It ends up throwing an error like this:
$HOME/project/component1/src/someFile.cpp:18:10: error: 'project/component1/someFile.hpp' file not found [clang-diagnostic-error]
\#include "component1/someFile.hpp"
This answer will only help you if you use CMake to manage your project.
CMake has an option to create a .json file that contains all the compiler calls with command line options. This file can be given to clang-tidy with the option:
-p <build-path> is used to read a compile command database.
For example, it can be a CMake build directory in which a file named
compile_commands.json exists (use -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
CMake option to get this output). When no build path is specified,
a search for compile_commands.json will be attempted through all
parent paths of the first input file . See:
http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an
example of setting up Clang Tooling on a source tree.
As the documentation states, you have to set the CMAKE_EXPORT_COMPILE_COMMANDS variable to generate the .json file with CMake and then pass the CMake output directory to clang-tidy.
Clang-tidy will then get the include paths from the commands in the .json file.
I tell clang-tidy to search for them using plain compiler includes, but they have to be introduced after a double dash (--). It also took me a while to discover it, since it is not included in the --help:
clang-tidy -checks='...' <source0> ... -- -Iblabla/ ...
Reading again the options, you coult try -extra-arg= parameter, but I use the double dash approax since it allows me to put all the options to give clang and clang-tidy in a single file, with no more processing than a $(cat $file) for both.
From: https://clang.llvm.org/extra/clang-tidy/#using-clang-tidy
clang-tidy is a LibTooling-based tool . You can also specify compilation options on the command line after --
Had the same problem in CMake. The problem in my case was that Clang-Tidy could not handle include directories via response files – at least in version 10.
Deactivating them solved it:
# Disable response files
set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES Off)

how to generate glut .so file in Linux

I would like to generate glut .so file in Ubuntu. I've downloaded the files, extracted them and opened the readme. This is the instructions for Linux
MAKEFILE GENERATION TO BUILD GLUT: <-- IMPORTANT!
Use "mkmkfiles.sgi" to put Makefiles using the SGI Makefile conventions
in place. Use "mkmkfiles.imake" to put Makefiles generated from
Imakefiles in place. Run one of these two commands in this directory,
then do a "make".
I don't really understand SGI Makefile. I know Makefile though. Could you please guide me for generating the dll. In the folder, these are the files
adainclude Imakefile mkmkfiles.imake README.fortran README.man
CHANGES include mkmkfiles.sgi README.glut2 README.mesa
FAQ.glut lib mkmkfiles.win README.glut3 README.mui
Glut.cf linux NOTICE README.ibm-shlib README.win
glutdefs Makefile Portability.txt README.inventor README.xinput
glutmake.bat Makefile.sgi progs README.irix6 test
glutwin32.mak Makefile.win README README.irix64bit
IAFA-PACKAGE man README.ada README.linux
I've tried running make but getting errors and there is no CMakeLists. Thank you.
When I run ./mkmkfiles.sgi or mkmkfiles.imake, I get this error
bash: ./mkmkfiles.sgi: /bin/csh: bad interpreter: No such file or directory
Technically you need first to instal tcsh. With that installed, running mkmkfiles.imake will work and generate the required Makefile so you can build on Linux. Here is an old post asking pretty much the same question: http://comments.gmane.org/gmane.linux.lfs.general/17539

fPIC compiling error: no such file or directory

I am running elementary OS 64-bit and have the source code for the following project on github:
https://github.com/pellegre/libcrafter
I however get the following error when trying to configure it via the ./configure command:
After that I check the config.log file:
Anyone know why this could be? I've compiled with fPIC before without hassle.
Example from the configure file in the folder:
Update for Peter in comments: