(I'm aware similar questions have been posted several times here, but I'm posting a new one precisely because the proposed solutions do not seem to work in my case!)
So, I'm trying to compile a pretty simple program that makes use of boost::program_options. My boost library is installed at /usr/lib/. If I type ls /usr/lib/ | grep program_options
, I get the following :
libboost_program_options-mt.a
libboost_program_options-mt.so
libboost_program_options.a
libboost_program_options.so
libboost_program_options.so.1.46.1
So the lib is there. Yet when I try to compile by doing g++ -L/usr/lib/ -lboost_program_options main.cpp
, I get a whole lot of "undefined reference to ... " errors (I don't think it's useful to c/c it here).
If I type ld -lboost_program_options --verbose
, I get this :
attempt to open /usr/x86_64-linux-gnu/lib64/libboost_program_options.so failed
attempt to open /usr/x86_64-linux-gnu/lib64/libboost_program_options.a failed
attempt to open /usr/local/lib/x86_64-linux-gnu/libboost_program_options.so failed
attempt to open /usr/local/lib/x86_64-linux-gnu/libboost_program_options.a failed
attempt to open /usr/local/lib64/libboost_program_options.so failed
attempt to open /usr/local/lib64/libboost_program_options.a failed
attempt to open /lib/x86_64-linux-gnu/libboost_program_options.so failed
attempt to open /lib/x86_64-linux-gnu/libboost_program_options.a failed
attempt to open /lib64/libboost_program_options.so failed
attempt to open /lib64/libboost_program_options.a failed
attempt to open /usr/lib/x86_64-linux-gnu/libboost_program_options.so failed
attempt to open /usr/lib/x86_64-linux-gnu/libboost_program_options.a failed
attempt to open /usr/lib64/libboost_program_options.so failed
attempt to open /usr/lib64/libboost_program_options.a failed
attempt to open /usr/local/lib/libboost_program_options.so failed
attempt to open /usr/local/lib/libboost_program_options.a failed
attempt to open /lib/libboost_program_options.so failed
attempt to open /lib/libboost_program_options.a failed
attempt to open /usr/lib/libboost_program_options.so succeeded
-lboost_program_options (/usr/lib/libboost_program_options.so)
libstdc++.so.6 needed by /usr/lib/libboost_program_options.so
found libstdc++.so.6 at /usr/lib/x86_64-linux-gnu/libstdc++.so.6
libgcc_s.so.1 needed by /usr/lib/libboost_program_options.so
found libgcc_s.so.1 at /lib/x86_64-linux-gnu/libgcc_s.so.1
libpthread.so.0 needed by /usr/lib/libboost_program_options.so
found libpthread.so.0 at /lib/x86_64-linux-gnu/libpthread.so.0
libc.so.6 needed by /usr/lib/libboost_program_options.so
found libc.so.6 at /lib/x86_64-linux-gnu/libc.so.6
libm.so.6 needed by /usr/lib/x86_64-linux-gnu/libstdc++.so.6
found libm.so.6 at /lib/x86_64-linux-gnu/libm.so.6
ld-linux-x86-64.so.2 needed by /usr/lib/x86_64-linux-gnu/libstdc++.so.6
found ld-linux-x86-64.so.2 at /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
ld: warning: cannot find entry symbol _start; not setting start address
So it actually finds the lib (after looking in many different places), but something weird messes everything up at the end.
Any idea?
Edit: Here are the "undefined reference ..." errors :
main.cpp:(.text+0x29): undefined reference to `boost::program_options::options_description::m_default_line_length'
main.cpp:(.text+0x35): undefined reference to `boost::program_options::options_description::m_default_line_length'
main.cpp:(.text+0x6e): undefined reference to `boost::program_options::options_description::options_description(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int)'
main.cpp:(.text+0xa4): undefined reference to `boost::program_options::options_description::add_options()'
main.cpp:(.text+0xbe): undefined reference to `boost::program_options::options_description_easy_init::operator()(char const*, char const*)'
main.cpp:(.text+0xd3): undefined reference to `boost::program_options::options_description_easy_init::operator()(char const*, boost::program_options::value_semantic const*, char const*)'
main.cpp:(.text+0xe2): undefined reference to `boost::program_options::variables_map::variables_map()'
main.cpp:(.text+0x13c): undefined reference to `boost::program_options::store(boost::program_options::basic_parsed_options<char> const&, boost::program_options::variables_map&, bool)'
And for the sake of completion, the short bit of code involving boost :
options_description desc("Allowed options");
desc.add_options()
("help,h","Display help")
("file,f",value<string>(&dataFile),"Path to the file containing the data");
variables_map vm;
store(parse_command_line(argc, argv, desc), vm);
With of course #include <boost/program_options.hpp>
at the beginning of the file.