Menu

compile cppcheck from sources on Windows o.s. machines

2017-12-29
2018-01-14
  • Giangiacomo Zaffini

    Hi,
    I'm used to compile cppcheck from sources on Windows o.s. machines.

    To my knowledge it is quite as easy task but I want to point out some tricks that I do in order to compile.

    I consider two scenarios, common of both scenarios is latest cmake (for the time being cmake 3.10):
    1) compiling with Visual Studio 2017 Community edition
    2) compiling with minGW (this case it is indeed a double case, because I consider both Lavavej's minGW and MSYS2/minGW-32(x86)/minGW-64(x64))

    for
    1) Visual Studio 2017 Community edition, everything is fine but a library (Shlwapi.lib) is missing when liinking cppcheck. I added Shlwapi.lib to cppcheck project with Configuraion properties -> Linker -> Added dependencies. This is because in .\cli\filelister.cpp MyDirectory function uses PathIsDirectoryA Windows API function defined in Shlwapi.lib.
    2) minGW/MSYS2/minGW-32(x86)/minGW-64(x64), I changed .\cli\filelister.cpp module and its MyDirectory function in order to compile in GetFileAttributes function and compile out PathIsDirectoryA Windows API function, following panel is a recap of source modification (for MSYS2/minGW-64(x64))

    ///////////////////////////////////////////////////////////////////////////////
    ////// This code is WIN32 systems /////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////
    
    #include <windows.h>
    #if !defined( __BORLANDC__ ) && !defined( __MINGW64__ )
    #include <Shlwapi.h>
    #endif
    
    // Here is the catch: cppcheck core is Ansi code (using char type).
    // When compiling Unicode targets WinAPI automatically uses *W Unicode versions
    // of called functions. Thus, we explicitly call *A versions of the functions.
    
    static BOOL MyIsDirectory(const std::string& path)
    {
    #if defined( __BORLANDC__ ) || defined( __MINGW64__ )
        return (GetFileAttributes(path.c_str()) & FILE_ATTRIBUTE_DIRECTORY);
    #else
    // See http://msdn.microsoft.com/en-us/library/bb773621(VS.85).aspx
        return PathIsDirectoryA(path.c_str());
    #endif
    }
    

    For Your information.
    Thank You all!
    Giangiacomo

     
  • Daniel Marjamäki

    I dont know.. but it seems to me we should try to get this into the repo. Just that we need to ensure it works with the non-cmake builds also.

    do you think you could create a pull request on github?

     

    Last edit: Daniel Marjamäki 2017-12-29
  • Giangiacomo Zaffini

    I just forked from GITHUB. First build test results are:
    1. source code compiles with Makefile under Lavavej's minGW
    2. source code compiles with Makefile under MSYS2(minGW-x64)
    3. source code compiles with cmake 3.10 Microsoft Visual Studio 2017 Community
    Still I have to compile with cmake and minGW, but I will soon report.
    I'm sorry that I have warned You for nothing, I have to say that I'm used to take source code from sourceforge, this is the first time that I take it from GitHub, could it be that streams are different?

    Giangiacomo

     
  • Mr. X

    Mr. X - 2017-12-30

    Forget about that CMake crap when using Visual Studio. There is a Visual Studio solution to build cppcheck inside the repository.

     
  • Giangiacomo Zaffini

    Another update:
    1. source code from GitHub compiles with Visual Studio 2017 Community edition when provided .sln solution file is used
    2. source code form GitHub compiles with Visual Studio 2017 Community edition when creating a solution with cmake 3.10
    3. source code release 1.81 from sourceforge compiles with Visual Studio 2017 Community edition when provided .sln solution file is used
    4. source code release 1.81 from sourceforge DOES NOT compile with Visual Studio 2017 Community edition when creating a solution with cmake 3.10

    for case 4. this is VS Output tab

    1>------ Inizio compilazione: Progetto: ZERO_CHECK, Configurazione: Release x64 ------
    1>Checking Build System
    1>CMake does not need to re-run because C:/Users/user/workspace/temp/cppcheck-1.81/b_VS2017/CMakeFiles/generate.stamp is up-to-date.
    1>CMake does not need to re-run because C:/Users/user/workspace/temp/cppcheck-1.81/b_VS2017/externals/tinyxml/CMakeFiles/generate.stamp is up-to-date.
    1>CMake does not need to re-run because C:/Users/user/workspace/temp/cppcheck-1.81/b_VS2017/externals/simplecpp/CMakeFiles/generate.stamp is up-to-date.
    1>CMake does not need to re-run because C:/Users/user/workspace/temp/cppcheck-1.81/b_VS2017/lib/CMakeFiles/generate.stamp is up-to-date.
    1>CMake does not need to re-run because C:/Users/user/workspace/temp/cppcheck-1.81/b_VS2017/cli/CMakeFiles/generate.stamp is up-to-date.
    1>CMake does not need to re-run because C:/Users/user/workspace/temp/cppcheck-1.81/b_VS2017/test/CMakeFiles/generate.stamp is up-to-date.
    1>CMake does not need to re-run because C:/Users/user/workspace/temp/cppcheck-1.81/b_VS2017/gui/CMakeFiles/generate.stamp is up-to-date.
    2>------ Inizio compilazione: Progetto: cli_objs, Configurazione: Release x64 ------
    3>------ Inizio compilazione: Progetto: lib_objs, Configurazione: Release x64 ------
    2>Building Custom Rule C:/Users/user/workspace/temp/cppcheck-1.81/cli/CMakeLists.txt
    2>CMake does not need to re-run because C:/Users/user/workspace/temp/cppcheck-1.81/b_VS2017/cli/CMakeFiles/generate.stamp is up-to-date.
    3>Building Custom Rule C:/Users/user/workspace/temp/cppcheck-1.81/lib/CMakeLists.txt
    3>CMake does not need to re-run because C:/Users/user/workspace/temp/cppcheck-1.81/b_VS2017/lib/CMakeFiles/generate.stamp is up-to-date.
    2>cmdlineparser.cpp
    2>cppcheckexecutor.cpp
    3>analyzerinfo.cpp
    3>astutils.cpp
    3>check.cpp
    2>C:\Users\user\workspace\temp\cppcheck-1.81\cli\cppcheckexecutor.cpp(950): warning C4267: 'inizializzazione': conversione da 'size_t' a 'unsigned int'. Possibile perdita di dati.
    2>C:\Users\user\workspace\temp\cppcheck-1.81\cli\cppcheckexecutor.cpp(950): warning C4267: 'inizializzazione': conversione da 'size_t' a 'const unsigned int'. Possibile perdita di dati.
    2>filelister.cpp
    2>threadexecutor.cpp
    3>check64bit.cpp
    3>checkassert.cpp
    3>checkautovariables.cpp
    2>Generazione del codice in corso...
    3>checkbool.cpp
    3>checkboost.cpp
    3>checkbufferoverrun.cpp
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\checkbufferoverrun.cpp(104): warning C4267: 'argomento': conversione da 'size_t' a 'int'. Possibile perdita di dati.
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\checkbufferoverrun.cpp(391): warning C4018: '>': errata corrispondenza tra signed e unsigned
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\checkbufferoverrun.cpp(395): warning C4018: '>=': errata corrispondenza tra signed e unsigned
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\checkbufferoverrun.cpp(401): warning C4018: '>=': errata corrispondenza tra signed e unsigned
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\checkbufferoverrun.cpp(727): warning C4018: '>=': errata corrispondenza tra signed e unsigned
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\checkbufferoverrun.cpp(1153): warning C4018: '>=': errata corrispondenza tra signed e unsigned
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\checkbufferoverrun.cpp(2012): warning C4244: '=': conversione da 'MathLib::bigint' a 'unsigned int'. Possibile perdita di dati.
    2>cli_objs.vcxproj -> C:\Users\user\workspace\temp\cppcheck-1.81\b_VS2017\cli\cli_objs.dir\Release\cli_objs.lib
    2>Compilazione progetto "cli_objs.vcxproj" completata.
    4>------ Inizio compilazione: Progetto: simplecpp_objs, Configurazione: Release x64 ------
    4>Building Custom Rule C:/Users/user/workspace/temp/cppcheck-1.81/externals/simplecpp/CMakeLists.txt
    4>CMake does not need to re-run because C:/Users/user/workspace/temp/cppcheck-1.81/b_VS2017/externals/simplecpp/CMakeFiles/generate.stamp is up-to-date.
    4>simplecpp.cpp
    3>checkclass.cpp
    4>C:\Users\user\workspace\temp\cppcheck-1.81\externals\simplecpp\simplecpp.cpp(132): warning C4267: '+=': conversione da 'size_t' a 'unsigned int'. Possibile perdita di dati.
    4>C:\Users\user\workspace\temp\cppcheck-1.81\externals\simplecpp\simplecpp.cpp(545): warning C4267: '+=': conversione da 'size_t' a 'unsigned int'. Possibile perdita di dati.
    4>C:\Users\user\workspace\temp\cppcheck-1.81\externals\simplecpp\simplecpp.cpp(547): warning C4267: '+=': conversione da 'size_t' a 'unsigned int'. Possibile perdita di dati.
    4>C:\Users\user\workspace\temp\cppcheck-1.81\externals\simplecpp\simplecpp.cpp(582): warning C4267: '+=': conversione da 'size_t' a 'unsigned int'. Possibile perdita di dati.
    4>C:\Users\user\workspace\temp\cppcheck-1.81\externals\simplecpp\simplecpp.cpp(1018): warning C4267: 'return': conversione da 'size_t' a 'unsigned int'. Possibile perdita di dati.
    3>checkcondition.cpp
    3>checkexceptionsafety.cpp
    4>simplecpp_objs.vcxproj -> C:\Users\user\workspace\temp\cppcheck-1.81\b_VS2017\externals\simplecpp\simplecpp_objs.dir\Release\simplecpp_objs.lib
    4>Compilazione progetto "simplecpp_objs.vcxproj" completata.
    5>------ Inizio compilazione: Progetto: tinyxml_objs, Configurazione: Release x64 ------
    5>Building Custom Rule C:/Users/user/workspace/temp/cppcheck-1.81/externals/tinyxml/CMakeLists.txt
    5>CMake does not need to re-run because C:/Users/user/workspace/temp/cppcheck-1.81/b_VS2017/externals/tinyxml/CMakeFiles/generate.stamp is up-to-date.
    3>checkfunctions.cpp
    5>tinyxml2.cpp
    5>tinyxml_objs.vcxproj -> C:\Users\user\workspace\temp\cppcheck-1.81\b_VS2017\externals\tinyxml\tinyxml_objs.dir\Release\tinyxml_objs.lib
    3>checkinternal.cpp
    3>checkio.cpp
    3>checkleakautovar.cpp
    3>checkmemoryleak.cpp
    3>checknullpointer.cpp
    3>checkother.cpp
    3>checkpostfixoperator.cpp
    3>Generazione del codice in corso...
    3>Compilazione in corso...
    3>checksizeof.cpp
    3>checkstl.cpp
    3>checkstring.cpp
    3>checktype.cpp
    3>checkuninitvar.cpp
    3>checkunusedfunctions.cpp
    3>checkunusedvar.cpp
    3>checkvaarg.cpp
    3>cppcheck.cpp
    3>errorlogger.cpp
    3>importproject.cpp
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\importproject.cpp(115): warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    3>C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\ucrt\stdlib.h(1199): note: vedere la dichiarazione di 'getenv'
    3>library.cpp
    3>mathlib.cpp
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\mathlib.cpp(122): warning C4244: '=': conversione da '__int64' a 'double'. Possibile perdita di dati.
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\mathlib.cpp(548): warning C4244: 'return': conversione da 'MathLib::bigint' a 'double'. Possibile perdita di dati.
    3>path.cpp
    3>pathmatch.cpp
    3>platform.cpp
    3>preprocessor.cpp
    3>settings.cpp
    3>suppressions.cpp
    3>symboldatabase.cpp
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\symboldatabase.cpp(4645): warning C4267: '=': conversione da 'size_t' a 'unsigned int'. Possibile perdita di dati.
    3>Generazione del codice in corso...
    3>Compilazione in corso...
    3>templatesimplifier.cpp
    3>timer.cpp
    3>token.cpp
    3>tokenize.cpp
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\tokenize.cpp(182): warning C4267: 'return': conversione da 'size_t' a 'unsigned int'. Possibile perdita di dati.
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\tokenize.cpp(7051): warning C4018: '<=': errata corrispondenza tra signed e unsigned
    3>tokenlist.cpp
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\tokenlist.cpp(95): warning C4267: 'return': conversione da 'size_t' a 'unsigned int'. Possibile perdita di dati.
    3>valueflow.cpp
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\valueflow.cpp(268): warning C4244: '=': conversione da 'double' a '__int64'. Possibile perdita di dati.
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\valueflow.cpp(402): warning C4244: 'inizializzazione': conversione da 'double' a 'float'. Possibile perdita di dati.
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\valueflow.cpp(402): warning C4244: 'inizializzazione': conversione da 'double' a 'const float'. Possibile perdita di dati.
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\valueflow.cpp(403): warning C4244: 'inizializzazione': conversione da 'double' a 'float'. Possibile perdita di dati.
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\valueflow.cpp(403): warning C4244: 'inizializzazione': conversione da 'double' a 'const float'. Possibile perdita di dati.
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\valueflow.cpp(618): warning C4018: '<': errata corrispondenza tra signed e unsigned
    3>C:\Users\user\workspace\temp\cppcheck-1.81\lib\valueflow.cpp(2570): warning C4018: '<': errata corrispondenza tra signed e unsigned
    3>Generazione del codice in corso...
    3>lib_objs.vcxproj -> C:\Users\user\workspace\temp\cppcheck-1.81\b_VS2017\lib\lib_objs.dir\Release\lib_objs.lib
    3>Compilazione progetto "lib_objs.vcxproj" completata.
    6>------ Inizio compilazione: Progetto: cppcheck, Configurazione: Release x64 ------
    6>Building Custom Rule C:/Users/user/workspace/temp/cppcheck-1.81/cli/CMakeLists.txt
    6>CMake does not need to re-run because C:/Users/user/workspace/temp/cppcheck-1.81/b_VS2017/cli/CMakeFiles/generate.stamp is up-to-date.
    6>main.cpp
    6>filelister.obj : error LNK2019: riferimento al simbolo esterno __imp_PathFileExistsA non risolto nella funzione "public: static bool __cdecl FileLister::fileExists(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?fileExists@FileLister@@SA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
    6>filelister.obj : error LNK2019: riferimento al simbolo esterno __imp_PathIsDirectoryA non risolto nella funzione "public: static bool __cdecl FileLister::isDirectory(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?isDirectory@FileLister@@SA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
    6>C:\Users\user\workspace\temp\cppcheck-1.81\b_VS2017\bin\Release\cppcheck.exe : fatal error LNK1120: 2 esterni non risolti
    6>Compilazione progetto "cppcheck.vcxproj" NON COMPLETATA.
    7>------ Inizio compilazione: Progetto: ALL_BUILD, Configurazione: Release x64 ------
    7>Building Custom Rule C:/Users/user/workspace/temp/cppcheck-1.81/CMakeLists.txt
    7>CMake does not need to re-run because C:/Users/user/workspace/temp/cppcheck-1.81/b_VS2017/CMakeFiles/generate.stamp is up-to-date.
    ========== Compilazione: 6 completate, 1 non riuscite, 0 aggiornate, 0 ignorate ==========
    

    Now back to minGW+MSYS2

    Ciao,
    Giangiacomo

     
  • Giangiacomo Zaffini

    maybe it is all about IgnoreSpecificDefaultLibraries which changes how cppcheck is linked when cmake generates projects files, it seems to me that IgnoreSpecificDefaultLibraries is not used in released project files.

    Giangiacomo

     
  • Giangiacomo Zaffini

    update:
    I recompiled both released 1.81 and GitHub trunk with cmake under MSYS2(minGW-x64) and both have the problem I signaled in the beginning, that is .\cli\filelister.cpp module's MyDirectory function uses PathIsDirectoryA Windows API function, but it's unresolved reference at linking, if it were to use GetFileAttributes function it would compile right.

    Giangiacomo

     
  • Fabian Schmill

    Fabian Schmill - 2018-01-14

    The Solution thats worked for me. Change in cli/CMakeList.txt:

    from:

    if (HAVE_RULES)
        target_link_libraries(cppcheck pcre)
    endif()
    

    to:

    if (HAVE_RULES)
        target_link_libraries(cppcheck pcre Shlwapi)
    else(HAVE_RULES)
        target_link_libraries(cppcheck Shlwapi)
    endif()
    
     
  • Daniel Marjamäki

    please create a pull request on github.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.