fcntl, Tiger, Lion, weak linking and a headache

Discussion in 'Mac Programming' started by Skwint, Oct 20, 2011.

  1. Skwint macrumors newbie

    Joined:
    Oct 20, 2011
    #1
    Hi,
    I have some C++ code which is built on snow leopard and runs on Tiger, Leopard, Snow Leopard and Lion. I am using calls from the 10.6 SDK and successfully avoiding them on Tiger at run time, so I'm pretty sure I've got my environment set up more or less right.

    One call I need is fcntl. If I build on Tiger it works on Tiger. If I build on snow leopard it crashes on Tiger. It crashes at run time on the call to fcntl and the error is that _fcntl@unix2003 can't be found in libSystem.B.dylib.

    I'm not sure how to go about fixing this - weak linking deals with an API that doesn't exist, but I don't understand how to deal with an API that seems to have changed? moved? something? I know it exists somewhere on Tiger because the code compiles and runs there...

    Does anyone know how to call fcntl on Tiger when build against the 10.6 SDK?

    Thanks,
    Andy
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    Have a look how fcntl is defined. Follow the macros back. That should tell you how to fix it. (Hint: When you use a new SDK, the compiler assumes you want to be Posix compatible. And Tiger apparently doesn't have a Posix compatible fcntl. So you need to override Posix 2003 compatibility).
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
  4. Skwint thread starter macrumors newbie

    Joined:
    Oct 20, 2011
    #4
    thanks

    Thanks! Google failed me - all I ever got was forum posts by other people with the same problem, and they were all solving it by linking against the 10.4 sdk.
     
  5. Skwint thread starter macrumors newbie

    Joined:
    Oct 20, 2011
    #5
    hmf

    This hasn't helped quite enough - the Paul Beach solution (link with 10.4) doesn't cut it - I need 10.6 calls to run on Lion. I've tried messing with the macros and they don't seem to have any impact - the $UNIX2003 is still being appended to the function name. The header file itself is even less clear than the documentation.

    At the moment I am thinking my best bet is to write my own library for the sole purpose of calling fcntl and building just that library on Tiger. That seems ridiculous :(
     
  6. gnasher729, Oct 21, 2011
    Last edited: Oct 21, 2011

    gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #6
    Instead of calling fcntl (arguments) just call (fcntl) (arguments). That prevents macro evaluation.
    And defining __DARWIN_ONLY_UNIX_CONFORMANCE 1 should fix the problem (after reading the header file).
     
  7. Skwint thread starter macrumors newbie

    Joined:
    Oct 20, 2011
    #7
    ah!

    so so close!

    the ()s didn't have any effect, but the __DARWIN_ONLY_UNIX_CONFORMANCE did - my code now builds and runs and ... dies somewhere else. It seems that setting that flag in my main executable prevents it loading plugins compiled without it.

    Thankyou though! That counts as progress in my book! :rolleyes:
     

Share This Page