0

I have following folder structure

-include->Header.h
       ->kernel.h  
-kernel.cu  
-Source.cpp

Now, Header.h here is public header and kernel.h is private. Source.cpp has a function which calls a function from kernel.cu and includes both the include files.

Source.cpp

#include "Header.h"
#include "kernel.h"
void getAverage(std::deque<cv::Mat> data, int numOfMats, cv::Mat& result)
{
    computeAverage(data, numOfMats, result); //Umesh: here you should directly call renamed main function from kernel.cu
}

Header.h

#include <iostream>
#include <deque>
#include <opencv2/core/mat.hpp>
using namespace std;
void getAverage(std::deque<cv::Mat> data, int numOfMats, cv::Mat& result);

Now, the kernel.cu has the logic of computeAverage().

I wanted to create a library of this code, so I have written a CMake for this:

cmake_minimum_required (VERSION 3.9)
project(AverageLib LANGUAGES CXX CUDA)

find_package(CUDA 11.6 REQUIRED)

set(CMAKE_PREFIX_PATH "C:/OpenCV/opencv/build")

find_package(OpenCV REQUIRED COMPONENTS core imgproc highgui)
include_directories(${OpenCV_INCLUDE_DIRS})

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
add_library(AverageLib SHARED kernel.cu Source.cpp)

install(TARGETS AverageLib DESTINATION lib)
install(FILES include/Header.h include/kernel.h DESTINATION include)

After running the cmake it installs library in my C drive. But when I want to test it, I created a sample cpp file which calls getAverage() function and I linked the installed include folder and library, also linked the library in linker.

But it does not work, I get following error

Error   LNK2019 unresolved external symbol "void __cdecl getAverage(class std::deque<class cv::Mat,class std::allocator<class cv::Mat> >,int,class cv::Mat &)"

I am not sure what wrong I am doing, can you please help?

Thank you in advance.

UmeshP
  • 1
  • 1

0 Answers0