Error read() on macOS arm64

Bare metal programming in PureBasic, for experienced users
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Error read() on macOS arm64

Post by Wolfram »

Hello,

why do get I this error on an ARM Mac?
"error: call to undeclared function 'read'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]"
On an Intel Mac the same code works.

Code: Select all

! read(serialPort, p_buffer, 4);
macOS Catalina 10.15.7
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Error read() on macOS arm64

Post by Fred »

You need to declare it with clang (or include the .h)
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: Error read() on macOS arm64

Post by Wolfram »

If I include it like this I get an error "clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: error: cannot specify -o when generating multiple output files"

Code: Select all

ImportC "unistd.h"
  read_(fd, p_buf, size)
EndImport
macOS Catalina 10.15.7
Quin
Addict
Addict
Posts: 1125
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Error read() on macOS arm64

Post by Quin »

I haven't tried this, but what if you do it with inline c?
like:

Code: Select all

! #include <unistd.h>
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Error read() on macOS arm64

Post by Fred »

You can try

Code: Select all

ImportC ""
  read_(fd, p_buf, size)
EndImport
Wolfram
Enthusiast
Enthusiast
Posts: 604
Joined: Thu May 30, 2013 4:39 pm

Re: Error read() on macOS arm64

Post by Wolfram »

This example works

Code: Select all

ImportC ""
    _read_(port, *read_buf, size) 
EndImport
  
  read_(port, *read_buf, size) 
But how can use the C code to include th .h file?
This example does not work on my ARM Mac and why does the C function red() works without including on my Intel Mac ?

Code: Select all

! #include <unistd.h>
! read(v_serialport, p_buffer, 4);
macOS Catalina 10.15.7
ricardo_sdl
Enthusiast
Enthusiast
Posts: 141
Joined: Sat Sep 21, 2019 4:24 pm

Re: Error read() on macOS arm64

Post by ricardo_sdl »

Fred wrote: Sun Feb 16, 2025 6:01 pm You can try

Code: Select all

ImportC ""
  read_(fd, p_buf, size)
EndImport
What does the empty string after ImportC imply or mean?
You can check my games at:
https://ricardo-sdl.itch.io/
Quin
Addict
Addict
Posts: 1125
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Error read() on macOS arm64

Post by Quin »

ricardo_sdl wrote: Mon Feb 17, 2025 7:17 pm
Fred wrote: Sun Feb 16, 2025 6:01 pm You can try

Code: Select all

ImportC ""
  read_(fd, p_buf, size)
EndImport
What does the empty string after ImportC imply or mean?
It means you're importing a function from a library PB has already imported, just the function itself hasn't been imported.
Post Reply