Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ARM Cross Compilation error using fcntl.h : error: 'close' was not declared in this scope

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.

like image 500
tzippy Avatar asked Aug 28 '12 12:08

tzippy


1 Answers

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;
}
like image 72
Quuxplusone Avatar answered Oct 06 '22 05:10

Quuxplusone