473,769 Members | 5,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::filesys tem::initial_pa th()'
simple_ls.cpp:( .text+0xb7): undefined reference to
`boost::filesys tem::native(std ::basic_string< char,
std::char_trait s<char>, std::allocator< char const&)'
simple_ls.cpp:( .text+0xc6): undefined reference to
`boost::filesys tem::path::path (char const*, bool
(*)(std::basic_ string<char, std::char_trait s<char>,
std::allocator< char const&))'
simple_ls.cpp:( .text+0xd8): undefined reference to
`boost::filesys tem::system_com plete(boost::fi lesystem::path const&)'
simple_ls.cpp:( .text+0x17a): undefined reference to
`boost::filesys tem::exists(boo st::filesystem: :path const&)'
simple_ls.cpp:( .text+0x193): undefined reference to
`boost::filesys tem::path::nati ve_file_string( ) const'
simple_ls.cpp:( .text+0x208): undefined reference to
`boost::filesys tem::is_directo ry(boost::files ystem::path const&)'
simple_ls.cpp:( .text+0x222): undefined reference to
`boost::filesys tem::path::nati ve_directory_st ring() const'
simple_ls.cpp:( .text+0x2b5): undefined reference to
`boost::filesys tem::is_directo ry(boost::files ystem::path const&)'
simple_ls.cpp:( .text+0x2d7): undefined reference to
`boost::filesys tem::path::leaf () const'
simple_ls.cpp:( .text+0x34a): undefined reference to
`boost::filesys tem::path::leaf () const'
simple_ls.cpp:( .text+0x3f1): undefined reference to
`boost::filesys tem::path::leaf () const'
simple_ls.cpp:( .text+0x56a): undefined reference to
`boost::filesys tem::path::nati ve_file_string( ) const'
/tmp/ccDxvNVJ.o: In function
`boost::filesys tem::directory_ iterator::direc tory_iterator(b oost::filesyste m::path
const&)':
simple_ls.cpp:( .text._ZN5boost 10filesystem18d irectory_iterat orC1ERKNS0_4pat hE[boost::filesyst em::directory_i terator::direct ory_iterator(bo ost::filesystem ::path
const&)]+0x2b): undefined reference to
`boost::filesys tem::detail::di r_itr_init(boos t::shared_ptr<b oost::filesyste m::detail::dir_ itr_imp>&,
boost::filesyst em::path const&)'
/tmp/ccDxvNVJ.o: In function
`boost::filesys tem::directory_ iterator::deref erence() const':
simple_ls.cpp:( .text._ZNK5boos t10filesystem18 directory_itera tor11dereferenc eEv[boost::filesyst em::directory_i terator::derefe rence()
const]+0xd): undefined reference to
`boost::filesys tem::detail::di r_itr_dereferen ce(boost::share d_ptr<boost::fi lesystem::detai l::dir_itr_imp>
const&)'
/tmp/ccDxvNVJ.o: In function
`boost::filesys tem::directory_ iterator::incre ment()':
simple_ls.cpp:( .text._ZN5boost 10filesystem18d irectory_iterat or9incrementEv[boost::filesyst em::directory_i terator::increm ent()]+0xd):
undefined reference to
`boost::filesys tem::detail::di r_itr_increment (boost::shared_ ptr<boost::file system::detail: :dir_itr_imp>&) '
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 8789
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_filesyst em
- or why I need it :-D -
Because you need to link against the boost_filesyste m 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_filesy stem. 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.comschri eb im Newsbeitrag
news:11******** **************@ j44g2000cwa.goo glegroups.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
1365
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 PL/Python module. Compilation failed on lines which had this: typedef struct PLyPlanObject { PyObject_HEAD; ... } PLyPlanObject;
5
3656
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 installed under this directory C:\Program Files\Intel\CPP\Compiler80\Ia32\Bin Any ideas what I do wrong? I try this: run the iclvars.bat batch file.
11
1520
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
1514
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 special fix for C++ compiler for in KB 837437 just for this problem. How can I download this ? Download support website doesn't have a clue about this fix ? Any help is greatly appreciated.
19
2193
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 hasn't someone written a compiler for Python? I guess it's not that simple eh? Simon
4
2116
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 gen_data.o gen_data.cpp
2
1785
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 incompatibilities for several compilers). In theory, you can create a Windows-executable but in practice this rarely works or requires too much time and energy.
1
5561
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
2210
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 works fine". Now admittedly, I tend to have a phobia of this situation because I recall from my Windows days the numerous times I was given code that was supposedly "good to go", but which failed to compile for some stupid reason. Of course I...
4
5484
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 Java, creating a file, say pr21.java with a single class and main method, compiling it, and running it. Since I've switched to C#, I have been using MS Visual C# Express 2008 as my IDE. It has this weird obsession with encapsulating all of my programs...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9996
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.