473,396 Members | 1,998 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,396 software developers and data experts.

Compiling c++ programs with Boost-library on Ubuntu

Hello out there :-)

I'm new to c++, coming from Java, and trying to learn the basics of the
language and all that, basically just for fun. :-)

So, when once I played around with c++ a bit i found out I didn't
really have any ways of looking at directories.
So, I looked around and found the boost library, which seems pretty
cool. However, I seem to be unable to compile anything using these
libraries.

For instance, the following example program from the boost site:
http://www.boost.org/libs/filesystem.../simple_ls.cpp
when compiled by me:
>g++ simple_ls.cpp -o simple_ls
produces the following error:
(WARNING! Large snippet coming up!)

soren@soren-laptop:~$ g++ simple_ls.cpp -o simple_ls
/tmp/ccDxvNVJ.o: In function `main':
simple_ls.cpp:(.text+0x89): undefined reference to
`boost::filesystem::initial_path()'
simple_ls.cpp:(.text+0xb7): undefined reference to
`boost::filesystem::native(std::basic_string<char,
std::char_traits<char>, std::allocator<char const&)'
simple_ls.cpp:(.text+0xc6): undefined reference to
`boost::filesystem::path::path(char const*, bool
(*)(std::basic_string<char, std::char_traits<char>,
std::allocator<char const&))'
simple_ls.cpp:(.text+0xd8): undefined reference to
`boost::filesystem::system_complete(boost::filesys tem::path const&)'
simple_ls.cpp:(.text+0x17a): undefined reference to
`boost::filesystem::exists(boost::filesystem::path const&)'
simple_ls.cpp:(.text+0x193): undefined reference to
`boost::filesystem::path::native_file_string() const'
simple_ls.cpp:(.text+0x208): undefined reference to
`boost::filesystem::is_directory(boost::filesystem ::path const&)'
simple_ls.cpp:(.text+0x222): undefined reference to
`boost::filesystem::path::native_directory_string( ) const'
simple_ls.cpp:(.text+0x2b5): undefined reference to
`boost::filesystem::is_directory(boost::filesystem ::path const&)'
simple_ls.cpp:(.text+0x2d7): undefined reference to
`boost::filesystem::path::leaf() const'
simple_ls.cpp:(.text+0x34a): undefined reference to
`boost::filesystem::path::leaf() const'
simple_ls.cpp:(.text+0x3f1): undefined reference to
`boost::filesystem::path::leaf() const'
simple_ls.cpp:(.text+0x56a): undefined reference to
`boost::filesystem::path::native_file_string() const'
/tmp/ccDxvNVJ.o: In function
`boost::filesystem::directory_iterator::directory_ iterator(boost::filesystem::path
const&)':
simple_ls.cpp:(.text._ZN5boost10filesystem18direct ory_iteratorC1ERKNS0_4pathE[boost::filesystem::directory_iterator::directory_i terator(boost::filesystem::path
const&)]+0x2b): undefined reference to
`boost::filesystem::detail::dir_itr_init(boost::sh ared_ptr<boost::filesystem::detail::dir_itr_imp>&,
boost::filesystem::path const&)'
/tmp/ccDxvNVJ.o: In function
`boost::filesystem::directory_iterator::dereferenc e() const':
simple_ls.cpp:(.text._ZNK5boost10filesystem18direc tory_iterator11dereferenceEv[boost::filesystem::directory_iterator::dereference ()
const]+0xd): undefined reference to
`boost::filesystem::detail::dir_itr_dereference(bo ost::shared_ptr<boost::filesystem::detail::dir_itr _imp>
const&)'
/tmp/ccDxvNVJ.o: In function
`boost::filesystem::directory_iterator::increment( )':
simple_ls.cpp:(.text._ZN5boost10filesystem18direct ory_iterator9incrementEv[boost::filesystem::directory_iterator::increment()]+0xd):
undefined reference to
`boost::filesystem::detail::dir_itr_increment(boos t::shared_ptr<boost::filesystem::detail::dir_itr_i mp>&)'
collect2: ld returned 1 exit status

I asked around a bit, and was told I didn't link the boost-libs
correctly, and to use something like:
>g++ simple_ls.cpp -o simple_ls -lboost/filesystem
but that produces:
soren@soren-laptop:~$ g++ simple_ls.cpp -o simple_ls -lboost/filesystem
/usr/bin/ld: cannot find -lboost/filesystem
collect2: ld returned 1 exit status

Basically, not only do I know why this fails - or why I need it :-D -
nor do I know how to about fixing it :-)

Are there any nice tutorials out there dealing with this sort of thing
that I've been unable to find?

Thx in advance,

/Søren

Nov 29 '06 #1
2 8760
so************@gmail.com wrote:
I asked around a bit, and was told I didn't link the boost-libs
correctly, and to use something like:
>>g++ simple_ls.cpp -o simple_ls -lboost/filesystem
but that produces:
soren@soren-laptop:~$ g++ simple_ls.cpp -o simple_ls -lboost/filesystem
/usr/bin/ld: cannot find -lboost/filesystem
collect2: ld returned 1 exit status

Basically, not only do I know why this fails
Try -lboost_filesystem
- or why I need it :-D -
Because you need to link against the boost_filesystem library.
nor do I know how to about fixing it :-)
have a look into /usr/lib/ and search for somethig with a name that starts
with libboost_filesystem. Remove the '.so' part at the end and the 'lib' at
the start, and you have what needs to follow the -l.
Are there any nice tutorials out there dealing with this sort of thing
that I've been unable to find?
I'd expect the boost documentation itself to contain something about that.
Nov 29 '06 #2

<so************@gmail.comschrieb im Newsbeitrag
news:11**********************@j44g2000cwa.googlegr oups.com...
Hello out there :-)

I'm new to c++, coming from Java, and trying to learn the basics of the
language and all that, basically just for fun. :-)

So, when once I played around with c++ a bit i found out I didn't
really have any ways of looking at directories.
So, I looked around and found the boost library, which seems pretty
cool. However, I seem to be unable to compile anything using these
libraries.

seems to me that u forgot to download and include some files while compiling
i use a ide with project support, don't know nothing about makefiles, so
creating a project and adding files - especially those included in " " - and
perhaps some libs - also look up the dependencies in .hpp - should help.
i have the same problems this antique behavior of c++ is verry confusing to
me.
Nov 29 '06 #3

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

Similar topics

0
by: Nikola Milutinovic | last post by:
Hi all. I'm not subscribed to the list, so all replies to me mail directly. I ran into a small problem, for which we have found a workaround. I was compiling PostgreSQL v7.4.1 and it's...
5
by: Lars Schouw | last post by:
I have downloaded the newest boos release. I am havng problems building boost using the intel C++ 8.0 compiler. It looks as if bjam can't fine the icl.exe compiler executable itself. This file is...
11
by: Carramba | last post by:
hi! thanx for taking time to read my post. code #include <stdio.h> int main() { printf("Hello word!"); return 0; }//END when Iam compiling code with gcc I can't start program in winXP by
6
by: Raja Cherukuri | last post by:
Hi, I am using Boost and VC 7.1 compiler has started complaining about out of heap space with C1060 after it crossed a certain size. No amount of "Zm" option changes work. Saw that there is a...
19
by: Simon Faulkner | last post by:
Pardon me if this has been done to death but I can't find a simple explanation. I love Python for it's ease and speed of development especially for the "Programming Challenged" like me but why...
4
by: Gary Wessle | last post by:
Hi I have been trying to find out the reason for this error for an 1hr, please look at it for me. thanks **************** error **************** $ make; ./proj g++ -gdwarf-2 -c -o...
2
by: sterten | last post by:
I often see scientific programs for Linux written in C which come with several files, are "zipped" with gzip and packked as .tar , they contain a "makefile" and several instructions (and...
1
by: Noah Roberts | last post by:
Trying to use boost::function in a C++/CLI program. Here is code: pragma once #include <boost/function.hpp> #include <boost/shared_ptr.hpp> #include <vector> using namespace System;
10
by: Tomás Ó hÉilidhe | last post by:
I'd post this on a gcc newsgroup but I'd be more productive talking to the wall. Anyway, let's say someone throws some source code at you for a particular program and says, "Just compile it, it...
4
by: anon538 | last post by:
I have been interested in switching from Java to C# for a long time now. I typically write small, stand alone programs for contests. Each program is completely self contained. I am used to, in...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.