GTest mit CLion



  • Hey!

    Ich habe gerade versucht mittels CLion GoogleTest zu bauen... allerdings zeigt der mir ordentlich Compiler Errors an:

    Das CMake File sieht so aus:

    cmake_minimum_required(VERSION 3.10)
    
    project(LynarMathProject)
    
    
    
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    
    set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
    
    
    
    add_subdirectory(lib/googletest-1.8.0)
    
    
    
    include_directories(lib/googletest-1.8.0/googletest/include)
    
    include_directories(lib/googletest-1.8.0/googlemock/include)
    
    
    
    add_executable(LynarMathProject main.cpp LynarMath/LynarMath.h LynarMath/LynarMath.cpp LynarMathTest/basicTests.cpp)
    
    
    
    target_link_libraries(LynarMathProject gtest gtest_main)
    

    Und die Fehlerausgabe so:

    "C:\Program Files\JetBrains\CLion 2018.1.6\bin\cmake\bin\cmake.exe" --build C:\Users\Admin\CLionProjects\LynarMathProject\cmake-build-debug --target LynarMathProject -- -j 4
    
    [ 12%] Building CXX object lib/googletest-1.8.0/googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj
    
    In file included from C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/include/gtest/internal/gtest-internal.h:40:0,
    
                     from C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/include/gtest/gtest.h:58,
    
                     from C:\Users\Admin\CLionProjects\LynarMathProject\lib\googletest-1.8.0\googletest\src\gtest-all.cc:39:
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::StrCaseCmp(const char*, const char*)':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/include/gtest/internal/gtest-port.h:2318:25: error: '_stricmp' was not declared in this scope
    
       return _stricmp(s1, s2);
    
                             ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/include/gtest/internal/gtest-port.h: In function 'char* testing::internal::posix::StrDup(const char*)':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/include/gtest/internal/gtest-port.h:2320:58: error: '_strdup' was not declared in this scope
    
     inline char* StrDup(const char* src) { return _strdup(src); }
    
                                                              ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::FileNo(FILE*)':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/include/gtest/internal/gtest-port.h:2328:52: error: '_fileno' was not declared in this scope
    
     inline int FileNo(FILE* file) { return _fileno(file); }
    
                                                        ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/include/gtest/internal/gtest-port.h: In function 'FILE* testing::internal::posix::FDOpen(int, const char*)':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/include/gtest/internal/gtest-port.h:2374:71: error: 'fdopen' was not declared in this scope
    
     inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
    
                                                                           ^
    
    In file included from C:\Users\Admin\CLionProjects\LynarMathProject\lib\googletest-1.8.0\googletest\src\gtest-all.cc:42:0:
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest.cc: In static member function 'static bool testing::internal::String::CaseInsensitiveWideCStringEquals(const wchar_t*, const wchar_t*)':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest.cc:1932:27: error: '_wcsicmp' was not declared in this scope
    
       return _wcsicmp(lhs, rhs) == 0;
    
                               ^
    
    In file included from C:\Users\Admin\CLionProjects\LynarMathProject\lib\googletest-1.8.0\googletest\src\gtest-all.cc:43:0:
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-death-test.cc: In function 'void testing::internal::DeathTestAbort(const string&)':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-death-test.cc:273:12: error: '_exit' was not declared in this scope
    
         _exit(1);
    
                ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-death-test.cc: In member function 'virtual void testing::internal::DeathTestImpl::Abort(testing::internal::DeathTest::AbortReason)':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-death-test.cc:498:10: error: '_exit' was not declared in this scope
    
       _exit(1);  // Exits w/o any normal exit hooks (we were supposed to crash)
    
              ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-death-test.cc: In member function 'virtual testing::internal::DeathTest::TestRole testing::internal::WindowsDeathTest::AssumeRole()':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-death-test.cc:741:24: error: '_MAX_PATH' was not declared in this scope
    
       char executable_path[_MAX_PATH + 1];  // NOLINT
    
                            ^~~~~~~~~
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-death-test.cc:744:45: error: 'executable_path' was not declared in this scope
    
                                                 executable_path,
    
                                                 ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-death-test.cc:285:38: note: in definition of macro 'GTEST_DEATH_TEST_CHECK_'
    
         if (!::testing::internal::IsTrue(expression)) { \
    
                                          ^~~~~~~~~~
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-death-test.cc:767:7: error: 'executable_path' was not declared in this scope
    
           executable_path,
    
           ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-death-test.cc:285:38: note: in definition of macro 'GTEST_DEATH_TEST_CHECK_'
    
         if (!::testing::internal::IsTrue(expression)) { \
    
                                          ^~~~~~~~~~
    
    In file included from C:\Users\Admin\CLionProjects\LynarMathProject\lib\googletest-1.8.0\googletest\src\gtest-all.cc:44:0:
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-filepath.cc: In static member function 'static testing::internal::FilePath testing::internal::FilePath::GetCurrentDir()':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-filepath.cc:52:26: error: '_MAX_PATH' was not declared in this scope
    
     # define GTEST_PATH_MAX_ _MAX_PATH
    
                              ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-filepath.cc:105:12: note: in expansion of macro 'GTEST_PATH_MAX_'
    
       char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
    
                ^~~~~~~~~~~~~~~
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-filepath.cc:106:27: error: 'cwd' was not declared in this scope
    
       return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
    
                               ^~~
    
    In file included from C:\Users\Admin\CLionProjects\LynarMathProject\lib\googletest-1.8.0\googletest\src\gtest-all.cc:45:0:
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc: In constructor 'testing::internal::Mutex::Mutex()':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:242:45: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in initialization
    
           critical_section_(new CRITICAL_SECTION) {
    
                                                 ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:243:48: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
    
       ::InitializeCriticalSection(critical_section_);
    
                                                    ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc: In destructor 'testing::internal::Mutex::~Mutex()':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:253:46: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'PCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void DeleteCriticalSection(PCRITICAL_SECTION)'
    
         ::DeleteCriticalSection(critical_section_);
    
                                                  ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc: In member function 'void testing::internal::Mutex::Lock()':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:261:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void EnterCriticalSection(LPCRITICAL_SECTION)'
    
       ::EnterCriticalSection(critical_section_);
    
                                               ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc: In member function 'void testing::internal::Mutex::Unlock()':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:271:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void LeaveCriticalSection(LPCRITICAL_SECTION)'
    
       ::LeaveCriticalSection(critical_section_);
    
                                               ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc: In member function 'void testing::internal::Mutex::ThreadSafeLazyInit()':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:292:33: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in assignment
    
             critical_section_ = new CRITICAL_SECTION;
    
                                     ^~~~~~~~~~~~~~~~
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:293:54: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
    
             ::InitializeCriticalSection(critical_section_);
    
                                                          ^
    
    lib\googletest-1.8.0\googlemock\gtest\CMakeFiles\gtest.dir\build.make:62: recipe for target 'lib/googletest-1.8.0/googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj' failed
    
    mingw32-make.exe[3]: *** [lib/googletest-1.8.0/googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj] Error 1
    
    CMakeFiles\Makefile2:238: recipe for target 'lib/googletest-1.8.0/googlemock/gtest/CMakeFiles/gtest.dir/all' failed
    
    mingw32-make.exe[2]: *** [lib/googletest-1.8.0/googlemock/gtest/CMakeFiles/gtest.dir/all] Error 2
    
    mingw32-make.exe[1]: *** [CMakeFiles/LynarMathProject.dir/rule] Error 2
    
    CMakeFiles\Makefile2:79: recipe for target 'CMakeFiles/LynarMathProject.dir/rule' failed
    
    mingw32-make.exe: *** [LynarMathProject] Error 2
    
    Makefile:163: recipe for target 'LynarMathProject' failed
    

    Das sieht stark danach aus, als wäre GoogleTest selbst verbuggt? Ich habe das aus dem gitHub Repository gedownloaded! Irgendwelche Ideen? Ich bin für jede Hilfe dankbar!



  • @padmad sagte in GTest mit CLion:

    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    

    CLion 2018.2 Help - Google Test Support hast Du Dir angesehen?



  • Hey,

    Danke für deine Antwort! Ja, habe ich!
    Ich hätte vielleicht erwähnen sollen, dass ich MinGW benutze. Den Compiler Flag müsste ich so ändern, wenn ich Cygwin benutzen würde, wenn ich das richtig verstanden habe.

    Ich habe es dennoch mal spaßighalber gemacht und erhalte dann diesen Error Log

    "C:\Program Files\JetBrains\CLion 2018.1.6\bin\cmake\bin\cmake.exe" --build C:\Users\Admin\CLionProjects\LynarMathProject\cmake-build-debug --target LynarMathProject -- -j 4
    
    [ 12%] Building CXX object lib/googletest-1.8.0/googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj
    
    In file included from C:\Users\Admin\CLionProjects\LynarMathProject\lib\googletest-1.8.0\googletest\src\gtest-all.cc:45:0:
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc: In constructor 'testing::internal::Mutex::Mutex()':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:242:45: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in initialization
    
           critical_section_(new CRITICAL_SECTION) {
    
                                                 ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:243:48: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
    
       ::InitializeCriticalSection(critical_section_);
    
                                                    ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc: In destructor 'testing::internal::Mutex::~Mutex()':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:253:46: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'PCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void DeleteCriticalSection(PCRITICAL_SECTION)'
    
         ::DeleteCriticalSection(critical_section_);
    
                                                  ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc: In member function 'void testing::internal::Mutex::Lock()':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:261:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void EnterCriticalSection(LPCRITICAL_SECTION)'
    
       ::EnterCriticalSection(critical_section_);
    
                                               ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc: In member function 'void testing::internal::Mutex::Unlock()':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:271:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void LeaveCriticalSection(LPCRITICAL_SECTION)'
    
       ::LeaveCriticalSection(critical_section_);
    
                                               ^
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc: In member function 'void testing::internal::Mutex::ThreadSafeLazyInit()':
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:292:33: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in assignment
    
             critical_section_ = new CRITICAL_SECTION;
    
                                     ^~~~~~~~~~~~~~~~
    
    C:/Users/Admin/CLionProjects/LynarMathProject/lib/googletest-1.8.0/googletest/src/gtest-port.cc:293:54: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
    
             ::InitializeCriticalSection(critical_section_);
    
                                                          ^
    
    mingw32-make.exe[3]: *** [lib/googletest-1.8.0/googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj] Error 1
    
    lib\googletest-1.8.0\googlemock\gtest\CMakeFiles\gtest.dir\build.make:62: recipe for target 'lib/googletest-1.8.0/googlemock/gtest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj' failed
    
    mingw32-make.exe[2]: *** [lib/googletest-1.8.0/googlemock/gtest/CMakeFiles/gtest.dir/all] Error 2
    
    CMakeFiles\Makefile2:238: recipe for target 'lib/googletest-1.8.0/googlemock/gtest/CMakeFiles/gtest.dir/all' failed
    
    mingw32-make.exe[1]: *** [CMakeFiles/LynarMathProject.dir/rule] Error 2
    
    CMakeFiles\Makefile2:79: recipe for target 'CMakeFiles/LynarMathProject.dir/rule' failed
    
    mingw32-make.exe: *** [LynarMathProject] Error 2
    
    Makefile:163: recipe for target 'LynarMathProject' failed
    

    Ich folge auch diesem Youtube Tutorial hier:

    Setting Up GoogleTest

    Der Herr im Video kriegt auch keinen Compiler Error...



  • @padmad sagte in GTest mit CLion:

    cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}'
    

    Compilation errors with MinGW 5.3 + MSYS erzählt von ziemlich den selben Fehlern von Google Test v1.8.0 mit MinGW.
    Next release? erzählt vom Warten auf v1.8.1.
    Fix compilation of googletest with MinGW using Win32 threads #721 schaut gut aus. Kannst Du das master-Repository holen und das bauen?



  • Hey!

    Vielen Dank für die Recherche!
    Ich habe das versucht zu bauen. Leider hat es nicht geklappt. Ich bin mitunter aber auch vielleicht zu schlecht in solch Dingen.

    Ich habe MinGW jetzt einfach durch Cygwin ersetzt. Jetzt funktioniert alles wie es soll und CLion ist nun meine neue IDE!
    Danke dennoch!



  • Das freut mich! 👍


Anmelden zum Antworten