Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there an intelligent way to know the name of the library to link to at compile time? (Linux/Kubuntu)
    primarykey
    data
    text
    <p>Please bear with me. I really want to know as I am curious about the answer:</p> <p>Is there an intelligent way to know the name of the library to link to at compile time?</p> <p>Allow me to give you an example that illustrates perfectly the reason for my question.</p> <p>I am a C++ newbie. I am learning about compiling, linking and libraries like boost. I just discovered boost/filesystem and wanted to try it. Having had troubles compiling, I used the following minimalist code:</p> <p><pre><code> // file boost_example.cpp #include "boost/filesystem.hpp"<br> #include &lt;iostream&gt;</p> <p>int main() { std::cout&lt;&lt;"Hello"; return 0; } </pre></code></p> <p>I tried to compile it, but being a newbie, I made a newbie mistake: I forgot to link to the proper library!<br> <code><pre> g++ boost_example.cpp -o run</pre></code><br> To be precise, I experienced the problem explained in <a href="http://www.network-theory.co.uk/docs/gccintro/gccintro_17.html" rel="noreferrer">this chapter of this fine book</a>.<br> I knew I had boost installed (I was told to install it to compile another project). I tried to copy from the Makefile of that other project, but the following didn't work:<br> <code><pre> g++ boost_example.cpp -o run -lbooster</pre></code> <code><pre> g++ boost_example.cpp -o run -lboost</pre></code> Trying to make an educated guess from the #include line in the code, I tried the following to no avail: <code><pre> g++ boost_example.cpp -o run -lboost_filesystem</pre></code> By that time, I had started to search the web frantically. I hate search engines because most of the time, you don't find what you're looking. I found the following but they didn't help but to waste my time:<br> <a href="http://ubuntuforums.org/showthread.php?t=244593" rel="noreferrer">Boost library link problem under kubuntu</a><br> <a href="http://ubuntuforums.org/showthread.php?t=897996" rel="noreferrer">C++/Boost linker errors</a> </p> <p>Since I am a RTFM kind of guy, I had actually checked the official documentation for the library I wanted to use: <a href="http://www.boost.org/doc/libs/1_43_0/libs/filesystem/doc/index.htm" rel="noreferrer">http://www.boost.org/doc/libs/1_43_0/libs/filesystem/doc/index.htm</a> but I didn't find any compile information. </p> <p>At some stage, I got inspired to check what I had actually installed on my system: <code><pre> $ locate boost_file /usr/lib/libboost_filesystem-mt.a /usr/lib/libboost_filesystem-mt.so /usr/lib/libboost_filesystem-mt.so.1.38.0 </pre></code> Thus, I found the proper name of the library to link. The following worked:<br> <code><pre> g++ boost_example.cpp -o run -lboost_filesystem-mt</pre></code> </p> <p>Now, beside using (possibly) intelligent guess work and searching the web, is there a more intelligent way to find the name of the library to link to? I would never have guessed the library name <code>boost_filesystem-mt</code> given the header <code>"boost/filesystem.hpp"</code>. </p> <p>What's worse: <a href="http://www.google.com/search?hl=en&amp;q=site:http://www.boost.org/+%22boost_filesystem-mt%22" rel="noreferrer">boost_filesystem-mt is not mentioned anywhere</a> on the official site! (I'm guessing it's distro/packaging dependent).</p> <p>Again, I always make a point of RTFM before asking a question, and I found <a href="http://www.network-theory.co.uk/docs/gccintro/gccintro_21.html" rel="noreferrer">this chapter of the aforementioned book</a>, so I checked what I could find on my system at /usr/lib/:<br> <code><pre> $ ls /usr/lib/<em>boost</em> /usr/lib/libboost_date_time-mt.a /usr/lib/libboost_prg_exec_monitor-mt.so.1.38.0 /usr/lib/libboost_date_time-mt.so /usr/lib/libboost_program_options-mt.a /usr/lib/libboost_date_time-mt.so.1.38.0 /usr/lib/libboost_program_options-mt.so /usr/lib/libbooster.a /usr/lib/libboost_program_options-mt.so.1.38.0 /usr/lib/libbooster.so /usr/lib/libboost_python-mt.a /usr/lib/libbooster.so.0 /usr/lib/libboost_python-mt-py25.a /usr/lib/libbooster.so.0.0.0 /usr/lib/libboost_python-mt-py25.so /usr/lib/libboost_filesystem-mt.a /usr/lib/libboost_python-mt-py25.so.1.38.0 /usr/lib/libboost_filesystem-mt.so /usr/lib/libboost_python-mt-py26.a /usr/lib/libboost_filesystem-mt.so.1.38.0 /usr/lib/libboost_python-mt-py26.so /usr/lib/libboost_graph-mt.a /usr/lib/libboost_python-mt-py26.so.1.38.0 /usr/lib/libboost_graph-mt.so /usr/lib/libboost_python-mt.so /usr/lib/libboost_graph-mt.so.1.38.0 /usr/lib/libboost_regex-mt.a /usr/lib/libboost_iostreams-mt.a /usr/lib/libboost_regex-mt.so /usr/lib/libboost_iostreams-mt.so /usr/lib/libboost_regex-mt.so.1.38.0 /usr/lib/libboost_iostreams-mt.so.1.38.0 /usr/lib/libboost_serialization-mt.a /usr/lib/libboost_math_c99f-mt.a /usr/lib/libboost_serialization-mt.so /usr/lib/libboost_math_c99f-mt.so /usr/lib/libboost_serialization-mt.so.1.38.0 /usr/lib/libboost_math_c99f-mt.so.1.38.0 /usr/lib/libboost_signals-mt.a /usr/lib/libboost_math_c99l-mt.a /usr/lib/libboost_signals-mt.so /usr/lib/libboost_math_c99l-mt.so /usr/lib/libboost_signals-mt.so.1.38.0 /usr/lib/libboost_math_c99l-mt.so.1.38.0 /usr/lib/libboost_system-mt.a /usr/lib/libboost_math_c99-mt.a /usr/lib/libboost_system-mt.so /usr/lib/libboost_math_c99-mt.so /usr/lib/libboost_system-mt.so.1.38.0 /usr/lib/libboost_math_c99-mt.so.1.38.0 /usr/lib/libboost_thread-mt.a /usr/lib/libboost_math_tr1f-mt.a /usr/lib/libboost_thread-mt.so /usr/lib/libboost_math_tr1f-mt.so /usr/lib/libboost_thread-mt.so.1.38.0 /usr/lib/libboost_math_tr1f-mt.so.1.38.0 /usr/lib/libboost_unit_test_framework-mt.a /usr/lib/libboost_math_tr1l-mt.a /usr/lib/libboost_unit_test_framework-mt.so /usr/lib/libboost_math_tr1l-mt.so /usr/lib/libboost_unit_test_framework-mt.so.1.38.0 /usr/lib/libboost_math_tr1l-mt.so.1.38.0 /usr/lib/libboost_wave-mt.a /usr/lib/libboost_math_tr1-mt.a /usr/lib/libboost_wave-mt.so /usr/lib/libboost_math_tr1-mt.so /usr/lib/libboost_wave-mt.so.1.38.0 /usr/lib/libboost_math_tr1-mt.so.1.38.0 /usr/lib/libboost_wserialization-mt.a /usr/lib/libboost_prg_exec_monitor-mt.a /usr/lib/libboost_wserialization-mt.so /usr/lib/libboost_prg_exec_monitor-mt.so /usr/lib/libboost_wserialization-mt.so.1.38.0 </pre></code></p> <p>And now I am scratching my head very hard, because I really don't know how to correlate the above to the <a href="http://www.boost.org/doc/libs/" rel="noreferrer">list of boost libraries</a>.</p> <p>I apologize for this long-winded example, but it perfectly illustrate my problem: </p> <p><strong>Beside guesswork, searching the web, asking other people, trial and error, etc... is there a more intelligent way to find the name of the library one should link to?</strong> Aren't those kind of things supposed to be documented somewhere?</p> <p>I'm certainly interested in knowing the answer as far as boost is concerned, but my question is more generic and is applicable to any library.</p> <p>Incidentally, I have a very similar question regarding the name of linux packages (be they .deb or .rpm). If I am told that to compile such or such software I need, say, PRCE or FooBar, how do I know precisely the name of the package to install? I know how to user apt-cache (for Kubuntu debs) but some package naming are not intuitive and I often end up installing packages I don't really need...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload