# Need boost::filesystem help.

## Recommended Posts

I'm doing something wrong here, trying that two-minute tutorial. But it gives me these errors when I try to compile:
/tmp/cchpZIv3.o: In function main':
main.cpp:(.text+0x93): undefined reference to boost::filesystem::path::path(char const*)'
collect2: ld returned 1 exit status


Here's my code file:
#include <boost/filesystem.hpp>

#include <iostream>
#include <string>

using namespace boost::filesystem;

int main(int argv,char* args[]){
path p("main.cpp");

return 0;
}


Here's the line I use to compile(if it's needed): g++ -o fst main.cpp If I don't try to declare p it compiles just fine.

##### Share on other sites
boost::filesystem needs more than just the headers for most of its functionality. You need to build the boost library with bjam and link against the filesystem library file. There are instructions for the build steps here.

##### Share on other sites

Quote:
 root@lappy:/usr/local/boost_1_34_0# ./configureBuilding Boost.Jam with toolset gcc... tools/jam/src/bin.linuxx86/bjamDetecting Python version... 2.5Detecting Python root... /usrUnicode/ICU support for Boost.Regex?... /usrBacking up existing Boost.Build configuration in user-config.jam.5Generating Boost.Build configuration in user-config.jam...Generating Makefile...root@lappy:/usr/local/boost_1_34_0# make install./tools/jam/src/bin.linuxx86/bjam -sICU_PATH=/usr --user-config=user-config.jam --prefix=/usr/local --exec-prefix=/usr/local --libdir=/usr/local/lib --includedir=/usr/local/include installJamfile.v2:341: in load-auxrule path.glob-tree unknown in module Jamfile./usr/share/boost-build/build/project.jam:318: in load-jamfile/usr/share/boost-build/build/project.jam:68: in load/usr/share/boost-build/build/project.jam:170: in project.find/usr/share/boost-build/build-system.jam:148: in load/usr/share/boost-build/kernel/modules.jam:261: in import/usr/share/boost-build/kernel/bootstrap.jam:132: in boost-build/usr/local/boost_1_34_0/boost-build.jam:9: in module scopeNot all Boost libraries built properly.root@lappy:/usr/local/boost_1_34_0#

it said it puts the libs in the "lib" directory, so i ls'd and there was no "lib" directory. so i tried the next method with bjam:
Quote:
 root@lappy:/usr/local/boost_1_34_0# bjam --build-dir=/tmp/build-boost --toolset=gcc stageJamfile.v2:341: in load-auxrule path.glob-tree unknown in module Jamfile./usr/share/boost-build/build/project.jam:318: in load-jamfile/usr/share/boost-build/build/project.jam:68: in load/usr/share/boost-build/build/project.jam:170: in project.find/usr/share/boost-build/build-system.jam:148: in load/usr/share/boost-build/kernel/modules.jam:261: in import/usr/share/boost-build/kernel/bootstrap.jam:132: in boost-build/usr/local/boost_1_34_0/boost-build.jam:9: in module scope

and nothing was built again :[

luckily i checked in synaptic and i already had "libboost-filesystem-dev" installed (although it's 1.33.1-9). so i added "-lboost_filesystem" to my compile line, and it works now. if it works then that's good, but i'm wondering if there's any features in 1.34 that make it absolutely necessary to upgrade. i'd like to upgrade, but i don't want to wrestle with it for 3 hours trying to get it to work...

##### Share on other sites
okay i tried again, this time when i did "make install" it actually made files, it gave me this when it finished:
Quote:
 ...failed updating 224 targets......skipped 64 targets......updated 5525 targets...Not all Boost libraries built properly.

i looked in /usr/local/include (where it said it would put it) and there were actually files there. problem was that they're in "/usr/local/include/boost-1_34/boost" and not "/usr/local/include/boost" luckily i just copied the boost folder to one directory above and it worked.

next problem is linking libraries. when i try to compile via command line it looked something like this "g++ main.cpp -o fst2 -lboost_filesystem-gcc41" (i also tried adding the .a at the end of the lib name). it tells me:
Quote:
 ./fst2: error while loading shared libraries: libboost_filesystem-gcc41-1_34.so.1.34.0: cannot open shared object file: No such file or directory

i tried using gcc and c++ instead of g++, same error. i looked and the file does in fact exist.

it works with code::blocks, and i'm using gcc as my compiler with that.

i guess my question now is how would i compile a program using boost::filesystem with a terminal command?

##### Share on other sites
If you can't get the bjam libraries to work, you can generally get away with just adding the source files for the boost libraries to your project. For boost::filesystem, the source files are in libs/filesystem/src subdirectory of the boost install. You may need to tweak some headers like boost/config/user.hpp.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627708
• Total Posts
2978730

• 21
• 14
• 12
• 22
• 35