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...

2
  • Could you try compiling this without Eclipse? Just add your crosscompiler binaries to PATH, like this: export PATH=$PATH:<pathtoyourcrosscompiler> where <pathtoyourcrosscompiler> is full path to arm-bcm2708hardfp-linux-gnueabi-g++. Then try: `arm-bcm2708hardfp-linux-gnueabi-g++ -o /tmp/test <yoursourcefile>', where <yoursorucefile> is a path to the file containing your program. Paste the output here, please. Also please try to change your path to full path. Commented Aug 29, 2012 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! Commented Jan 1, 2014 at 16:01

1 Answer 1

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.