Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 548867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:07:30+00:00 2026-05-13T11:07:30+00:00

I compiled the Boost C++ libraries as follows: bjam install variant=release link=static threading=multi runtime-link=static

  • 0

I compiled the Boost C++ libraries as follows:

bjam install variant=release link=static threading=multi runtime-link=static

No errors. Then I compiled the following source:

#include <boost/thread/thread.hpp>
#include <iostream>

#define BOOST_THREAD_NO_LIB

void hello() {
  std::cout << "Hello world, I'm a thread!" << std::endl;
}

int main(int argc, char* argv[]) {
  boost::thread thrd(&hello);
  thrd.join();
  return 0;
}

Using:

g++ -lboost_thread Thread.cpp

The program compiled and ran fine because the Boost libraries are found in /usr/local/lib. When I removed /usr/local/lib from /etc/ld.so.conf.d/libc.conf I ran into the following error (no surpise):

./a.out: error while loading shared libraries: libboost_thread.so.1.41.0: cannot
open shared object file: No such file or directory

How do I compile Thread.cpp linking to Boost statically? I tried the following:

g++ -static -lboost_thread -lpthread Thread.cpp

I have the following Boost libraries installed:

 ldconfig -v | grep boost
 libboost_unit_test_framework.so.1.41.0 -> libboost_unit_test_framework.so.1.41.0
 libboost_math_tr1f.so.1.41.0 -> libboost_math_tr1f.so.1.41.0
 libboost_prg_exec_monitor.so.1.41.0 -> libboost_prg_exec_monitor.so.1.41.0
 libboost_math_c99.so.1.41.0 -> libboost_math_c99.so.1.41.0
 libboost_regex.so.1.41.0 -> libboost_regex.so.1.41.0
 libboost_signals.so.1.41.0 -> libboost_signals.so.1.41.0
 libboost_python.so.1.41.0 -> libboost_python.so.1.41.0
 libboost_serialization.so.1.41.0 -> libboost_serialization.so.1.41.0
 libboost_graph.so.1.41.0 -> libboost_graph.so.1.41.0
 libboost_date_time.so.1.41.0 -> libboost_date_time.so.1.41.0
 libboost_thread.so.1.41.0 -> libboost_thread.so.1.41.0
 libboost_math_c99l.so.1.41.0 -> libboost_math_c99l.so.1.41.0
 libboost_math_tr1l.so.1.41.0 -> libboost_math_tr1l.so.1.41.0
 libboost_wserialization.so.1.41.0 -> libboost_wserialization.so.1.41.0
 libboost_system.so.1.41.0 -> libboost_system.so.1.41.0
 libboost_math_tr1.so.1.41.0 -> libboost_math_tr1.so.1.41.0
 libboost_math_c99f.so.1.41.0 -> libboost_math_c99f.so.1.41.0
 libboost_wave.so.1.41.0 -> libboost_wave.so.1.41.0
 libboost_filesystem.so.1.41.0 -> libboost_filesystem.so.1.41.0
 libboost_program_options.so.1.41.0 -> libboost_program_options.so.1.41.0
 libboost_program_options.so.1.35.0 -> libboost_program_options.so.1.35.0
 libboost_program_options-mt.so.1.35.0 -> libboost_program_options-mt.so.1.35.0
 libboost_thread-gcc42-mt-1_34_1.so.1.34.1 -> libboost_thread-gcc42-mt-1_34_1.so.1.34.1

I receive the following compile errors:

/tmp/ccek8Br2.o: In function `main':
Thread.cpp:(.text+0x10b): undefined reference to `boost::thread::join()'
Thread.cpp:(.text+0x119): undefined reference to `boost::thread::~thread()'
Thread.cpp:(.text+0x140): undefined reference to `boost::thread::~thread()'
/tmp/ccek8Br2.o: In function `boost::mutex::mutex()':
Thread.cpp:(.text._ZN5boost5mutexC1Ev[boost::mutex::mutex()]+0x22): undefined reference to `pthread_mutex_init'
/tmp/ccek8Br2.o: In function `boost::detail::thread_data<void (*)()>::~thread_data()':
Thread.cpp:(.text._ZN5boost6detail11thread_dataIPFvvEED0Ev[boost::detail::thread_data<void (*)()>::~thread_data()]+0x1c): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/tmp/ccek8Br2.o: In function `boost::detail::thread_data<void (*)()>::~thread_data()':
Thread.cpp:(.text._ZN5boost6detail11thread_dataIPFvvEED1Ev[boost::detail::thread_data<void (*)()>::~thread_data()]+0x1c): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/tmp/ccek8Br2.o: In function `boost::condition_variable::condition_variable()':
Thread.cpp:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x17): undefined reference to `pthread_cond_init'
/tmp/ccek8Br2.o: In function `boost::condition_variable::~condition_variable()':
Thread.cpp:(.text._ZN5boost18condition_variableD1Ev[boost::condition_variable::~condition_variable()]+0x11): undefined reference to `pthread_cond_destroy'
/tmp/ccek8Br2.o: In function `boost::mutex::~mutex()':
Thread.cpp:(.text._ZN5boost5mutexD1Ev[boost::mutex::~mutex()]+0x11): undefined reference to `pthread_mutex_destroy'
/tmp/ccek8Br2.o: In function `boost::detail::thread_data_base::thread_data_base()':
Thread.cpp:(.text._ZN5boost6detail16thread_data_baseC2Ev[boost::detail::thread_data_base::thread_data_base()]+0x23): undefined reference to `vtable for boost::detail::thread_data_base'
/tmp/ccek8Br2.o: In function `boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)':
Thread.cpp:(.text._ZN5boost6threadC1IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thread_move_tIS4_EEEEPNS0_5dummyEE4typeE[boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)]+0x36): undefined reference to `boost::thread::start_thread()'
/tmp/ccek8Br2.o:(.rodata._ZTIN5boost6detail11thread_dataIPFvvEEE[typeinfo for boost::detail::thread_data<void (*)()>]+0x10): undefined reference to `typeinfo for boost::detail::thread_data_base'
collect2: ld returned 1 exit status

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:07:31+00:00Added an answer on May 13, 2026 at 11:07 am

    Try:

    g++ -static -pthread Thread.cpp -lboost_thread
    

    Libraries must be specified after the objects (or sources) that use symbols from those libraries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a newbie about boost. I compiled boost libraries with success (under mac os
Using Visual Studio 2008 and Boost Libraries 1.46.1 I want to compile and link
I'm trying setup a subset of boost and get it properly compiled using bjam,
When building Boost binary libraries with bjam , one may specify which compiler to
I compiled the boost 1.50.0 libraries using b2 with the correct Python configuration. Here's
Background Using boost and other similar libraries is the easiest way to find compiler
I have compiled part of boost - the ibeta_inv function - into a .Net
I'm trying to compile the boost 1.49 using bjam.exe. I found the commandline: bjam.exe
I'm trying to compile using a compiled Boost libs. I can compile using header-only
I have just started with using boost libraries. For one of our projects i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.