0

I'm working on a library, this library has multiple classes of which some of the time they are needed by the user, other times they are not needed. There are, however "core" classes and "helper" classes but the rest are what the user wants in his/hers runtime environment.

I have been recently been doing some programming in PHP and found that a specific library has an approach like this:

In the config file:

'classes' => [
     'foo' => 'src/app/classes/Foo',
     'bar' => 'src/app/classes/Bar',
]

Then whenever you want to call "foo" you can just use: using foo;

I'm wondering whether or not this approach is possible in C++ (obviously, different Syntax) but have a config file that loads all of required .h files that are needed so then the user does not have to include them each time?

My aim, is to have build a shell script program that will allow users to access the library methods from the terminal and pass in data.

Phorce
  • 4,424
  • 13
  • 57
  • 107
  • 1
    I think you are looking for dynamic libraries : http://stackoverflow.com/questions/496664/c-dynamic-shared-library-on-linux – AntoineB Aug 26 '15 at 13:51
  • [Building Your Own Plugin Framework: Part 1](http://www.drdobbs.com/cpp/building-your-own-plugin-framework-part/204202899?cid=RSSfeed%255FDDJ%255FCpp) – Joe Aug 26 '15 at 13:51
  • If I knew PHP more I might understand where you're coming from better, but in C++ classes basically don't exist anymore once compiled, only functions. – SirGuy Aug 26 '15 at 13:51
  • You have many misunterstandings here. To start with, the *user* won´t ever do anything with .h files. – deviantfan Aug 26 '15 at 13:59
  • @GuyGreer Let me explain a bit more.. Say I have a library (.so) and this contains 1000 different elements and therefore there are 1000 different .h and the user only wants to use 500 of these, they can specify these.. Also, with the console app, when a user (in terminal) does App and it loads with ">>" I want them to be able to type: ">> Hello::World("hi");" without "HelloWorld() cannot be found" because I haven't included the .h file – Phorce Aug 26 '15 at 14:01
  • About `build a shell script program that will allow users to access the library methods from the terminal and pass in data.`: C++ has no unified ABI, ie. the binary format of your lib depends on the compiler. If you´re using C instead, it´s possible ... see eg. LoadLibrary for Windows (Linux has similar functions) – deviantfan Aug 26 '15 at 14:02
  • @deviantfan So, building something like (how Python) works from the terminal, is impossible to do? That is my overall goal .. Obviously, not as a language, just as a way to run specific tasks – Phorce Aug 26 '15 at 14:03
  • About your second-last comment: It seems like your real question is "Why do I need .h files? I don´t like that I have to include them every time". Well... but you want to be able to use precompiled libraries, right? – deviantfan Aug 26 '15 at 14:05
  • @deviantfan - Yes, I want to be precompiled libraries.. Like, in the future, if I want to add another part of the library, the whole library shouldn't need to be re-compiled.. Just have to include it and it can be used - Am I making sense? – Phorce Aug 26 '15 at 14:06
  • @Phorce You will always have to recompile the binary where you modified the code. What you can do is to split your program into several binaries, see the link in the first comment. – deviantfan Aug 26 '15 at 23:49

0 Answers0