1

我正在使用 cmake 来构建我的项目,但我收到了这些错误。

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

我很困惑为什么这些函数在用 PointSet.cxx 编写时是未定义的。下面是我的 CMakeLists.txt 文件。目前 PointSet.h、PointSet.cxx 和 LAS2VTK.cxx 都在同一个文件夹中,但我可能会更改它。

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()

当我在 PointSet.h 文件中有函数定义并且没有 PointSet.cxx 文件但我想清理代码库时,它编译得很好。

4

0 回答 0