C++ IO Functions not working
-
Hello,
the standard io functions of c++, do not seem to be working, while the C ones are working.
Minimum example, gives segmentation fault. Obviously you should not use printf in c++, but std::cout is also not working.
#include <signal.h> #include <fstream> #include <iostream> using namespace std; bool shutdown_ = false; void sigint_handler(int s) { shutdown_ = true; } int main(const int argc, const char **argv) { signal(SIGINT, sigint_handler); printf("hello printf\n"); ofstream outFile ("test.txt"); outFile << "hello" << std::endl; outFile.close(); return 0; }
Output:
root@Omega-229D:~# ./main hello printf Segmentation fault
So it is compiling, but not working then when running the program.
-
@joh :
Just curious..
Are you cross compiling it using "toolchain-mipsel_24kc_gcc-7.3.0_musl" ? Also, would like to know the options passed ..I use mipsel-linux-muslsf-native.tgz, which is 32-bit, from http://musl.cc (v 9.3.1) for compiling..
Runtime is musl-libc 1.2.1 from http://musl.libc.org, compiled in qemu, then moved to omega2.The setup is running under qemu-mipsel in Linux x64.Malta 24kec processor can take only 256MB ram.I guess it is by mips design, and no smp.
To complie my 2k loc, that is good.
I have compiled protobuf3 under qemu.
When compiling the entire Omega/OpenWRT..things are different, though.We need lot of ram, smp..
Just sharing.
Thanks..
-
@joh I compiled your sample and ran it on my device without issue. I would add a statement to your sig handler to determine what signal you may be capturing which I suspect is where you will identify the root cause.
void sigint_handler(int s) {
printf("Caught signal %s", s);
shutdown_ = true;
}
-
Ok I figured out now that the basic example (https://github.com/OnionIoT/c-cross-compile-example) is working with the file operations.
@tjoseph1 Yes I am using the basic "toolchain-mipsel_24kc_gcc-7.3.0_musl" with the Flags from the xCompile file.
@crispyoz The signal handler did not show anything, I don't think it's the problem.
I have a lot of libraries included, which seem to cause the problem, now I have to find out which one is causing it.
But I still wonder why the library would change the behavior of the file io functions..
-
Ok I figured out now that the uClibc++ is the problem, I require this library for zmq.
I am using the uClibc++ and zmq just from the make menuconfig, so seems I need to find another version here...