Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #89459

Re: Link at runtime instead of build-time

From Christian Gollwitzer <auriocus@gmx.de>
Newsgroups comp.lang.c++
Subject Re: Link at runtime instead of build-time
Date 2023-03-05 22:45 +0100
Organization A noiseless patient Spider
Message-ID <tu32id$1en3f$1@dont-email.me> (permalink)
References <6e54715f-9094-46c2-94ec-82aa9d7eaccdn@googlegroups.com> <tu2m2g$1ddsn$1@dont-email.me> <bd9d76af-a28d-4c27-9b1b-4246cc25a8e4n@googlegroups.com>

Show all headers | View raw


Am 05.03.23 um 20:11 schrieb Frederick Virchanza Gotham:
> 
>> As always, I'm questioning this NEED.
> 
> 
> I'm combining a console program and a GUI program into one program (i.e. one executable).
> 
> Depending upon the command-line arguments to the program, it might enter into GUI mode, and if it does, it needs to load the GUI libraries.
> 
> But if it runs in console mode, I don't want the system to need to have the Gui libraries installed.

This usually works by exporting a known entry function from the library, 
load the library by dlopen() and find the function using dlsym(). Put 
all the functionality into the library, so that you can invoke the GUI 
stuff with a simple call. It doesn't make sense to have global variables 
in the main program have influenced by loadable library.

If you need a lot of the functionality of the main program in the 
library, then instead put this functionality in a library if its own 
(say, libengine.so). Then the main program reduces to

if (std::string(argv[1] == "-gui") {
	dlopen();
	run_gui = dlsym("...");
	run_gui();
} else {
	run_cmdline();
}

Link both this main and the GUI library with libengine.so.

	Christian

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Link at runtime instead of build-time Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2023-03-05 09:59 -0800
  Re: Link at runtime instead of build-time Christian Gollwitzer <auriocus@gmx.de> - 2023-03-05 19:12 +0100
    Re: Link at runtime instead of build-time Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2023-03-05 11:11 -0800
      Re: Link at runtime instead of build-time Christian Gollwitzer <auriocus@gmx.de> - 2023-03-05 22:45 +0100
        Re: Link at runtime instead of build-time Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2023-03-05 16:10 -0800
          Re: Link at runtime instead of build-time Christian Gollwitzer <auriocus@gmx.de> - 2023-03-06 09:29 +0100
            Re: Link at runtime instead of build-time Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2023-03-06 02:37 -0800
      Re: Link at runtime instead of build-time "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2023-03-06 15:45 +0100
        Re: Link at runtime instead of build-time Muttley@dastardlyhq.com - 2023-03-06 17:14 +0000
          Re: Link at runtime instead of build-time Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2023-03-06 13:41 -0800
            Re: Link at runtime instead of build-time gazelle@shell.xmission.com (Kenny McCormack) - 2023-03-06 22:20 +0000
            Re: Link at runtime instead of build-time Christian Gollwitzer <auriocus@gmx.de> - 2023-03-06 23:58 +0100

csiph-web