Boost linking fail
Solution 1
from gcc man page:
-Ldir Add directory dir to the list of directories to be searched for -l.
So, is it that you are missing -L/home/foo/lib
to the command line?
Your code compiled properly on my linux machine (Ubuntu 10.04, boost-filesystem 1.40) with the following command:
g++ test.cpp -lboost_filesystem
or
g++ test.cpp -lboost_system -lboost_filesystem
It gave me compile errors with g++ test.cpp -lboost_system
Solution 2
You must tell the compiler/linker where your libraries are as well, if they are not in the default location. For this you must use the -L
flag to the compiler:
g++ -I/home/y/include/ test.cc -L/home/foo/lib -lboost_system -lboost_filesystem
Solution 3
Your boost libraries appear to be decorated with the suffix gcc34-1_38. Are you using gcc 3.4? Is your boost library on the library path? If not you may need to add the the path to your boost libraries using the -L
flag to g++ or you can add the path to the LD_LIBRARY_PATH
environment variable. In any case, you can link to your boost libraries by using -lboost_system-gcc34-1_38
and -lboost_filesystem-gcc34-1_38
.
Solution 4
Add -lboost_system
(-lboost_system-mt
if you're going to be threading) and -lboost_filesystem
(-lboost_filesystem-mt
if you're going to be threading) to the cmdline, before any input files.
DarthVader
Updated on June 20, 2022Comments
-
DarthVader almost 2 years
I have the following code which i m trying to compile:
#include <boost/filesystem/convenience.hpp> #include <boost/foreach.hpp> #include <boost/range.hpp> #include <iostream> int main(int, char**) { namespace bf = boost::filesystem; BOOST_FOREACH(bf::path path, boost::make_iterator_range( bf::recursive_directory_iterator(bf::path("/home")), bf::recursive_directory_iterator())) { std::cout << path.string() << std::endl; } return 0; }
My boost library is in /home/foo/include . and the include files are actually there.
when i run the following:
g++ -I/home/foo/include/ test.cc
I get the following error. how can i resolve this. what should i follow?
/tmp/ccvDmFNL.o(.text+0x502): In function `__static_initialization_and_destruction_0(int, int)': : undefined reference to `boost::system::get_system_category()' /tmp/ccvDmFNL.o(.text+0x51b): In function `__static_initialization_and_destruction_0(int, int)': : undefined reference to `boost::system::get_generic_category()' /tmp/ccvDmFNL.o(.text+0x534): In function `__static_initialization_and_destruction_0(int, int)': : undefined reference to `boost::system::get_generic_category()' /tmp/ccvDmFNL.o(.text+0x54d): In function `__static_initialization_and_destruction_0(int, int)': : undefined reference to `boost::system::get_generic_category()' /tmp/ccvDmFNL.o(.text+0x566): In function `__static_initialization_and_destruction_0(int, int)': : undefined reference to `boost::system::get_system_category()' /tmp/ccvDmFNL.o(.gnu.linkonce.t._ZN5boost10filesystem24basic_directory_iteratorINS0_10basic_pathISsNS0_11path_traitsEEEE6m_initERKS4_+0x2e): In function `boost::filesystem::basic_directory_iterator<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >::m_init(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)': : undefined reference to `boost::filesystem::detail::not_found_error()' /tmp/ccvDmFNL.o(.gnu.linkonce.t._ZN5boost10filesystem24basic_directory_iteratorINS0_10basic_pathISsNS0_11path_traitsEEEE6m_initERKS4_+0xbe): In function `boost::filesystem::basic_directory_iterator<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >::m_init(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)': : undefined reference to `boost::filesystem::detail::dir_itr_first(void*&, void*&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::filesystem::file_status&, boost::filesystem::file_status&)' /tmp/ccvDmFNL.o(.gnu.linkonce.t._ZN5boost6system10error_codeC1Ev+0x14): In function `boost::system::error_code::error_code()': : undefined reference to `boost::system::get_system_category()' /tmp/ccvDmFNL.o(.gnu.linkonce.t._ZN5boost10filesystem24basic_directory_iteratorINS0_10basic_pathISsNS0_11path_traitsEEEE9incrementEv+0xde): In function `boost::filesystem::basic_directory_iterator<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >::increment()': : undefined reference to `boost::filesystem::detail::dir_itr_increment(void*&, void*&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, boost::filesystem::file_status&, boost::filesystem::file_status&)' /tmp/ccvDmFNL.o(.gnu.linkonce.t._ZN5boost10filesystem6statusINS0_10basic_pathISsNS0_11path_traitsEEEEENS_9enable_ifINS0_13is_basic_pathIT_EENS0_11file_statusEE4typeERKS7_+0x34): In function `boost::enable_if<boost::filesystem::is_basic_path<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >, boost::filesystem::file_status>::type boost::filesystem::status<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >(boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> const&)': : undefined reference to `boost::filesystem::detail::status_api(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::system::error_code&)' /tmp/ccvDmFNL.o(.gnu.linkonce.t._ZN5boost10filesystem6detail11dir_itr_impINS0_10basic_pathISsNS0_11path_traitsEEEED1Ev+0x1d): In function `boost::filesystem::detail::dir_itr_imp<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >::~dir_itr_imp()': : undefined reference to `boost::filesystem::detail::dir_itr_close(void*&, void*&)' collect2: ld returned 1 exit status
EDIT:
Now i tried:
g++ -I/home/foo/include/ test.cc -lboost_system -lboost_filesystem
and get the following error:
/usr/bin/ld: cannot find -lboost_system collect2: ld returned 1 exit status
I have the libboost_system-gcc34-1_38.so within
/home/foo/lib
how can I point to that?