I am writing a small application in c++ and I have some questions regarding that. I am basically a Java developer now moving into c++.
-
If I use some library like boost, curl etc. can I make it run without installing that on the client machine (I mean something like including all library jar files inside the project in Java)
-
I have installed some library or software in linux. After that if I type in the terminal it pings the software. For example php, after you install it you can use php from terminal. How does this work? Can I use my simple c++ project to do so?
Yes. You use a process called static linking, which links all the libraries into one big executable. In
./configurescripts (from autotools), you use the--enable-staticflag. When building your program, you use the-staticflag. The static libraries are the ones with the.asuffixes; shared libraries use.so, sometimes with a version number suffix).PHP is not a library, it is a language (i.e. executable) which provides its own command-line interface. Your C++ executable can work similarly, you just have to get the input from
cin(in<iostream>) and write results tocout, usingcerrfor error messages.Your title question, “How to make a library in c++ in linux” (as opposed to using a library): You use the
arprogram to link several.ofiles into a single.alibrary file. You can also useranlibto clean up the.afile. Read themanpages for those commands to see how they are used.