C ++ Avoid Linking Libraries

I currently have a C ++ installation, for example,

class FlowController { public: //... private: cntrl::OneWayValve _intake; } 

As you can see, I am using an instance of cntrl :: OneWayValve in my class. The Valve class is in another library that I link to at compile time. Cntrl :: OneWayValve has cntrl :: Value in its implementation, for example:

 class OneWayValve { public: //... private: cntrl::Valve _valve; } 

And, as before, cntrl :: Valve is in a different library for reasons that you will have to ask about the previous developer.

Now that I am compiling my FlowController class, I need to link it to the OneWayValve library and the cntrl :: Valve library.

My question is: Can I only link to the cntrl :: OneWayValve library at compile time?

Forward declaration?
Static libraries (really don't want to do this)?
Another alternative?

Basically, I don't want to know that its use of cntrl :: Valve internally, its nothing from my business.

Note: apologies for the OS - this is Unix.

Cheers, Ben

+4
source share
3 answers

What you can do is make the Valve library part of your OneWayValve library with a tool called a librarian. I donโ€™t know which OS / compiler you are using, so Iโ€™ll tell you how to do it with Visual Studio, since this is the only system I did it on (if you do not want to read CP / M + LIB-80 :-)

If you open the Tools | Options dialog for the OneWayValve project and select Configuration Properties | Librarian | Additional dependencies, you can put a link to your Valve library in the "Additional dependencies" setting. This will force OneWayValve.lib to contain any objects that it refers to Valve.lib.

+1
source

Unfortunately, OneWayValve not very well designed for you. You need not only reference both libraries, but you will also have to recompile the OneWayValve library and your code if the Valve class changes.

0
source

You can do this by defining all the OneWayValve and Valve methods in your headers as inline. Then you do not need to contact the library.

But if it was designed in this way, then what problems are associated with this library? Nothing wrong with dynamically linking a library.

0
source

Source: https://habr.com/ru/post/1336134/


All Articles