Possible bug with DirectoryIterator - c++

Working with DirectoryIterator example, from Poco documentation, I have some issues with it.
This is the source code:
#include "Poco/DirectoryIterator.h"
#include <iostream>
using Poco::DirectoryIterator;
using Poco::Path;
int main(int argc, char** argv) {
std::string cwd(Path::current());
DirectoryIterator it(cwd);
DirectoryIterator end;
while (it != end) {
std::cout << it.name();
if (it->isFile())
std::cout << it->getSize();
std::cout << std::endl;
Path p(it.path());
++it;
}
return 0;
}
I am using Mingw, with gcc 8.2, under Msys2 and Windows 7 (tested with Windows 10 too). Using Eclipse CDT as IDE.
When compiling in Debug mode, and run the binary, the exception "Path not found" is thrown.
When compiling in Release mode, and run the binary, it works, but the iterator "it" doesn't evolve.
It always shows "a.txt"
I am trying the example with this directory tree:
/test//a.txt
/test//b.txt
/test//test2
/test/test2/c.txt
/test/test2/d.txt
I have tested the same example in linux, and everything is working ok.
Why does it work in Linux, but not in Windows?
Any clue?
Thanks

Compiling your program, I get the next message: "Compiling POCO on Windows without #define POCO_WIN32_UTF8 is deprecated"
You need to compile with #define POCO_WIN32_UTF8.
#define POCO_WIN32_UTF8
#include "Poco/DirectoryIterator.h"

Related

weird c++ string bug with gcc

Can someone explain what is happening here?
#include <iostream>
#include <string>
using namespace std;
int main() {
string kek = "kek";
cout << "test" << endl;
return 0;
}
For some reason, every time I compile with g++, and I declare a string variable, I can't see any output, no compile or runtime errors, simply no output.
Now, if I change the code to be this instead:
#include <iostream>
#include <string>
using namespace std;
int main() {
// string kek = "kek";
cout << "test" << endl;
return 0;
}
then everything works.
Does anyone know what the problem is here?
I am currently on Windows 10, using gcc 8.1.0.
Edit:
same thing but using bash, linux compile
i think the version of mingw i had is bugged so trying to reinstall it
Okay so still i have no idea what that bug was about,
but when i had it, the version of MinGW i had was 32bit,
changing the MinGW installation to 64bit, fixed that issue.
i have changed nothing, except removing MinGW 32bit from my comp,
and setting the MinGW 64bit.
Swaping from MinGW 32bit to 64bit, fixed the issue.

G++ compiled application crashes when using std::string or char pointer

I just installed MinGW because I wanted to write code using a lightweight code editor instead of Visual Studio or Codeblocks, both of which I never had a problem with. So the code compiles and works, but for some reason it crashes every time I try to use a string or char pointer. For example this code:
#include <iostream>
int main()
{
std::string a;
a = "Hello";
std::cout << a;
std::cin.get();
}
throws this error when executed:
but this code:
#include <iostream>
int main()
{
std::cout << "hello";
std::cin.get();
}
Works perfectly:
(I have tried both with std::string and const char* with no difference)
I have Visual studio 2017 installed, I don't know if that could be the issue.
MinGW version 6.0.3.
PD: I only added C:/MinGW/bin directory to Path environment, don't know if I should add any other directory
Fixed it! For some reason g++ by default links the std library dynamically. As my program didn't find the dll it was not able to link std::string and std::cout. The solution was to pass the -static-libstdc++ argument to g++.
TL;DR:
Instead of compiling directly like this:
g++ somesourcefile.cpp
try this argument:
g++ somesourcefile.cpp -static-libstdc++

File too big compiling on Cygwin G++

I'm specifically building a test program to work on Chaiscript, which is how I encountered this issue:
chai.cpp:
#include <cstdio>
#include <iostream>
#include <chaiscript/chaiscript.hpp>
#include <chaiscript/chaiscript_stdlib.hpp>
std::string helloWorld(const std::string &t_name)
{
return "Hello " + t_name + "!";
}
int main(int argc, char** argv, char** env) {
chaiscript::ChaiScript chai;
chai.add(chaiscript::fun(&helloWorld), "helloWorld");
chai.eval("puts(helloWorld(\"Bob\"));");
return 0L;
}
/usr/lib/gcc/i686-pc-cygwin/5.4.0/../../../../i686-pc-cygwin/bin/as: CMakeFiles/chai.dir/src/chai.cpp.o: too many sections (37830)
/tmp/ccqGbeku.s: Assembler messages:
/tmp/ccqGbeku.s: Fatal error: can't write CMakeFiles/chai.dir/src/chai.cpp.o: File too big
/usr/lib/gcc/i686-pc-cygwin/5.4.0/../../../../i686-pc-cygwin/bin/as: CMakeFiles/chai.dir/src/chai.cpp.o: too many sections (37830)
This issue doesn't appear when I build on Mac or Linux.
I discovered a workaround to this issue from the Chaiscript CMakeLists.txt:
if(MINGW OR CYGWIN)
add_definitions(-O3)
endif()
Other searches on the Internet imply this big-object problem is linked the Windows executable format, and is not likely to be addressed in G++. Using MingW32 did not address this error in my case - I'm not going to 64-bit.
Object file has too many sections

CLion finds a wrong function signature

I constantly have CLion editor showing me parameter type mismatch errors while during build everything is fine. For example, consider the following MWE:
#include <iostream>
#include <boost/container/flat_set.hpp>
using namespace std;
namespace bc = boost::container;
int main() {
bc::flat_set<bc::flat_set<int>> manySets;
bc::flat_set<int> oneSet({1, 2, 3});
manySets.insert(oneSet);
cout << "Hello, World!" << endl;
return 0;
}
Here flat_set is a template from boost library (description could be seen here). Editor shows me an error:
But when I build it (even from CLion), everything is compiled fine.
My system is:
Ubuntu 15.10 64bit
CLion 1.2.4
This looks like a known problem - https://youtrack.jetbrains.com/issue/CPP-6027. We hope to fix it soon.

Simple netbeans C++ project doesn't compile

I installed Netbeans and as C++ compiler I installed cygwin. I made a simple project to test out my installation, this is the code:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "test";
return 0;
}
This is the error message that it gives: http://pastebin.com/jRRh7MPi
I hope you guys can help me out.
You need to either explicitly link to C++ standard library, or compile using g++ instead of gcc.