LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-19-2016, 08:07 PM   #1
rdx
Member
 
Registered: Apr 2007
Location: Dallas
Distribution: Slackware64 14.2
Posts: 283

Rep: Reputation: 25
Basic usage of Boost, how to compile?


I just installed the latest Boost on my Slackware64 14.1 system. It seemed to go well and as far as I know all got installed properly except the includes and lib were in a weird place. I moved the includes to /usr/local/include and linked the libs to /usr/local/lib to make it generally compatible with my setup.

But when I try to compile one of the example programs I get errors of the type indication a missing lib (i.e., undefined reference to `boost::random::random_device::random_device' and similar in this particular example). From what I read in the manual, mostly libs aren't even needed, the headers supply everything. Basically all I wanted from Boost was elliptic integrals and other special functions but I'm stuck on a simple 'how to compile' problem.
 
Old 10-19-2016, 10:33 PM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
Did you try linking against the library?
Code:
$ g++ main.cpp -lboost_random
The following code from the Boost docs compiles on my 14.2 system:
Code:
#include <iostream>
#include <boost/random/random_device.hpp>
#include <boost/random/uniform_int_distribution.hpp>

int main() {
    std::string chars(
        "abcdefghijklmnopqrstuvwxyz"
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "1234567890"
        "!@#$%^&*()"
        "`~-_=+[{]}\\|;:'",<.>/? ");
    boost::random::random_device rng;
    boost::random::uniform_int_distribution<> index_dist(0, chars.size() - 1);
    for(int i = 0; i < 8; ++i) {
        std::cout << chars[index_dist(rng)];
    }
    std::cout << std::endl;
}
 
1 members found this post helpful.
Old 10-22-2016, 10:00 PM   #3
rdx
Member
 
Registered: Apr 2007
Location: Dallas
Distribution: Slackware64 14.2
Posts: 283

Original Poster
Rep: Reputation: 25
Ok, that works, thank you. But I still haven't found in the docs what the libs are and when they are needed. I guess I always have this problem when I'm new to something. It's not that I mind feeling stupid, but I don't have time to spend on things that should be easy, I am busy already, lol.

BTW, the program compiles and runs but does it do anything useful? ^.^

Oh, one more thing: The example programs in the package compile without linking libs. Something magic seems to be going on there but IDK what it is.

Last edited by rdx; 10-22-2016 at 10:05 PM.
 
Old 10-23-2016, 02:55 AM   #4
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Rep: Reputation: 19
Most of the boost library is just header files, and they don't require building or linking to be used. Just include the appropriate headers and you're good to go.The boost library documentation will tell you which headers you need to include for each library.
 
Old 10-23-2016, 10:19 AM   #5
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
You're welcome.

Quote:
Originally Posted by rdx View Post
But I still haven't found in the docs what the libs are and when they are needed.
http://www.boost.org/doc/libs/1_62_0...only-libraries
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile with ATLAS and Boost Numeric Bindings Ornithological Ornod Programming 1 01-13-2010 05:43 AM
I have boost libraries in ubuntu installed using aptget , how can I Compile them amolgupta Programming 7 11-12-2009 02:02 PM
basic vi / grep usage opensource82 Linux - Newbie 10 07-07-2008 04:22 AM
Problem with boost regex - can't compile easiest examples lodziarz Programming 3 02-28-2008 04:15 PM
memory usage boost DAChristen29 Linux - Software 5 07-24-2003 10:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration