473,382 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

traverse directory with boost

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::path 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::path::path(char const*)'
/home/fred/myPrograms/backtest/try/try.cpp:12: undefined reference to `boost::filesystem::exists(boost::filesystem::path const&)'
collect2: ld returned 1 exit status
make: *** [proj] Error 1
Aug 6 '06 #1
4 5231
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::path::path(char
const*)' /home/fred/myPrograms/backtest/try/try.cpp:12: undefined
reference to `boost::filesystem::exists(boost::filesystem::path
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.
Aug 6 '06 #2
Alex Buell <al********@munted.org.ukwrites:
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::path::path(char
const*)' /home/fred/myPrograms/backtest/try/try.cpp:12: undefined
reference to `boost::filesystem::exists(boost::filesystem::path
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<charv (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

Aug 6 '06 #3
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
$
Aug 6 '06 #4
Gary Wessle wrote:
Alex Buell <al********@munted.org.ukwrites:
>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::path::path(char
const*)' /home/fred/myPrograms/backtest/try/try.cpp:12: undefined
reference to `boost::filesystem::exists(boost::filesystem::path
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<charv (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
Aug 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python suppose you want to walk into a directory, say, to apply a string replacement to all html files. The os.path.walk() rises for the occasion. © import os ©...
1
by: Thieum22 | last post by:
Hi, I try to go through a directory and it's subdirectories to reah the properties of each files. But I have a problem to set active the directory where the files are, in order to display their...
5
by: perseus | last post by:
Well, As you all have seen, I received a host of messages that say that I should not post up here a question about BOOST. BOOST is a FREE interface that allows you, THE STANDARD C++ USERS, to...
2
by: Peng Yu | last post by:
Could you give some examples about how to write a file in a non local directory? And what if the directory is not exist, do I have to create one? Thanks, Peng
16
by: Torsten Mueller | last post by:
I have to port a program from Windows to HPUX. It has an algorithm iterating over files of a directory and all of it's subdirectories using _findfirst() and _findnext() on a structure called...
6
by: Sigmathaar | last post by:
Hi, while making an XML parser for the creation of an entire directory list I got this problem and I'm having trouble solving it. The program (not yet written) goes through an XML Schema Instance...
5
by: johnwayne83 | last post by:
This is my first semester in c++ and i took java last semester. I need some help and i really cant find any information that has helped me or to point me in the right direction. I am using...
5
by: darren | last post by:
Hello In a program i'm writing, I need to be able to serve files from a specified directory. I don't want to reinvent the wheel by writing a class that provides basic directory a file...
8
by: aki | last post by:
Hi All, I describe the problem as below. A directory( path known) , contains 0 to any number of files . The file names are with following structure : ...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.