I found a problem.
I wrote a demo that opened and read a special file. It runs in qnx 7.0.
When I used "x86_64-pc-nto-qnx7.0.0-g ++ FileTest.cc -o FileTest", it compiled and runs successfully.
When I compiled with "x86_64-pc-nto-qnx7.0.0-g ++ -std = c ++ 11 FileTest.cc -o FileTest", some errors is reported:
FileTest.cc: In function 'int main()':
FileTest.cc:13:40: error: 'open' was not declared in this scope
int fd = open("./Zqm.bin", O_RDONLY);
^
FileTest.cc:15:25: error: 'read' was not declared in this scope
read(fd, buffer, 100);
^
FileTest.cc:21:13: error: 'close' was not declared in this scope
close(fd);
^
I don't have experience in this (POSIX functions), but you might need to add -lc (that's LC, not IC) to your command-line to link with the C library (clib).
But as jonnin said, since you're clearly using C++, I would used std::ifstream instead of Unix functions.
You should include <cstring> for memset.
You can zero the buffer with {}.
You shouldn't try to print buffer with cout unless you are sure it is zero-terminated. Even then, if it's binary data you should loop through it and print its byte values.
Works for me (compiled as C++14). However, I also see no reason to use the low-level functions here.
There's a C++ <memory> where, e.g., unique_ptr lives. But I guess because strings are basically just sequences of bytes (in the common case) the "memory" functions in C are in <string.h>, hence <cstring>.
BTW, I don't think I actually answered his question since I don't think he was compiling on desktop linux (qnx is a linux-based embedded thing). So I'm not sure what the problem was.
Need to add the compile option XOPEN_SOURCE.
like this:
x86_64-pc-nto-qnx7.0.0-g++ -D_XOPEN_SOURCE=500 -std=c++11 -L/home/xxx/3rd-party/qnx-x86_64/protobuf/lib -L/home/xxx/3rd-party/qnx-x86_64/zeromq/lib -lprotobuf -lzmq -I/home/xxx/3rd-party/qnx-x86_64/protobuf/include -I/home/xxx/3rd-party/qnx-x86_64/zeromq/include simple.pb.cc ZmqDumpTest.cc -o ZmqDumpTest
details:
In the program, in order to achieve the above functions, it is necessary to define a corresponding macro. As the second function POSIX, _POSIX_SOURCE should be defined. Similar to _BSD_SOURCE, _SVID_SOURCE, _XOPEN_SOURCE.
That is:
#define _XOPEN_SOURCE
It is for the purpose of using the 5. The X/Open Portability Guide.
QNX-g++ is a GCC variant. GCC's language default includes GNU extensions.
The -std=c++11 disables GNU extensions.
man g++:
c++11
The 2011 ISO C++ standard plus amendments.
gnu++11
GNU dialect of -std=c++11.
There are thus multiple options:
* Define a macro on command line or in source
* Tell g++ to use the GNU extensions (to enable your POSIX functions)
* Use Standard C functions
* Use Standard C++ functions