Search code examples
clibraries

apue.h on macOS


I follow these steps in order to install apue.h on macOS:

  1. make in the apue.3e folder. No errors here. I also tried make CC=/usr/bin/clang as another user suggested in another topic.
  2. Copied the libraries:
sudo cp ./lib/libapue.a /usr/local/lib
sudo chmod 644 /usr/local/lib/libapue.a
sudo cp ./include/apue.h /usr/local/include
sudo chmod 644 /usr/local/include/apue.h
  1. Run a test file: gcc test.c -o test -lapue But I get the following error: error: implicit declaration of function 'open' is invalid in C99

I have no idea of how to install correctly the library in macOS. What I have to do now?

Test.c:

#include <apue.h>
#include <stdio.h>

int main() {
        int fd = open("test.txt", O_CREAT);
        printf("Hello, world!\n");
        return 0;
}

Uhm, so embarassing. The library was correctly installed, I tried with the open function because I asked a test code to chatGPT and it wrote me this code. I'm sorry and thanks for your replies.


Solution

  • open is a standard UNIX call, not part of apue

    int fd = open("test.txt", O_CREAT);
    

    you need to include its header

    #include <fcntl.h>
    

    see https://man7.org/linux/man-pages/man2/open.2.html