ImportC PureBasic - Linker error

Mac OSX specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 610
Joined: Thu May 30, 2013 4:39 pm

ImportC PureBasic - Linker error

Post by Wolfram »

Hello everybody!
I get an Linker error when importing a C file on PB 5.31 64 and 32 bit on OSX 10.9.4.
clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated
clang: error: cannot specify -o when generating multiple output files

These works on 10.7

Code: Select all

ImportC "/usr/include/sys/unistd.h"
  usleep(T)
EndImport
and these not on 10.9

Code: Select all

ImportC "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/sys/unistd.h"
  usleep(T)
EndImport
Whats wrong???
macOS Catalina 10.15.7
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: ImportC PureBasic - Linker error

Post by Trond »

None of these are supposed to work!

Import and ImportC are for importing compiled symbols from object files (compiled files).

ImportC only refers to the calling convention used. It doesn't import C source files.

If the command you wish to import is part of the standard libraries that are already linked, you do not have to specify a filename. So you can do:

Code: Select all

ImportC ""
  usleep(T)
EndImport
Else you must put the filename of an object file.
User avatar
Shardik
Addict
Addict
Posts: 2076
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: ImportC PureBasic - Linker error

Post by Shardik »

Trond is right! You should use just ImportC ""... EndImport.

usleep(Microseconds.i) is a BSD command (MacOS X is just a modified BSD Unix with a mach kernel, the basic OS parts of MacOS without any GUI are open sourced by Apple and called Darwin) to suspend execution of your program for the specified microseconds. You might as well use sleep(Seconds.i) to wait the specified time in seconds or nanosleep(Nanoseconds.i) to wait the specified nanoseconds. To obtain help for these commands you may open a shell and type
> man usleep

You may even try these commands in the shell:
> sleep 2

This is an example program which I tested on Mavericks (OS X 10.9.5) and which should just work on all MacOS X versions:

Code: Select all

ImportC ""
  sleep(Seconds.I)         ; Suspend execution for the given number of seconds 
  usleep(Microseconds.I)   ; Suspend execution for the given number of microseconds
  nanosleep(Nanoseconds.I) ; Suspend execution for the given number of nanoseconds
EndImport

Debug "Starting to wait for 2 seconds..."
sleep(2)
Debug "2 seconds have expired!"
Debug ""
Debug "Starting to wait for 1500000 microseconds..."
usleep(1500000)
Debug "1500000 microseconds (= 1.5 second) have expired!"
Why do you have to use sleep() at all? I assume that PureBasic's native Delay(Milliseconds.i) command is just a wrapper of usleep() or nanosleep()... :wink:
Last edited by Shardik on Fri Jul 10, 2015 7:29 am, edited 1 time in total.
Wolfram
Enthusiast
Enthusiast
Posts: 610
Joined: Thu May 30, 2013 4:39 pm

Re: ImportC PureBasic - Linker error

Post by Wolfram »

Thanks Trond, Thanks Shardik.

…sometimes the problem is in front of the computer ;-)
Why do you have to use sleep() at all? I assume that PureBasic's native Delay(Milliseconds.i) command is just a wrapper of usleep() or nanosleep()
Because I need 0.1 ms delay.
macOS Catalina 10.15.7
Post Reply