5

Even though I am including <fcntl.h>, I keep getting

'write' was not declared in this scope
'read' was not declared in this scope
'close' was not declared in this scope

even though the open() function works just fine, and it compiles fine for x86.

I am following the instructions at [Howto] Cross compile using Eclipse and running Eclipse on a VM (oSX as host) with Ubuntu 12.04.

My Project Properties are:

CrossSettings, Path: tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/bin
Cross GCC Compiler, Command: arm-bcm2708hardfp-linux-gnueabi-gcc
Cross G++ Compiler, Command: arm-bcm2708hardfp-linux-gnueabi-g++
Cross G++ Linker, Command: arm-bcm2708hardfp-linux-gnueabi-g++

This is the simplified source that gives the error for the "close":

#include <iostream>
#include <fcntl.h>

using namespace std;
int fd;

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    close(fd);
    return 0;
}

When I compile for x86 with gcc/g++ it works...

Mark Booth
  • 4,360
  • 2
  • 29
  • 42
tzippy
  • 151
  • 1
  • 3
  • Could you try compiling this without Eclipse? Just add your crosscompiler binaries to PATH, like this: export PATH=$PATH:<pathtoyourcrosscompiler> where is full path to arm-bcm2708hardfp-linux-gnueabi-g++. Then try: `arm-bcm2708hardfp-linux-gnueabi-g++ -o /tmp/test ', where is a path to the file containing your program. Paste the output here, please. Also please try to change your path to full path. – Krzysztof Adamski Aug 29 '12 at 12:11
  • Have you got anywhere on this problem? If so, please create a self-answer and mark it as such. We're (at least I) am going through the site to try and get the question:answer ratio up. Thanks! – RPiAwesomeness Jan 01 '14 at 16:01

1 Answers1

1

I think that this compiling under x86 is a fluke. According to the read manpage, it's part of unistd.h. Same for close() and write(). Only open is declared in fcntl.h. I think you'll need to include both:

#include <unistd.h>
#include <fcntl.h>

If you're planning to use C++ streams, you'll also need to include fstream.

#include <fstream>
Fred
  • 4,552
  • 18
  • 29