CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2012
    Posts
    0

    boost thread linker issues

    Alright, been fighting and scouring the internet for this for awhile now and am at a loss. I'm pretty new at all this, but I'm learning. Here's the deal.

    I am using Code::Blocks IDE with default mingw32 g++ compiler.
    I downloaded and compiled boost 1.48 as detailed here: http://wiki.codeblocks.org/index.php...indowsQuickRef (I used --build-type=complete)

    I have used Code::Blocks to link to all of the .a files in the output "lib" folder (including "libboost_thread-mgw46-mt-1_48.a" and "libboost_thread-mgw46-mt-d-1_48.a".)

    I am trying to compile this code from: http://antonym.org/2009/05/threading...g-threads.html

    Code:
    //#define BOOST_THREAD_USE_LIB
    #include <iostream>
    #include <boost/thread.hpp>
    #include <boost/date_time.hpp>
    
    void workerFunc()
    {
        boost::posix_time::seconds workTime(3);
    
        std::cout << "Worker: running" << std::endl;
    
        // Pretend to do something useful...
        boost::this_thread::sleep(workTime);
    
        std::cout << "Worker: finished" << std::endl;
    }
    
    int main(int argc, char* argv[])
    {
        std::cout << "main: startup" << std::endl;
    
        boost::thread workerThread(workerFunc);
    
        workerFunc();
    
        std::cout << "main: waiting for thread" << std::endl;
    
        workerThread.join();
    
        std::cout << "main: done" << std::endl;
    
        return 0;
    }
    When I try to compile I get a bunch of errors like :
    undefined reference to `_imp___ZN5boost6thread4joinEv'
    undefined reference to `_imp___ZN5boost6threadD1Ev'
    undefined reference to `_imp___ZN5boost6threadD1Ev'

    It works fine when I comment out the lines dealing with boost threading but leave the line that deals with boost time.

    If I define BOOST_THREAD_USE_LIB (to tell the library to link statically like I would like) I get errors like these:
    undefined reference to `boost::thread::join()'
    undefined reference to `boost::thread::~thread()'
    undefined reference to `boost::thread::~thread()'

    Again I am very new and I have much to learn. I feel like I have enough information here to figure out what the problem is, but unfortunately it is beyond my grasp. I may just need to know more about linking if anyone is aware of any good beginner resources on the subject feel free to give me a heads up I feel that my knowledge is particularly weak in this area.

    Thanks in advance for any insight!

    On a side note: If any mods happen upon this thread, while reading the "read before posting" post, I discovered a couple of ironic errors in the encouragement for proper grammar. Grammar is spelled "grammer" in the post. Additionally "response" should be "respond". This is trivial but I thought someone might care.

  2. #2
    Join Date
    Jul 2007
    Location
    somwhere nearby
    Posts
    150

    Re: boost thread linker issues

    i had the same problem with the latest version of boost . but thank to God , i managed to solve it .
    read it from here :
    http://forums.codeblocks.org/index.p...;topicseen#new
    rebuild your boost library as specified there ( the last post ) . then configure codeblocks as shown in that thread . then you are good to go .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured