/usr/bin/ld:找不到-llibboost P> >现在我正尝试使用Linux中的Boost C++库(Ubuntu 12.04),因为我以前在Windows中使用过它们。因此,使用Boost网站上的一些示例代码
testfile.cpp/usr/bin/ld:找不到-llibboost P> >现在我正尝试使用Linux中的Boost C++库(Ubuntu 12.04),因为我以前在Windows中使用过它们。因此,使用Boost网站上的一些示例代码,c++,ubuntu,boost,ubuntu-12.04,C++,Ubuntu,Boost,Ubuntu 12.04,testfile.cpp #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 pat
#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;
}
我的问题我得到链接器错误
/usr/bin/ld: cannot find -llibboost_filesystem
似乎无法理解我错过了什么。请提供帮助。按照惯例,大多数Linux发行版上的库名称都使用
lib
前缀。指示链接器搜索哪些库时,应删除此前缀。假设gnuld
链接器,文档中说
-l namespec
--library=namespec
Add the archive or object file specified by namespec to the list of files to
link. This option may be used any number of times. If namespec is of the
form :filename, ld will search the library path for a file called filename,
otherwise it will search the library path for a file called libnamespec.a.
所以你要么想要
g++ -L/usr/local/lib -o "testfile" -lboost_filesystem
或
这不应该是
-lboost\u文件系统?是的,你说得对。我没有意识到文件之间的命名约定在那里发生了变化。感谢可能的副本
g++ -L/usr/local/lib -o "testfile" -lboost_filesystem
g++ -L/usr/local/lib -o "testfile" -l :libboost_filesystem.so