Profactor / cv-plot

fast modular opencv plotting library
MIT License
157 stars 29 forks source link

My project have included the header files, but cannot find the implement files. How should I write CMakeLists.txt #12

Closed cia1099 closed 4 years ago

cia1099 commented 4 years ago

Hi, I write my project CMakeLists.txt as

cmake_minimum_required(VERSION 3.10.0)
project(myproject)
# OpenCV
find_package(OpenCV 4 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
# CVPlot
include_directories("/home/cia1099/Program_Files/cv-plot/CvPlot/inc")
add_executable(myproject main.cpp)
target_link_libraries(myproject ${OpenCV_LIBS})

The Cmake configuration and generation can be done, and the context of "#include <CvPlot/cvplot.h>" can be find in main.cpp I am sure that the functions of cvplot.h have been declared and there is codeIntelligent support in my IDE. But when I was building myproject, there are errors which show:

... undefined reference to `CvPlot::plot(cv::_InputArray const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
[build] /bin/ld: main.cpp:(.text+0x19f): undefined reference to `CvPlot::Axes::render(int, int) const'
[build] /bin/ld: main.cpp:(.text+0x372): undefined reference to `CvPlot::Axes::~Axes()'
[build] /bin/ld: main.cpp:(.text+0x43e): undefined reference to `CvPlot::Axes::~Axes()'
[build] clang: error: linker command failed with exit code 1 (use -v to see invocation)
...

I wonder know how to write CMakeLists.txt to get these implementation code such as "*.ipp" files to get successful building?

wpalfi commented 4 years ago

Add

#define CVPLOT_HEADER_ONLY

to your main.cpp before including cvplot. Or add

target_compile_definitions(myproject PUBLIC CVPLOT_HEADER_ONLY)

to your CMakeLists.txt.

Sorry, This was missing in the documentation.