undefined referrence

Developers
Tao Yang
2006-12-06
2013-05-13
  • Tao Yang
    Tao Yang
    2006-12-06

    I am trying to using STLport, Boost on linux with gcc, I compiled stlport 5.0.2 first, then compiled Boost 1.33.1 with following command:

    bjam "-sTOOLS=gcc-stlport" "-sSTLPORT_PATH=/opt" "-sSTLPORT_VERSION=5.0.2" "-sSTLPORT_VERSIONS=5.0.2" "-sBUILD=debug release <runtime-link>static/dynamic" --prefix=/usr/local --builddir=./build install

    Then I am trying to compile following code:

    #include <hash_set>
    #include <string>
    #include <iostream>

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

    using std::hash_set;
    using std::string;
    using std::cout;

    class MyThread
    {
    public:
        MyThread();

        void run();

        void join();

    private:
        boost::thread m_thread;
    };

    MyThread::MyThread() : m_thread(boost::bind(&MyThread::run, this))
    {
    }

    void MyThread::run()
    {
        hash_set<string> strSet;

        string str = "hello ";
        strSet.insert(str);
        cout << "insert: " << str << std::endl;
        str = "world!";
        strSet.insert(str);
        cout << "insert: " << str << std::endl;

        hash_set<string>::iterator sIter = strSet.begin();
        while (strSet.end() != sIter) {
            str = *sIter;
            cout << "get: " << str << std::endl;
        }

    }

    void MyThread::join()
    {
        m_thread.join();
    }

    int main()
    {
        MyThread thread1;
        thread1.join();
        return 0;
    }

    with following command:

    g++ -pthread -O2 -o test -I/usr/local/include/boost-1_33_1 -I/opt/STLport/include/stlport test.cpp -L/usr/local/lib -lboost_thread-gcc-mt-p -L/opt/STLport/lib -lstlport

    however, I get following error message:

    /tmp/ccnKcH1k.o: In function `MyThread::MyThread()':
    test.cpp:(.text+0xec): undefined reference to `boost::thread::thread(boost::function0<void, stlp_std::allocator<boost::function_base> > const&)'
    /tmp/ccnKcH1k.o: In function `MyThread::MyThread()':
    test.cpp:(.text+0x2ac): undefined reference to `boost::thread::thread(boost::function0<void, stlp_std::allocator<boost::function_base> > const&)'
    collect2: ld returned 1 exit status

    I tried both gcc 4.1.1 and gcc 3.4, they all give me the same error message.

    Am I doing something wrong? or missing somethig here?

    Thanks a lot for your help in advance!
    cheers,
    Tao

     
    • Have you checked that this symbol is in the boost thread library ? Try to see what constructor you have in this library. What is sure is that when you build your apply you are using STLport because we see that it is looking for allocator in stlp_std namespace which is a STLport namespace.

      You can perhaps try to rebuild boost even if I do not see any problem in your command. You can also try STLport 5.1.0 even if once again it shouldn't help. Have you asked boost forum too ?

       
    • I'm suspect that problem near bjam/boost build: it was oriented on ancient STLport.

      I use STLport with boost, but boost's libs built with the same make rules as STLport, never with bjam. [all versions of STLport, boost 1.33, 1.33.1, all gcc versions you mention above].

      This 'custom' boost builds publicly available in 'complement' project at SF.

        - ptr