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

  • SEARCH
  • Home
  • 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 3273258
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:54:47+00:00 2026-05-17T18:54:47+00:00

I am writing an executable which uses dlopen() (LoadLibrary() on Windows) to dynamically load

  • 0

I am writing an executable which uses dlopen() (LoadLibrary() on Windows) to dynamically load a shared library. The shared library uses symbols from the executable.

In Windows this is possible. Executables can export symbols: declspec(dllexport) and .def files both work. The linker, when creating the .exe, also creates the .lib file (the “import library”), so the DLL just needs to link with that .lib.

In Linux, this is possible as well. I pass -Wl,-export_dynamic when building the executable so it exports its symbols.

On Mac OS X, instead… -Wl,-export_dynamic does not work, but there is -Wl,-exported_symbols_list,<filename> where <filename> is a list of symbols to export (a sort of a simpler version of a .def file). But then, building the shared library is not as easy: the linker complains about the unresolved symbols.

I tried a hack: renamed the executable to lib<executable>.dylib and, when linking the shared library, I passed -l<executable>. But it gives the error “can’t link with a main executable”.

The general problem is that Linux shared libraries can have unresolved symbols, while Windows and Mac OS X do not allow it. But Windows has “import libraries” to resolve symbols against dependencies, and Mac OS X apparently does not…

How can this be solved on Mac OS X? Is there an equivalent of an “import library” (the stub library created by the Windows linker when creating a .dll, so, if any module needs to dynamically link to the .dll, it is linked against the “import library”)? Or some other solution?

  • 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-05-17T18:54:48+00:00Added an answer on May 17, 2026 at 6:54 pm

    The standalone Lua interpreter supports dynamically loading (via dlopen) of shared libraries that use symbols from the executable (the Lua API). No special link flag is used when building it. The shared libraries are built using this incantation:

    env MACOSX_DEPLOYMENT_TARGET=10.3 gcc -bundle -undefined dynamic_lookup -o random.so lrandom.o
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If you are writing a program that is executable from the command line, you
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
I'm writing a python script that uses subprocess.Popen to execute two programs (from compiled
Let's say I am writing installation script for the program which contains executable file
When writing C/C++ code, in order to debug the binary executable the debug option
I'm writing a piece of open-source software which will be easily embeddable (both static/dynamic
I'm writing a C application which is run across a compute cluster (using condor).
I am developing a Math application which can be extended by writing python scripts.
I'm in the process of writing a compiler that will be generating ELF executable
I'm writing a small program which is to be used as a digital distribution

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.