Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > traverse directory with boost

Reply
Thread Tools

traverse directory with boost

 
 
Gary Wessle
Guest
Posts: n/a
 
      08-06-2006
hi
I did not find any way to traverse a given directory in c++ till I
found boost, not sure if there many boost(ers) out here. but this is
given me some error I cannot locate a fix.

thanks

**************** code ****************
#include <iostream>
#include <string>
#include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp
#include "boost/filesystem/fstream.hpp"
namespace fs = boost::filesystem;

using namespace std;

int main(){

fs:ath full_path("../data");
if (exists(full_path)) cout << "yes" << endl;

}
//there exists data directory in the parent of the current directory.

**************** error ****************
$ make
g++ -gdwarf-2 -c -o try.o try.cpp
g++ -Wall -gdwarf-2 -o proj try.o
try.o: In function `main':
/home/fred/myPrograms/backtest/try/try.cpp:11: undefined reference to `boost::filesystem:ath:ath(char const*)'
/home/fred/myPrograms/backtest/try/try.cpp:12: undefined reference to `boost::filesystem::exists(boost::filesystem:ath const&)'
collect2: ld returned 1 exit status
make: *** [proj] Error 1
 
Reply With Quote
 
 
 
 
Alex Buell
Guest
Posts: n/a
 
      08-06-2006
On 06 Aug 2006 13:37:20 +1000, I waved a wand and this message
magically appeared from Gary Wessle:

> $ make
> g++ -gdwarf-2 -c -o try.o try.cpp
> g++ -Wall -gdwarf-2 -o proj try.o
> try.o: In function `main':
> /home/fred/myPrograms/backtest/try/try.cpp:11: undefined reference to
> `boost::filesystem:ath:ath(char
> const*)' /home/fred/myPrograms/backtest/try/try.cpp:12: undefined
> reference to `boost::filesystem::exists(boost::filesystem:ath
> const&)' collect2: ld returned 1 exit status make: *** [proj] Error 1


you need:

g++ -Wall -gdwarf2 -o proj try.o -lboost_filesystem

(i.e. you aren't linking against the boost library)
--
http://www.munted.org.uk

Take a nap, it saves lives.
 
Reply With Quote
 
 
 
 
Gary Wessle
Guest
Posts: n/a
 
      08-06-2006
Alex Buell <(E-Mail Removed)> writes:

> On 06 Aug 2006 13:37:20 +1000, I waved a wand and this message
> magically appeared from Gary Wessle:
>
> > $ make
> > g++ -gdwarf-2 -c -o try.o try.cpp
> > g++ -Wall -gdwarf-2 -o proj try.o
> > try.o: In function `main':
> > /home/fred/myPrograms/backtest/try/try.cpp:11: undefined reference to
> > `boost::filesystem:ath:ath(char
> > const*)' /home/fred/myPrograms/backtest/try/try.cpp:12: undefined
> > reference to `boost::filesystem::exists(boost::filesystem:ath
> > const&)' collect2: ld returned 1 exit status make: *** [proj] Error 1

>
> you need:
>
> g++ -Wall -gdwarf2 -o proj try.o -lboost_filesystem
>
> (i.e. you aren't linking against the boost library)


why is it then that I was able to run this without linking against the
boost library


************************************************** **************
#include <iostream>
using std::cout;
using std::endl;
#include<string>
using std::string;
#include <vector>
using std::vector;
#include "boost/format.hpp"
using boost::format;

int main(){
string s("abcde");
vector<char> v (s.begin(), s.end());
format fmter("%1% %3t%2%");
fmter % v[0];
fmter % v[1];
cout << fmter.str() << '\n';
}

no linking against the boost library here
**************** **************** ****************
CXXFLAGS = -gdwarf-2
OBJS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))
COMP = g++

proj: $(OBJS)
$(COMP) -Wall -gdwarf-2 -o proj $(OBJS)

#-Wall turns on all warnings
#-gdwarf-2 for dubugging note gdb manual 12.4.1
clean:
rm -rf *.o proj



 
Reply With Quote
 
Gary Wessle
Guest
Posts: n/a
 
      08-06-2006
I did not post the output in my last post, here it is

$ make clean; make
rm -rf *.o proj
g++ -gdwarf-2 -c -o try.o try.cpp
g++ -Wall -gdwarf-2 -o proj try.o
$
 
Reply With Quote
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      08-06-2006
Gary Wessle wrote:

> Alex Buell <(E-Mail Removed)> writes:
>
>> On 06 Aug 2006 13:37:20 +1000, I waved a wand and this message
>> magically appeared from Gary Wessle:
>>
>> > $ make
>> > g++ -gdwarf-2 -c -o try.o try.cpp
>> > g++ -Wall -gdwarf-2 -o proj try.o
>> > try.o: In function `main':
>> > /home/fred/myPrograms/backtest/try/try.cpp:11: undefined reference to
>> > `boost::filesystem:ath:ath(char
>> > const*)' /home/fred/myPrograms/backtest/try/try.cpp:12: undefined
>> > reference to `boost::filesystem::exists(boost::filesystem:ath
>> > const&)' collect2: ld returned 1 exit status make: *** [proj] Error 1

>>
>> you need:
>>
>> g++ -Wall -gdwarf2 -o proj try.o -lboost_filesystem
>>
>> (i.e. you aren't linking against the boost library)

>
> why is it then that I was able to run this without linking against the
> boost library


There are several boost libraries.

>
> ************************************************** **************
> #include <iostream>
> using std::cout;
> using std::endl;
> #include<string>
> using std::string;
> #include <vector>
> using std::vector;
> #include "boost/format.hpp"
> using boost::format;
>
> int main(){
> string s("abcde");
> vector<char> v (s.begin(), s.end());
> format fmter("%1% %3t%2%");
> fmter % v[0];
> fmter % v[1];
> cout << fmter.str() << '\n';
> }
>
> no linking against the boost library here
> **************** **************** ****************
> CXXFLAGS = -gdwarf-2
> OBJS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))
> COMP = g++
>
> proj: $(OBJS)
> $(COMP) -Wall -gdwarf-2 -o proj $(OBJS)
>
> #-Wall turns on all warnings
> #-gdwarf-2 for dubugging note gdb manual 12.4.1
> clean:
> rm -rf *.o proj


Different code, different requirements. Read the documentation for the
libraries you are using. They will tell you what to tell the linker.


Best

Kai-Uwe Bux
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
noob question:traverse directory and populate mysql db jay Ruby 0 02-01-2007 09:52 AM
How to Traverse a Directory Newbie Ruby 6 09-21-2006 05:07 PM
Traverse a directory weberw@adelphia.net Perl Misc 11 07-15-2006 04:10 PM
glob and Traverse Directory weberw@adelphia.net Perl Misc 7 07-15-2006 02:49 AM
traverse a directory and subdirectories to find files ' properties Thieum22 Perl 1 08-06-2004 08:01 PM



Advertisments