cmake undefined reference

时间:2013-01-14 21:30:16

标签: cmake undefined-reference

我正在使用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文件但是我想清理代码库时编译得很好。

0 个答案:

没有答案