CMakeFiles/main.dir/sample_process.cpp.o: In function `SampleProcess::Postprocess(aclmdlDataset const*, PicDesc&, int, int)': sample_process.cpp:(.text+0x1104): undefined reference to `SampleProcess::CalculateCrc16(unsigned char volatile*, unsigned char)' collect2: error: ld returned 1 exit status src/CMakeFiles/main.dir/build.make:406: recipe for target 'main' failed make[2]: *** [main] Error 1 CMakeFiles/Makefile2:85: recipe for target 'src/CMakeFiles/main.dir/all' failed make[1]: *** [src/CMakeFiles/main.dir/all] Error 2 Makefile:129: recipe for target 'all' failed make: *** [all] Error 2
时间: 2024-04-26 19:26:39 浏览: 104
这个错误提示是链接错误,说明编译器无法找到`CalculateCrc16`函数的定义。可能是因为你在代码中只提供了函数的声明,但没有提供函数的实现。请确认你是否在代码中提供了`CalculateCrc16`函数的实现,并且该实现是否被正确地编译和链接到可执行文件中。
另外,如果你在代码中提供了`CalculateCrc16`函数的实现,但是在编译时没有正确地链接该函数的实现,也可能会导致链接错误。请确认是否正确地配置了编译器链接选项,并将`CalculateCrc16`函数的实现文件链接到可执行文件中。
相关问题
FAILED: MyTestHttp : && /usr/bin/c++ -g CMakeFiles/MyTestHttp.dir/main.cpp.o -o MyTestHttp && : /usr/bin/ld: CMakeFiles/MyTestHttp.dir/main.cpp.o: in function `Http::Http()': /home/hy-20/project/MyTestHttp/main.cpp:20: undefined reference to `curl_global_init' /usr/bin/ld: /home/hy-20/project/MyTestHttp/main.cpp:21: undefined reference to `curl_easy_init' /usr/bin/ld: CMakeFiles/MyTestHttp.dir/main.cpp.o: in function `Http::~Http()': /home/hy-20/project/MyTestHttp/main.cpp:25: undefined reference to `curl_easy_cleanup' /usr/bin/ld: /home/hy-20/project/MyTestHttp/main.cpp:26: undefined reference to `curl_global_cleanup' /usr/bin/ld: CMakeFiles/MyTestHttp.dir/main.cpp.o: in function `Http::setUrl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': /home/hy-20/project/MyTestHttp/main.cpp:29: undefined reference to `curl_easy_setopt' /usr/bin/ld: CMakeFiles/MyTestHttp.dir/main.cpp.o: in function `Http::setPostFields(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': /home/hy-20/project/MyTestHttp/main.cpp:31: undefined reference to `curl_easy_setopt' /usr/bin/ld: CMakeFiles/MyTestHttp.dir/main.cpp.o: in function `Http::setMethod(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': /home/hy-20/project/MyTestHttp/main.cpp:35: undefined reference to `curl_easy_setopt' /usr/bin/ld: /home/hy-20/project/MyTestHttp/main.cpp:36: undefined reference to `curl_easy_setopt' /usr/bin/ld: CMakeFiles/MyTestHttp.dir/main.cpp.o: in function `Http::setHeaders(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': /home/hy-20/project/MyTestHttp/main.cpp:41: undefined reference to `curl_slist_append' /usr/bin/ld: /home/hy-20/project/MyTestHttp/main.cpp:42: undefined reference to `curl_easy_setopt' /usr/bin/ld: CMakeFiles/MyTestHttp.dir/main.cpp.o: in function `Http::setWriteFunction(std::function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> const&)': /home/hy-20/project/MyTestHttp/main.cpp:46: undefined reference to `curl_easy_setopt' /usr/bin/ld: /home/hy-20/project/MyTestHttp/main.cpp:47: undefined reference to `curl_easy_setopt' /usr/bin/ld: CMakeFiles/MyTestHttp.dir/main.cpp.o: in function `Http::perform()': /home/hy-20/project/MyTestHttp/main.cpp:50: undefined reference to `curl_easy_perform' collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed.
这是一个链接错误,编译器找不到 curl 库的函数。你需要在链接时加上 curl 库。如果你使用的是 CMake,可以在 CMakeLists.txt 中添加以下代码:
```
find_package(CURL REQUIRED)
target_link_libraries(YourProjectName ${CURL_LIBRARIES})
```
其中,YourProjectName 是你的项目名称。
usr/bin/ld: CMakeFiles/yolov8.dir/yolov8_generated_process.cu.o:/media/lindsay/data/tensorrt_infer_engine/x86/yolov8-tensorrtx/tensorrt7/person/include/config.h:15: multiple definition of `OUTPUT_BLOB_NAME'; CMakeFiles/yolov8.dir/yolov8.cpp.o:/media/lindsay/data/tensorrt_infer_engine/x86/yolov8-tensorrtx/tensorrt7/person/include/config.h:15: first defined here /usr/bin/ld: CMakeFiles/yolov8.dir/yolov8_generated_process.cu.o:/media/lindsay/data/tensorrt_infer_engine/x86/yolov8-tensorrtx/tensorrt7/person/include/config.h:14: multiple definition of `INPUT_BLOB_NAME'; CMakeFiles/yolov8.dir/yolov8.cpp.o:/media/lindsay/data/tensorrt_infer_engine/x86/yolov8-tensorrtx/tensorrt7/person/include/config.h:14: first defined here
根据提供的错误信息,你的代码中存在重复定义的问题。编译器指出在 `yolov8_generated_process.cu.o` 和 `yolov8.cpp.o` 文件中都重复定义了 `OUTPUT_BLOB_NAME` 和 `INPUT_BLOB_NAME` 变量。
这种错误通常发生在多个源文件中都包含了同一个头文件,并且该头文件中定义了全局变量。由于每个源文件都会被编译成独立的目标文件,因此重复定义的全局变量会导致链接时出现冲突。
要解决这个问题,你可以考虑将这些全局变量的定义放在一个单独的源文件中,并在其他需要使用这些变量的源文件中使用 `extern` 关键字进行声明。这样可以确保全局变量只有一份定义,并且可以在多个源文件中共享。
首先,在一个源文件(比如 `config.cpp`)中定义这些全局变量:
```cpp
// config.cpp
#include "config.h"
const std::string INPUT_BLOB_NAME = "input_blob";
const std::string OUTPUT_BLOB_NAME = "output_blob";
```
然后,在其他源文件中使用 `extern` 关键字进行声明:
```cpp
// yolov8_generated_process.cu
#include "config.h"
extern const std::string INPUT_BLOB_NAME;
extern const std::string OUTPUT_BLOB_NAME;
// 其他代码
```
```cpp
// yolov8.cpp
#include "config.h"
extern const std::string INPUT_BLOB_NAME;
extern const std::string OUTPUT_BLOB_NAME;
// 其他代码
```
这样做可以确保全局变量只有一份定义,并且可以在多个源文件中共享使用。
请根据你的实际需求和代码结构,将全局变量的定义放在一个单独的源文件中,并在其他源文件中使用 `extern` 进行声明。如果问题仍然存在,请提供更多相关代码以便我们更好地帮助你解决问题。
阅读全文