cmake undefined reference

有些话、适合烂在心里 提交于 2020-04-16 06:46:14

问题


I am using cmake to build my project, but I am getting these errors.

Scanning dependencies of target las2vtk
[ 50%] Building CXX object CMakeFiles/las2vtk.dir/LAS2VTK.cxx.o
[100%] Building CXX object CMakeFiles/las2vtk.dir/PointSet.cxx.o
Linking CXX executable las2vtk
CMakeFiles/las2vtk.dir/LAS2VTK.cxx.o: In function `main':
LAS2VTK.cxx:(.text+0xf1): undefined reference to `PointSet<PointND<3, float> >::read_LAS(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, int)'
LAS2VTK.cxx:(.text+0x104): undefined reference to `PointSet<PointND<3, float> >::write_VTK(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
collect2: ld returned 1 exit status
make[2]: *** [las2vtk] Error 1
make[1]: *** [CMakeFiles/las2vtk.dir/all] Error 2
make: *** [all] Error 2

I am confused why those functions are undefined when they are written in PointSet.cxx. Below is my CMakeLists.txt file. Currently PointSet.h, PointSet.cxx, and LAS2VTK.cxx are all in the same folder, but I might change that.

cmake_minimum_required(VERSION 2.8)

PROJECT(las2vtk)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

set(SOURCES PointSet.cxx)

set(LASLIBS_INCLUDE "${CMAKE_MODULE_PATH}/lastools/laslib/inc")
set(LASLIBS_LIB "${CMAKE_MODULE_PATH}/lastools/laslib/lib")

include_directories(${LASLIBS_INCLUDE})
link_directories(${LASLIBS_LIB})
set(LASLIBS las)

add_executable(las2vtk LAS2VTK.cxx ${SOURCES})

target_link_libraries(las2vtk ${LASLIBS})

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

if(VTK_LIBRARIES)
  target_link_libraries(las2vtk ${VTK_LIBRARIES})
else()
  target_link_libraries(las2vtk vtkHybrid )
endif()

It compiled just fine when I had my function definitions within my PointSet.h file and had no PointSet.cxx file but I wanted to clean up the code base.

来源:https://stackoverflow.com/questions/14327052/cmake-undefined-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!