jeudi 28 janvier 2021

Undefined symbols for architecture x86_64 on gcc [duplicate]

I have read that I may have encountered some sort of bug or glitch with respect to the mac's regular GCC.. is this the case or is my code the culprit.. what do I mean??

% sh compile.sh                             
-- Conan: Adjusting output directories
-- Conan: Using cmake targets configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Current conanbuildinfo.cmake directory: /ch09_06_threadpool_local_queues/build
-- Configuring done
-- Generating done
-- Build files have been written to: /ch09_06_threadpool_local_queues/build
Scanning dependencies of target test_cpp_multi
[ 33%] Building CXX object CMakeFiles/test_cpp_multi.dir/src/helloworld.cpp.o
[ 66%] Linking CXX executable bin/test_cpp_multi
Undefined symbols for architecture x86_64:
  "thread-local wrapper routine for thread_pool::local_work_queue", referenced from:
      thread_pool::worker_thread() in helloworld.cpp.o
      thread_pool::run_pending_task() in helloworld.cpp.o
      std::__1::future<std::__1::result_of<std::__1::__bind<std::__1::list<int, std::__1::allocator<int> > (sorter<int>::*)(std::__1::list<int, std::__1::allocator<int> >&), sorter<int>*, std::__1::list<int, std::__1::allocator<int> > > ()>::type> thread_pool::submit<std::__1::__bind<std::__1::list<int, std::__1::allocator<int> > (sorter<int>::*)(std::__1::list<int, std::__1::allocator<int> >&), sorter<int>*, std::__1::list<int, std::__1::allocator<int> > > >(std::__1::__bind<std::__1::list<int, std::__1::allocator<int> > (sorter<int>::*)(std::__1::list<int, std::__1::allocator<int> >&), sorter<int>*, std::__1::list<int, std::__1::allocator<int> > >) in helloworld.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/test_cpp_multi] Error 1
make[1]: *** [CMakeFiles/test_cpp_multi.dir/all] Error 2

This helloworld.cpp was working in the past.. and I am working with a C++ book trying to learn about concurrency where in which it adds this bit to the code.. but I am unable to compile..

https://github.com/anthonywilliams/ccia_code_samples/blob/main/listings/listing_9.6.cpp

class thread_pool
{
    std::atomic_bool done;
    thread_safe_queue<function_wrapper> work_queue;
    std::vector<std::thread> threads;
    join_threads joiner;

    thread_safe_queue<function_wrapper> pool_work_queue;
    typedef std::queue<function_wrapper> local_queue_type;
    static thread_local std::unique_ptr<local_queue_type> local_work_queue;

    void worker_thread()
    {
        local_work_queue.reset(new local_queue_type);

        while(!done)
        {
            run_pending_task();
        }
    }
...

    template<typename FunctionType>
    std::future<typename std::result_of<FunctionType()>::type> submit(FunctionType f)
    {
        typedef typename std::result_of<FunctionType()>::type result_type;
        std::packaged_task<result_type()> task(f);
        std::future<result_type> res(task.get_future());
        if(local_work_queue)
        {
            local_work_queue->push(std::move(task));
        }
        else
        {
            pool_work_queue.push(std::move(task));
        }
        return res;
    }

    void run_pending_task()
    {
        function_wrapper task;
        if(local_work_queue && !local_work_queue->empty())
        {
            task=std::move(local_work_queue->front());
            local_work_queue->pop();
            task();
        }
        else if(pool_work_queue.try_pop(task))
        {
            task();
        }
        else
        {
            std::this_thread::yield();
        }
    }

EDIT: For experimental purposes I went ahead and loaded up my code in a linux machine... same issue apparently, so it's not apple.. but not sure how to come to get it compiling

$ sh compile.sh 
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: Adjusting output directories
-- Conan: Using cmake targets configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Current conanbuildinfo.cmake directory: /ch09_06_threadpool_local_queues/build
-- Conan: Compiler GCC>=5, checking major version 9
-- Conan: Checking correct version: 9
-- Configuring done
-- Generating done
-- Build files have been written to: /ch09_06_threadpool_local_queues/build
Scanning dependencies of target test_cpp_multi
[ 33%] Building CXX object CMakeFiles/test_cpp_multi.dir/src/thread_safe_queue.cpp.o
[ 66%] Building CXX object CMakeFiles/test_cpp_multi.dir/src/helloworld.cpp.o
[100%] Linking CXX executable bin/test_cpp_multi
/usr/bin/ld: CMakeFiles/test_cpp_multi.dir/src/helloworld.cpp.o: in function `TLS wrapper function for thread_pool::local_work_queue':
helloworld.cpp:(.text._ZTWN11thread_pool16local_work_queueE[_ZTWN11thread_pool16local_work_queueE]+0x9): undefined reference to `TLS init function for thread_pool::local_work_queue'
/usr/bin/ld: helloworld.cpp:(.text._ZTWN11thread_pool16local_work_queueE[_ZTWN11thread_pool16local_work_queueE]+0x19): undefined reference to `thread_pool::local_work_queue'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/test_cpp_multi.dir/build.make:99: bin/test_cpp_multi] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/test_cpp_multi.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Aucun commentaire:

Enregistrer un commentaire