22

If i launch my cppcheck i get following error: cppcheck ListLib.c (information) Failed to load std.cfg. Your Cppcheck installation is broken, please re-install. The Cppcheck binary was compiled with CFGDIR set to "/usr/bin/cfg" and will therefore search for std.cfg in that path.

System : opensuse13 ,cppcheck version: cppcheck-1.64 , compiled with : make SRCDIR=build CFGDIR=/usr/bin/cfg HAVE_RULES=yes

checking if file is there: ls /usr/bin/cfg : gtk.cfg posix.cfg qt.cfg sdl.cfg std.cfg windows.cfg

whereis cfg: cfg: /usr/bin/cfg

whereis std.cfg: std: /usr/bin/cfg/std.cfg

cat std: /usr/bin/cfg/std.cfg gives me the output from that file

Stacktrace:

lstat("/home/.../ListLib.c", {st_mode=S_IFREG|0644, st_size=4568, ...}) = 0
stat("/home/.../ListLib.c", {st_mode=S_IFREG|0644, st_size=4568, ...}) = 0
open("std.cfg", O_RDONLY)               = -1 ENOENT (No such file or directory)
open("cfg/std.cfg", O_RDONLY)           = -1 ENOENT (No such file or directory)
write(2, "(information) Failed to load std"..., 213) = 213
write(2, "\n", 1)                       = 1
exit_group(1)                           = ?
+++ exited with 1 +++

changing to /usr/bin directory works: Checking /.../ListLib.c

cppcheck --check-config ListLib.c: gives the same error and works just fine if i do it in /usr/bin/

Okey for people landing on this page i got it working with the cfg files in my homefolder:

make SRCDIR=build CFGDIR=~/cppcheck_cfg and then offcourse
sudo make install

zilleplus
  • 479
  • 1
  • 3
  • 12
  • The `cppcheck --check-config` option *may* have some useful output. – R Perrin Mar 18 '14 at 18:08
  • cppcheck --check-config ListLib.c: gives the same error and works just fine if i do it in /usr/bin/ – zilleplus Mar 18 '14 at 18:22
  • This worked for me: **cd /home/kubuntu/Projects/cppcheck && make SRCDIR=build CFGDIR=/home/kubuntu/Projects/cppcheck/cfg/std.cfg -j3 && sudo make install -j3** It seems like CFGDIR must actually be a file NOT a directory! – Alex Bitek Jun 16 '14 at 21:26
  • 1
    CFGDIR has to be a Dir note how it states CFDIR and not CFG file , from the muanual: The .cfg files are needed by cppcheck. Either put them in a subfolder cfg where the binary is. Otherwise compile cppcheck with CFGDIR to specify an arbitrary path where you put the .cfg files. I even have multiple cgf files dont see this working properly, seems bad practice – zilleplus Jun 18 '14 at 14:07
  • The cppcheck README gives the preferred make line: https://github.com/danmar/cppcheck – phoenix Jan 28 '16 at 20:03

6 Answers6

26

I faced the same problem too.

Solution:

$ make SRCDIR=build CFGDIR=/usr/share/cppcheck/

$ sudo make install CFGDIR=/usr/share/cppcheck/

Got suggestions from the cppcheck community members and came to know that 'make install' also requires the CFGDIR option to be passed.

prabhugs
  • 742
  • 7
  • 20
  • 2
    I dug into the Makefile and found out the reason: `make install` also builds the code inside the `lib` directory, which does not get compiled by simply calling `make`. – foraidt May 26 '15 at 12:04
4
make SRCDIR=build CFGDIR=/usr/bin/cfg HAVE_RULES=yes

make install CFGDIR=/usr/bin/cfg
  • 4
    I think it would benefit the question and future users if you were to explain what this does step by step. – Elias Aug 29 '14 at 13:50
  • Only thing different here is the HAVE_RULES=yes, i just saw that the manual now recomments have_rules=yes. Just "make install" is also fine here no point in repeating CFGDIR=/usr/bin/cfg. – zilleplus Aug 31 '14 at 09:13
2

I had same issue few days ago and solved by changing the way I run makefile on cppcheck.

I use Linux Red Hat version and cppcheck version is 1.65.

make SRCDIR=build CFGDIR=/home/###/####/cppcheck-1.65/cfg/ && make install

I didn't really dig into the detail but makefile of cppcheck look like they are clearing up obj and build cppcheck including cfg location by first make command

make SRCDIR=build CFGDIR=/home/###/####/cppcheck-1.65/cfg/ &&

and second make command would distribute cppcheck into /usr/bin/ location.

make install

Now all you have to do is to set up bash.

j. cho
  • 71
  • 1
  • 11
1

Check permissions, with file /usr/bin/cfg/std.cfg, to ensure you have permissions to access the config file that you think it should be trying to read.

Then, failing that, run cppcheck under strace to find the system call that's failing: strace -o /tmp/strace.out cppcheck ListLib.c.

R Perrin
  • 471
  • 3
  • 8
  • permissions are 777, i tried the stacktrace and got following error: open("std.cfg", O_RDONLY) = -1 ENOENT (No such file or directory) open("cfg/std.cfg", O_RDONLY) = -1 ENOENT (No such file or directory) write(2, "(information) Failed to load std"..., 213) = 213 write(2, "\n", 1) = 1 exit_group(1) = ? if i do whereis std.cfg i get std: /usr/bin/cfg/std.cfg – zilleplus Mar 18 '14 at 17:52
  • The strace output suggests it's only checking the current directory and a "cfg" subdirectory for the ".cfg" files. Try cding to /usr/bin before running cppcheck to see if that satisfies it. (My version of cppcheck (1.60.1) does not have the CFGDIR build-time configuration option) – R Perrin Mar 18 '14 at 18:02
  • This suggest to me that the CFGDIR setting is not working as expected. Perhaps try rebuilding cppcheck in a clean directory, to ensure the CFGDIR setting is as you expect. Then run the cppcheck built there. – R Perrin Mar 18 '14 at 18:37
  • Thank you for your help, posted the solution for others – zilleplus Mar 18 '14 at 19:19
0

I ran into the same problem running cppCheck GUI on a directory after compiling it on a Mac with Qt Creator and running the GUI version. I solved the problem by copying "std.cfg" into the application folder: Contents/MacOS You have to right-click the cppcheck-gui application to access the contents. Its seems to be ok to put it beside the cppcheck-gui file in the same folder as that must be where it checks first. The "std.cfg" file can be found in the cfg folder.

0

As @prabhugs said, I will make more description. In the source code of the github,cppcheck, It's recommended that the make syntax is:

$ make SRCDIR=build CFGDIR=cfg HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function

where the "CFGDIR" option is a dirction that you can spicify. For example:

$ make SRCDIR=build CFGDIR=/usr/share/cppcheck HAVE_RULES=yes CXXFLAGS="-O2 -DNDEBUG -Wall -Wno-sign-compare -Wno-unused-function

And then, you can use this sytax:

$ sudo make install CFGDIR=/usr/share/cppcheck/

after these step ibelieve you can enjoy the cppcheck.

William
  • 11
  • 3