Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 链接器错误:未定义对“ThreadPool::ThreadPool()';_C++_Linker_Linker Errors - Fatal编程技术网

C++ 链接器错误:未定义对“ThreadPool::ThreadPool()';

C++ 链接器错误:未定义对“ThreadPool::ThreadPool()';,c++,linker,linker-errors,C++,Linker,Linker Errors,我有一个班级。我有一个头文件threadpool.h和实现threadpool.cc。当我尝试初始化线程池时,如下所示:threadpool*tp=newthreadpool()我收到以下链接器错误: /usr/bin/ld: ../src/libmapreducelib.a(mapreduce_impl.cc.o): in function `Master::Master(MapReduceSpec const&, std::vector<FileShard, std::allo

我有一个班级。我有一个头文件threadpool.h和实现threadpool.cc。当我尝试初始化线程池时,如下所示:
threadpool*tp=newthreadpool()我收到以下链接器错误:

/usr/bin/ld: ../src/libmapreducelib.a(mapreduce_impl.cc.o): in function `Master::Master(MapReduceSpec const&, std::vector<FileShard, std::allocator<FileShard> > const&)':
/aos-pr4/src/master.h:43: undefined reference to `ThreadPool::ThreadPool()'
collect2: error: ld returned 1 exit status
make[2]: *** [test/CMakeFiles/mrdemo.dir/build.make:127: bin/mrdemo] Error 1
make[1]: *** [CMakeFiles/Makefile2:330: test/CMakeFiles/mrdemo.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
下面是我的threadpool.h、threadpool.cc和CMakeLists.txt文件

//在adpool.h中
#ifndef螺纹池
#定义线程池
#布拉格语一次
类线程池{
公众:
使用Task=std::function;
//构造函数,初始化要添加到队列的静态工作进程数
线程池()
线程池(int numOfWorkers);
虚拟线程池();
....
}
#恩迪夫
//在threadpool.cc中
#包括“threadpool.h”
线程池::线程池(){
//注释掉
}
....
我甚至确保我的cmakelist库包含threadpool.h

//CMakeLists.txt
project(mapreducer)

include(GenerateProtos.cmake)

add_library(
  mapreducelib #library name
  mapreduce.cc mapreduce_impl.cc #sources
  master.h  mapreduce_spec.h file_shard.h threadpool.h) #headers
target_link_libraries(mapreducelib p4protolib)
target_include_directories(mapreducelib PUBLIC ${MAPREDUCE_INCLUDE_DIR})
add_dependencies(mapreducelib p4protolib)

我相信它应该是好的,我已经在另一个项目中使用了我的线程池。这一定是项目层次结构。

现在我不是cmake的高手,但我没有看到CMakeLists.txt
threadpool()中列出的threadpool.cc缺少一个
。谢谢。这两件事都解决了我的问题。
//CMakeLists.txt
project(mapreducer)

include(GenerateProtos.cmake)

add_library(
  mapreducelib #library name
  mapreduce.cc mapreduce_impl.cc #sources
  master.h  mapreduce_spec.h file_shard.h threadpool.h) #headers
target_link_libraries(mapreducelib p4protolib)
target_include_directories(mapreducelib PUBLIC ${MAPREDUCE_INCLUDE_DIR})
add_dependencies(mapreducelib p4protolib)