Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

CLion na Windows + GoogleTest - problem z kompilacją biblioteki, który czasami się pojawia

Ostatnio zmodyfikowano 2022-03-25 12:31
Autor Wiadomość
baziorek
Temat założony przez niniejszego użytkownika
CLion na Windows + GoogleTest - problem z kompilacją biblioteki, który czasami się pojawia
» 2022-03-24 14:46:10
Prowadząc zajęcia na uczelni bardzo rzadko, ale niestety co jakiś czas pojawia się problem z importem paczki, która zawiera CMake i Google-testy na Windowsie:
https://www.gg.pl/dysk/3juSCwolAp1r3zuSCwolg5I/zaj1Fraction_dlaStudentow.zip. Problem ten dotyczy właśnie problemów z kompilacją biblioteki GTest (bo paczka sama w sobie też się nie będzie kompilować, bo tam trzeba zrobić implementacje), który dotyczy rzeczy pod Linuxa, mimo iż kompilujemy na Windowsie.
Największy problem w tym jest taki, że u większości studentów tego problemu nie ma, a około 1/10 ma właśnie ten problem.

Niestety nie posiadam w ogóle Windowsa na komputerze, dlatego nie mam tego problemu. Kolejnym problemem jest to, że osoby, którym działa nie pamiętają jak to skonfigurowali, a osoby, którym nie działa nie pamiętają jak sobie zainstalowali kompilator:D.

Oto komunikaty błędów kompilatora (jak widać ewidentnie dotyczą biblioteki GTest)

====================[ Build | SimpleString_dlaStudentow | Debug ]===============
"C:\Program Files\JetBrains\CLion 2021.2.2\bin\cmake\win\bin\cmake.exe" --build C:\Users\Admin\Desktop\motylek\zaj4SimpleString_dlaStudentow\cmake-build-debug --target SimpleString_dlaStudentow -- -j 6
[ 14%] Building CXX object lib/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj
In file included from C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/include/gtest/internal/gtest-internal.h:40:0,
                 from C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/include/gtest/gtest.h:62,
                 from C:\Users\Admin\Desktop\motylek\zaj4SimpleString_dlaStudentow\lib\googletest\src\gtest-all.cc:38:
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::StrCaseCmp(const char*, const char*)':
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/include/gtest/internal/gtest-port.h:2002:25: error: '_stricmp' was not declared in this scope
   return _stricmp(s1, s2);
                         ^
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/include/gtest/internal/gtest-port.h: In function 'char* testing::internal::posix::StrDup(const char*)':
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/include/gtest/internal/gtest-port.h:2004:58: error: '_strdup' was not declared in this scope
 inline char* StrDup(const char* src) { return _strdup(src); }
                                                          ^
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/include/gtest/internal/gtest-port.h: In function 'int testing::internal::posix::FileNo(FILE*)':
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/include/gtest/internal/gtest-port.h:2012:52: error: '_fileno' was not declared in this scope
 inline int FileNo(FILE* file) { return _fileno(file); }
                                                    ^
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/include/gtest/internal/gtest-port.h: In function 'FILE* testing::internal::posix::FDOpen(int, const char*)':
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/include/gtest/internal/gtest-port.h:2090: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\Desktop\motylek\zaj4SimpleString_dlaStudentow\lib\googletest\src\gtest-all.cc:41:0:
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest.cc: In static member function 'static bool testing::internal::String::CaseInsensitiveWideCStringEquals(const wchar_t*, const wchar_t*)':
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest.cc:2104:27: error: '_wcsicmp' was not declared in this scope
   return _wcsicmp(lhs, rhs) == 0;
                           ^
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest.cc: In member function 'int testing::UnitTest::Run()':
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest.cc:5411:21: error: '_OUT_TO_STDERR' was not declared in this scope
     _set_error_mode(_OUT_TO_STDERR);
                     ^~~~~~~~~~~~~~
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest.cc:5411:35: error: '_set_error_mode' was not declared in this scope
     _set_error_mode(_OUT_TO_STDERR);
                                   ^
In file included from C:\Users\Admin\Desktop\motylek\zaj4SimpleString_dlaStudentow\lib\googletest\src\gtest-all.cc:42:0:
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-death-test.cc: In function 'void testing::internal::DeathTestAbort(const string&)':
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-death-test.cc:297:12: error: '_exit' was not declared in this scope
     _exit(1);
            ^
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-death-test.cc: In member function 'virtual void testing::internal::DeathTestImpl::Abort(testing::internal::DeathTest::AbortReason)':
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-death-test.cc:528: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/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-death-test.cc: In member function 'virtual testing::internal::DeathTest::TestRole testing::internal::WindowsDeathTest::AssumeRole()':
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-death-test.cc:772:24: error: '_MAX_PATH' was not declared in this scope
   char executable_path[_MAX_PATH + 1];  // NOLINT
                        ^~~~~~~~~
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-death-test.cc:774:65: error: 'executable_path' was not declared in this scope
                                                                 executable_path,
                                                                 ^
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-death-test.cc:309:38: note: in definition of macro 'GTEST_DEATH_TEST_CHECK_'
     if (!::testing::internal::IsTrue(expression)) { \
                                      ^~~~~~~~~~
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-death-test.cc:798:11: error: 'executable_path' was not declared in this scope
           executable_path, const_cast<char*>(command_line.c_str()),
           ^
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-death-test.cc:309:38: note: in definition of macro 'GTEST_DEATH_TEST_CHECK_'
     if (!::testing::internal::IsTrue(expression)) { \
                                      ^~~~~~~~~~
In file included from C:\Users\Admin\Desktop\motylek\zaj4SimpleString_dlaStudentow\lib\googletest\src\gtest-all.cc:43:0:
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-filepath.cc: In static member function 'static testing::internal::FilePath testing::internal::FilePath::GetCurrentDir()':
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-filepath.cc:49:26: error: '_MAX_PATH' was not declared in this scope
 # define GTEST_PATH_MAX_ _MAX_PATH
                          ^
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-filepath.cc:102:12: note: in expansion of macro 'GTEST_PATH_MAX_'
   char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
            ^~~~~~~~~~~~~~~
C:/Users/Admin/Desktop/motylek/zaj4SimpleString_dlaStudentow/lib/googletest/src/gtest-filepath.cc:103:27: error: 'cwd' was not declared in this scope
   return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd);
                           ^~~
lib\googletest\CMakeFiles\gtest.dir\build.make:71: recipe for target 'lib/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj' failed
CMakeFiles\Makefile2:268: recipe for target 'lib/googletest/CMakeFiles/gtest.dir/all' failed
CMakeFiles\Makefile2:144: recipe for target 'CMakeFiles/SimpleString_dlaStudentow.dir/rule' failed
Makefile:168: recipe for target 'SimpleString_dlaStudentow' failed
mingw32-make.exe[3]: *** [lib/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj] Error 1
mingw32-make.exe[2]: *** [lib/googletest/CMakeFiles/gtest.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/SimpleString_dlaStudentow.dir/rule] Error 2
mingw32-make.exe: *** [SimpleString_dlaStudentow] Error 2


Oczywiście nawet jak ktoś nie natrafi na taki problem, nie zna rozwiązania, może by podrzucił Golden Path, którego o dziwo nie znalazłem dla konfiguracji: CLion, Windows, CMake, Google-test, MinGW.

Na razie sobie radzę z tym mówiąc: "Zainstaluj Visual Studio Community + plugin do CMake'a", no ale jednak chciałbym poznać lepsze rozwiązanie.
P-179346
DejaVu
» 2022-03-24 16:14:52
Czy to nie jest przypadkiem ten problem?
https://github.com/google/googletest/issues/813

Podobny problem w kontekście boosta:
https://github.com/boostorg/type_erasure/issues/16
Installed the 1_70 version of boost + installed mingw_64 instead of unmaintained mingw, now compiles smoothly.

Thanks! it works for me to change the version.
P-179347
baziorek
Temat założony przez niniejszego użytkownika
» 2022-03-24 23:16:17
Czy to nie jest przypadkiem ten problem?
https://github.com/google/googletest/issues/813
Bardzo dziękuję, wygląda na to, że to jest to. Teraz pozostaje pytanie gdzie to zmienić w paczce, a o to muszę pomęczyć studentów z tym problemem aby poeksperymentowali.

Z tego co widzę wszystko się sprowadza do tego, że zamiast flagi
--std=c++**
 powinna być:
--std=gnu++**
, a to się chyba osiągnie zmieniając plik CMakeLists.txt, a dokładniej ten fragment (wg tego):
set(CMAKE_CXX_EXTENSIONS OFF)
 na
ON


Jak to pomoże to zamykam wtedy temat:).
P-179348
baziorek
Temat założony przez niniejszego użytkownika
» 2022-03-25 11:00:51
Udało się rozwiązać problem przez usunięcie linijek:
set(CMAKE_CXX_STANDARD 17)
    set(COMPILER_FLAGS "--std=c++17")
    set(LINKER_FLAGS "--std=c++17")

Z głównego CMake'a paczki.

W końcu się udało rozwiązać ten problem!
P-179349
DejaVu
» 2022-03-25 12:31:19
No to good job :) Zamykam
P-179350
« 1 »
  Strona 1 z 1