How can I fix CLion problem with filesystem inlcude? - c++

I use a CLion as my IDE. I create project with C++17 standard.
I have a code fragment below:
#include <filesystem>
namespace fs = std::filesystem;
std::vector<std::string> getFilesArray() {
auto dir = ".";
std::vector<std::string> filesList;
for (auto item : fs::recursive_directory_iterator(dir))
{
if (!fs::is_regular_file(item.path()) || item.path().extension() != ".cpp" && item.path().extension() != ".h" && item.path().extension() != ".hpp")
continue;
filesList.push_back(item.path().string());
}
return filesList;
}
When I try to compile project I have a lot of errors like:
C:/PROGRA~2/MINGW-~1/I686-8~1.0-P/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: In member function 'std::filesystem::__cxx11::path& std::filesystem::__cxx11::path::operator/=(const std::filesystem::__cxx11::path&)':
C:/PROGRA~2/MINGW-~1/I686-8~1.0-P/mingw32/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:47: error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')
|| (__p.has_root_name() && __p.root_name() != root_name()))
My Cmake file is:
cmake_minimum_required(VERSION 3.15)
project(FinalParser)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "-std=c++17 -lc++fs")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(FinalParser main.cpp Parse/Parser.cpp Parse/Parser.cpp Parse/Parser.h files.h Graph/Parser.cpp Graph/Parser.h)
target_link_libraries(FinalParser stdc++fs)
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/Users/user/Desktop/boost_1_71_0")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/Users/user/Desktop/boost_1_71_0/libs")
FIND_PACKAGE(Boost)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()
How can I fix it?

So, I am going to give you the full proof solution for this similar error which also comes when someone tries to use the STL header file which is #include<bits/stdc++.h>
So, this error is occurring because you are currently using the GCC version 8.2.0 which is the default on the MinGW website. To solve this problem you need to update to GCC 10.2.0
Following are the steps you need to follow:-
Download and install the Msys2 from https://www.msys2.org/
Run or launch this and type pacman -Syu and hit enter then it will ask you to continue by typing Y/N just type enter without pressing Y/n.
Close this and again launch msys2 and again type the same command until it shows nothing to do with or nothing to update.
For doing the same I am also sharing a link of the youtube video.
https://www.youtube.com/watch?v=aXF4A5UeSeM&
5. For checking that you have successfully installed GCC 10.2.0 just open cmd and type GCC --version and hit enter if it is showing 10.2.0 hurray u did it, wait this is not the end.
6. Now uninstall Clion or any IDE which you are using.
7. Before reinstalling it you need to delete some of the remaining Jetbrains dump files which are showing in your program files folder (name Jetbrains) Delete that folder and Reinstall it.
8. Now select Msys2/MingW-64, not the previous one which you have in your system already (normal MinGW) while installing it.
9. Now You can go to your add or remove program section and can delete that waste normal MinGW-64, not the msys2 (don't delete msys2) only delete ming64 the previous one.
10. Now you can enjoy running that sexy stl library without having any error.
Still, if you have any problem doing these steps just ask me in a comment.

Related

Test framework quit unexpectedly: cat: /tmp/tmp.z5uNpMUXj6: No such file or directory

I've got a problem using CLion 2020.1.2. I submitted a question to the help forum a few days ago but not getting a response, so I'm reposting the question here.
Basically the issue is that my test program runs fine outside of debugger mode - I'm using googletest - but as soon as I set a breakpoint and try to run the debugger the test framework quit unexpectedly with the following message:
Testing started at 12:50 ...
D:\libOmexMeta\cmake-build-release-wsl-ubuntu1804-gcc101\bin\OmexMetaTests --gtest_color=no
cat: /tmp/tmp.zA2hjQPSYh: No such file or directory
cat: /tmp/tmp.65NNrNx20t: No such file or directory
Process finished with exit code 0
I'm basically stumped with this one so I've been developing without a debugger, which is less than ideal. I thought it might have something to do with Release Vs Debug flags so I tried again with :
set(CMAKE_CXX_FLAGS "-O0")
set(CMAKE_C_FLAGS "-O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O0")
set(CMAKE_C_FLAGS_RELEASE "-O0")
set(CMAKE_CXX_FLAGS_DEBUG "-O0")
set(CMAKE_C_FLAGS_DEBUG "-O0")
in my cmake script - which does nothing, it seems. Any idea what is going on here?
I also tried using msvc compilers and the debugger just skips over break points.
I forgot to mention that I'm using Ubuntu 18.04 from WSL.

Error with cmake conan and liblogicalaccess

I have installed the 2.2.1 version of the liblogicalaccess library on Kubuntu 18.04 with CMake 3.17.1 and Conan 1.25.0.
I tried to follow the C++ howto of the liblogicalaccess library and on the second line of code, when running the program it gives the following error:
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_M_construct null not valid
./run.sh: line 9: 6781 Aborted (core dumped) bin/./github_console
main.cpp
// my first program in C++
#include <iostream>
#include <logicalaccess/dynlibrary/librarymanager.hpp>
#include <logicalaccess/readerproviders/readerconfiguration.hpp>
#include <logicalaccess/cards/chip.hpp>
int main()
{
std::cout << "Hello World!\n";
// Reader configuration object to store reader provider and reader unit selection.
std::shared_ptr<logicalaccess::ReaderConfiguration> readerConfig(new logicalaccess::ReaderConfiguration());
// Set PCSC ReaderProvider by calling the Library Manager which will load the function from the corresponding plug-in
readerConfig->setReaderProvider(logicalaccess::LibraryManager::getInstance()->getReaderProvider("PCSC"));
}
The first line of code starting with std::shared_ptr.. just runs fine, so might this be faulty code within the library or could this be a version/compatility fault. The second line calling the getReaderProvider somehow causes the error. I have no idea where to look for the fix of this error. Came from this problem originally. That was fixed but still stuck at the same code. I did some random troubelshooting but no luck. Any advice?
EDIT:
My CmakeLists.txt is:
project(test)
cmake_minimum_required(VERSION 3.16)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
set(CMAKE_CXX_FLAGS "-I /usr/include/PCSC")
add_executable(test main.cpp)
target_link_libraries(test PUBLIC CONAN_PKG::LogicalAccess)
conanfile.txt:
[requires]
LogicalAccess/2.2.1
[generators]
cmake
[imports]
lib, * -> lib
And to build i just run cmake --build . in the project_folder/build.

Cygwin libzint(zint) goes into infinite loop

Cygwin Zint(libzint) stucks on ZBarcode_Create() function call with basic example code which perfectly works on Linux system:
#include <zint.h>
int main()
{
struct zint_symbol *my_symbol;my_symbol = ZBarcode_Create();
if(my_symbol != NULL)
{
printf("Symbol successfully created!\n");
}
ZBarcode_Delete(my_symbol);
return 0;
}
Steps to reproduce:
Downloaded and installed Cygwin, zlib, libpng and libzint(zint) packages
In Visual Studio created a new project, added Include Path, added libzint.a library name, added library path in Linker options
Added Cygwin path to PATH variable
Tried to build libzint by myself result is the same
Can someone help me to find out is it common behavior for libs that were created with Cygwin or is it only Zint(libzint)?
The code is working fine. After installing the needed libraries with cygwin setup and
checking their presence
$ cygcheck -cd |grep zint
libzint-devel 2.4.3-3
libzint2.4 2.4.3-3
zint 2.4.3-3
the compilation is without any problem and the testing also
$ gcc -o prova prova.c -Wall -lzint
$ ./prova.exe
Symbol successfully created!

Pretty printing in Eclipse C++ works for some projects and doesn't for others

I have enabled pretty printing for Eclipse-CDT. This is my previous question: Enable pretty printing in Eclipse C++
I have done all the steps as mentioned in my previous question. I realized that pretty printing does work for a simple test program but doesn't work on my projects. Hence, I am opening a new question as this seems to be project-specific settings.
This is my setup:
Eclipse Version: 2018-09 (4.9.0)
gdb 7.11.1
Xubuntu 16.04
gcc 7.4.0
g++ 7.4.0
I have a simple test.cpp
#include <map>
#include<vector>
int main() {
std::map<char, int> first;
first['a'] = 10;
first['b'] = 20;
std::vector<int> a{1,2,3,4,5};
}
I import this into Eclipse using New > Makefile Project with Existing Code, compile it in terminal:
g++ -g -o test test.cpp
I then debug this program in Eclipse and got this:
Name : first
Details:std::map with 1 element = {[97 'a'] = 10}
Default:{...}
Decimal:{...}
Hex:{...}
Binary:{...}
Octal:{...}
So pretty printing works in Eclipse-CDT for this simple test case. I am assuming whatever settings in Eclipse > Windows > Preferences are set up fine.
For my other two projects (one of which is using https://github.com/Svalorzen/AI-Toolbox), I paste the code snippet in test.cpp into the main.cpp, compile it using make with project-specific CMakeLists in Eclipse, debug it and got this:
For one of the projects:
Name : first
Details:{_M_t = {_M_impl = {<No data fields>}}}
Default:{...}
Decimal:{...}
Hex:{...}
Binary:{...}
Octal:{...}
For the other project:
Multiple errors reported.
1) Failed to execute MI command:
-var-create - * first
Error message from debugger back end:
Null value returned for children
2) Unable to create variable object
3) Failed to execute MI command:
-var-create - * first
Error message from debugger back end:
Null value returned for children
I have checked the Debug Configuration > Debugger for all 3 cases and the settings are the same. Does anyone have any idea why am I getting these errors?
I am guessing that I might need to modify the CMakeLists but I do not have sufficient knowledge to figure this out. This is the snippet of my CMakeLists for both projects:
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
The full CMakeLists is here https://github.com/Svalorzen/AI-Toolbox/blob/master/CMakeLists.txt
So after fiddling with CMakeLists, I figured out the offending line that disables pretty printing:
set_target_properties(lib PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${LTO_SUPPORTED})
Removing this line will make pretty printing work. I changed it to this instead and build in debug mode.
IF(CMAKE_BUILD_TYPE MATCHES Release)
set_target_properties(lib PROPERTIES INTERPROCEDURAL_OPTIMIZATION ${LTO_SUPPORTED})
ENDIF(CMAKE_BUILD_TYPE MATCHES Release)

QtCreator Cmake C++17 Features

So here I am, compiling my CMake-based C++ Projects in my terminal like there's not tomorrow with gcc-7.2.0 on Xubuntu 16.04 (via ppa)
Everything works fine and the new features add considerable value to my codebase.
However, trying to compile the very same project in qtcreator with the same compiler yields me errors like the following
: error: expected ‘)’ before ‘;’ token
if (auto event = events_.find(eventName); event == end(events_)) {
^
: error: ‘else’ without a previous ‘if’
} else {
^
if trying to compile initializer-ifs. I tried to manually pick gcc-7 in the build&run section in qtCreators options but without success. So my question is this:
What do I have to adjust in the IDE to make it conform to this latest standard?
If you're compiling Cmake projects in Qt creator, just be sure there is a line like this in your CMakeLists.txt:
set(CMAKE_CXX_STANDARD 17)
To use gcc-7.2.0, be sure it is listed in the Compilers tab of the Build & Run section in Tools/Option. Then, in Kits tab, select the kit you configured your project with, and select gcc-7.2.0 as the the kit's compiler.
If you're using qmake, instead, add this line to your pro file:
QMAKE_CXXFLAGS += -std=c++17