Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error in Tensorrt model using CMake #3819

Closed
gbdjxgp opened this issue Apr 23, 2024 · 1 comment
Closed

Compilation error in Tensorrt model using CMake #3819

gbdjxgp opened this issue Apr 23, 2024 · 1 comment

Comments

@gbdjxgp
Copy link

gbdjxgp commented Apr 23, 2024

Description

I tried to compile YOLOV8 model using tensorRT and cmake, but get some error.
The original code was publicly available in https://github.com/FeiYull/TensorRT-Alpha/yolov8 Inside, I modified the cmakelists.txt file in the yolov8 folder to the following format and received a link error as shown below. How should I resolve this error? Thank you!
Note:I have included the logger.cpp and logger.h file in TensorRT/common/ but still get this error.

Error:

LINK : warning LNK4098: 默认库“LIBCMT”与其他库的使用冲突;请使用 /NODEFAULTLIB:library
app_yolov8.cpp.obj : error LNK2019: 无法解析的外部符号 "class sample::LogStreamConsumer sample::gLogInfo" (?gLogInfo@sample@@3VLogStreamConsumer@1@A),函数 "void __cdecl task(class YOLOV8 &,struct utils::InitParameter const &,class std::vector<class cv::Mat,class std::allocator > &,int const &,int const &,bool const &,bool const &)" (?task@@YAXAEAVYOLOV8@@AEBUInitParameter@utils@@aeav?$vector@VMat@cv@@v?$allocator@VMat@cv@@@std@@@std@@AEBH3AEB_N4@Z) 中引用了该符号
yolo.cpp.obj : error LNK2001: 无法解析的外部符号 "class sample::LogStreamConsumer sample::gLogInfo" (?gLogInfo@sample@@3VLogStreamConsumer@1@A)
app_yolov8.cpp.obj : error LNK2019: 无法解析的外部符号 "class sample::LogStreamConsumer sample::gLogWarning" (?gLogWarning@sample@@3VLogStreamConsumer@1@A),函数 main 中引用了该符号
utils.cpp.obj : error LNK2001: 无法解析的外部符号 "class sample::LogStreamConsumer sample::gLogWarning" (?gLogWarning@sample@@3VLogStreamConsumer@1@A)
app_yolov8.cpp.obj : error LNK2019: 无法解析的外部符号 "class sample::LogStreamConsumer sample::gLogError" (?gLogError@sample@@3VLogStreamConsumer@1@A),函数 main 中引用了该符号
yolov8.cpp.obj : error LNK2019: 无法解析的外部符号 "class sample::Logger sample::gLogger" (?gLogger@sample@@3VLogger@1@A),函数 "public: virtual bool __cdecl YOLOV8::init(class std::vector<unsigned char,class std::allocator > const &)" (?init@YOLOV8@@UEAA_NAEBV?$vector@EV?$allocator@E@std@@@std@@@z) 中引用了该符号
yolo.cpp.obj : error LNK2001: 无法解析的外部符号 "class sample::Logger sample::gLogger" (?gLogger@sample@@3VLogger@1@A)
app_yolov8.exe : fatal error LNK1120: 4 个无法解析的外部命令
ninja: build stopped: subcommand failed.

cMakelists.txt:

`cmake_minimum_required(VERSION 3.10)

set(CMAKE_BUILD_TYPE "Release")

PROJECT(yolov8 VERSION 1.0.0 LANGUAGES C CXX CUDA)
message(STATUS CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR})
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/common.cmake)
message(STATUS TensorRT_ROOT = ${TensorRT_ROOT})
message(STATUS ${ALL_LIBS})
file(GLOB CPPS
${CMAKE_CURRENT_SOURCE_DIR}/.cpp
${CMAKE_CURRENT_SOURCE_DIR}/
.cu
${CMAKE_CURRENT_SOURCE_DIR}/../utils/.cu
${CMAKE_CURRENT_SOURCE_DIR}/../utils/
.cpp
${TensorRT_ROOT}/samples/common/logger.cpp
${TensorRT_ROOT}/samples/common/logger.h
${TensorRT_ROOT}/samples/common/logging.h
${TensorRT_ROOT}/samples/common/sampleOptions.cpp
${TensorRT_ROOT}/samples/common/sampleUtils.cpp
)
list(REMOVE_ITEM CPPS app_yolov8.cpp)
message(STATUS CPPS = ${CPPS})
list (LENGTH CPPS length)
message(STATUS length = ${length})
find_package(OpenCV REQUIRED)
include_directories(${INCLUDE_DRIS} ${OpenCV_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS INCLUDE_DRIS = ${INCLUDE_DRIS})
message(STATUS OpenCV_INCLUDE_DIRS = ${OpenCV_INCLUDE_DIRS})
add_library(${PROJECT_NAME} SHARED ${CPPS})
target_link_libraries(${PROJECT_NAME} ${ALL_LIBS} ${OpenCV_LIBRARIES})

set_property(TARGET ${PROJECT_NAME} PROPERTY CUDA_ARCHITECTURES 50 61 72 75)
target_compile_options(${PROJECT_NAME} PUBLIC
$&lt;$&lt;COMPILE_LANGUAGE:CUDA>:--default-stream per-thread -lineinfo; --use_fast_math --disable-warnings>)

add_executable(app_yolov8 app_yolov8.cpp yolov8.cpp decode_yolov8.cu)
file(GLOB sources ../utils/.cpp ../utils/.h ../utils/*.cu)
target_sources(app_yolov8 PUBLIC ${sources})

file(GLOB linklibraries C:/ProgramData/TensorRT-8.6.1.6/lib/*.lib)
target_sources(app_yolov8 PUBLIC ${sources})
target_link_libraries(app_yolov8 ${ALL_LIBS} ${OpenCV_LIBRARIES} ${linklibraries})

target_link_directories(app_yolov8 PUBLIC "C:/ProgramData/TensorRT-8.6.1.6/lib")
include_directories("C:/ProgramData/TensorRT-8.6.1.6/include")
`

@gbdjxgp gbdjxgp changed the title [compile error]failure of TensorRT 8.6.1.6 when running YOLO on GPU 3090 Compilation error in Tensorrt model using CMake Apr 24, 2024
@gbdjxgp gbdjxgp closed this as completed Apr 24, 2024
@gbdjxgp
Copy link
Author

gbdjxgp commented Apr 24, 2024

solved. modify CmakeLists into:

cmake_minimum_required(VERSION 3.10)

#set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_BUILD_TYPE "Release")

PROJECT(yolov8 VERSION 1.0.0 LANGUAGES C CXX CUDA)
message(STATUS CMAKE_CURRENT_SOURCE_DIR = ${CMAKE_CURRENT_SOURCE_DIR})
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/common.cmake)
message(STATUS TensorRT_ROOT = ${TensorRT_ROOT})
message(STATUS ${ALL_LIBS})
file(GLOB CPPS 
  ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
  ${CMAKE_CURRENT_SOURCE_DIR}/*.cu
  ${CMAKE_CURRENT_SOURCE_DIR}/../utils/*.cu
  ${CMAKE_CURRENT_SOURCE_DIR}/../utils/*.cpp
  ${TensorRT_ROOT}/samples/common/logger.cpp 
  ${TensorRT_ROOT}/samples/common/logger.h
  ${TensorRT_ROOT}/samples/common/logging.h
  ${TensorRT_ROOT}/samples/common/sampleOptions.cpp
  ${TensorRT_ROOT}/samples/common/sampleUtils.cpp
  )
list(REMOVE_ITEM CPPS app_yolov8.cpp)
message(STATUS CPPS = ${CPPS})
list (LENGTH CPPS length)
message(STATUS ***length*** = ${length}) 
find_package(OpenCV REQUIRED)
include_directories(${INCLUDE_DRIS} ${OpenCV_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS ***INCLUDE_DRIS*** = ${INCLUDE_DRIS})
message(STATUS ***OpenCV_INCLUDE_DIRS*** = ${OpenCV_INCLUDE_DIRS})
add_library(${PROJECT_NAME} SHARED ${CPPS})
target_link_libraries(${PROJECT_NAME} ${ALL_LIBS} ${OpenCV_LIBRARIES})

set_property(TARGET ${PROJECT_NAME} PROPERTY CUDA_ARCHITECTURES 50 61 72 75)
target_compile_options(${PROJECT_NAME} PUBLIC 
   $<$<COMPILE_LANGUAGE:CUDA>:--default-stream per-thread -lineinfo; --use_fast_math --disable-warnings>)
  
add_executable(app_yolov8 app_yolov8.cpp yolov8.cpp decode_yolov8.cu ${TensorRT_ROOT}/samples/common/logger.cpp)
#add_executable(app_yolov8)
file(GLOB sources ../utils/*.cpp ../utils/*.h ../utils/*.cu)
target_sources(app_yolov8 PUBLIC ${sources})


#target_include_directories(app_yolov8 PUBLIC ../utils)
#target_include_directories()
file(GLOB linklibraries C:/ProgramData/TensorRT-8.6.1.6/lib/*.lib)
#target_link_libraries(app_yolov8 PUBLIC ${linklibraries})
target_sources(app_yolov8 PUBLIC ${sources})
target_link_libraries(app_yolov8 ${ALL_LIBS} ${OpenCV_LIBRARIES} ${linklibraries})

target_link_directories(app_yolov8 PUBLIC "C:/ProgramData/TensorRT-8.6.1.6/lib")
include_directories("C:/ProgramData/TensorRT-8.6.1.6/include")

# NVCC
# target_link_libraries(detect ${PROJECT_NAME} ${ALL_LIBS} ${OpenCV_LIBRARIES} libgflags_nothreads.a)
#message(STATUS ***all_libs*** = ${ALL_LIBS})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant