I am cross compiling (host: x86 linux) for raspberry pi (ARM) using
arm-bcm2708hardfp-linux-gnueabi-g++
When I choose g++ it all works out fine and compiles. But when cross compiling I get:
error: 'close' was not declared in this scope
This is the simplified source code
#include <iostream>
#include <fcntl.h>
using namespace std;
int fd;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
close(fd);
return 0;
}
Any idea? Did I forget to include smth? I am using eclipse as IDE.
I believe it's as simple as this: close
is declared in <unistd.h>
, not <fcntl.h>
. To find out what header file declares a symbol, you should always check the man pages first.
#include <iostream>
#include <unistd.h> // problem solved! it compiles!
using namespace std;
int fd;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
close(fd); // but explicitly closing fd 0 (stdin) is not a good idea anyway
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With