Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8450705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:02:37+00:00 2026-06-10T11:02:37+00:00

I have a command-line executable from which I would like to be able load

  • 0

I have a command-line executable from which I would like to be able load essentially any dynamic library that contains Objective-C classes. In the Project Settings, I have specified that my program supports garbage collection (without requiring it). To this end, I use dlopen to load the libraries, as it’s globally more flexible than NSBundle (first off and most importantly, it can load libraries that aren’t in a bundle).

However, when I try to load a library or framework that requires garbage collection, dlopen fails and I get this message:

Unable to open /path/to/object: dlopen(/path/to/lib, 2): no
suitable image found. Did find:
       /path/to/lib: GC capability mismatch

If my program supports garbage collection, why can’t it load libraries that require it? How can I load libraries that require it?

I can’t really flag my executable as requiring garbage collection because it will stop working with libraries that don’t support it.

Right now I have two versions of my executable, but that’s sub-par.

Additional informations: I target Mountain Lion only. My program is a universal binary and it currently handles relaunching as its 32-bits counterpart using the posix_spawn function, however there seems to be no flag controlling garbage collection there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:02:39+00:00Added an answer on June 10, 2026 at 11:02 am

    I found the solution to my problem. The Objective-C runtime has several switches triggered by environment variables, including OBJC_DISABLE_GC that can turn off the garbage collector even if the executable wants it on. This switch is taken into account when new images are loaded (see gc_enforcer and how it uses the UseGC static variable), so turning the GC off will actually affect the way libraries are loaded into the process.

    My solution, then, is to implement proper retain/release logic into my executable but compile it with -fobjc-gc-only. I then try to load the library normally; if it works, everything’s good. If it doesn’t, I programmatically relaunch the process with the same arguments, plus OBJC_DISABLE_GC=YES in its environment, so the GC is disabled and the library successfully loads this time.

    This snippet excludes error handling.

    char disableGC[] = "OBJC_DISABLE_GC=YES";
    // resets the current process with the given argv and enables the GC as per useGC
    void respawn(char* const argv[], bool useGC)
    {
        posix_spawnattr_t attributes;
        posix_spawnattr_init(&attributes);
        posix_spawnattr_setflags(&attributes, POSIX_SPAWN_SETEXEC)
    
        // build the environment variables array
        std::vector<char*> environment;
        for (char** environ_iter = environ; *environ_iter != 0; environ_iter++)
            environment.push_back(*environ_iter);
    
        // disable the GC if we need it off
        if (!useGC)
        {
            environment.push_back(disableGC);
        }
    
        environment.push_back(nullptr);
    
        pid_t child;
        posix_spawn(&child, argv[0], nullptr, &attributes, argv, environment.data());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a command-line executable which I need to run from Java on Windows
We have a command line exe that takes input from a text file and
I have a command-line process that creates a PDF file from an HTML file
I have a Java executable that takes in command line arguments to launch root
i have a command line executable program that accepts a configuration file as it's
I have a Perl module CSS::Minifier that I need to make executable (command line
I have a command line tool written in c# (that i have the source
I have a command line program that prints out a report such as: I
I have a command line script that uses the Django ORM and MySQL backend.
I have a command line that I'm trying to modify to remove some of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.