简体   繁体   中英

CMake cannot find source file

I am trying to configure PCL With visual studio but I am facing an error when using cmake. I am using pcl 1.8 with VS 2013 and cmake 3.14. I could successfully did the configuration step but when I move to generate, I do face add_executable error.

this is my cmakelists

cmake_minimum_required(VERSION 2.8 FATAL_ERROR) 
project(cloud_viewer)

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS}) 
link_directories(${PCL_LIBRARY_DIRS}) 
add_definitions(${PCL_DEFINITIONS})

add_executable (cloud_viewer cloud_viewer.cpp) 
target_link_libraries (cloud_viewer ${PCL_LIBRARIES})

This is the error I get:

CMake Error at CMakeLists.txt:11 (add_executable): Cannot find source file: cloud_viewer.cpp Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error at CMakeLists.txt:11 (add_executable): No SOURCES given to target: cloud_viewer


Image that shows both CMakelists.txt and cloud_viewer being in the same folder

[在此处输入图片说明

Could anyone help me solving it. thanks in advance.

Looking at your screenshot, you should name your file cloud_viewer.cpp , not cloud_viewer.ccp . Be careful about the extension: cpp vs ccp


On a side note, try using the cmake taget based system instead of the directory based:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR) 
project(cloud_viewer)

find_package(PCL 1.2 REQUIRED)

add_executable(cloud_viewer cloud_viewer.cpp) 
target_link_libraries(cloud_viewer PUBLIC ${PCL_LIBRARIES})
target_compile_definitions(cloud_viewer PUBLIC ${PCL_DEFINITIONS})
target_include_directories(cloud_viewer PUBLIC ${PCL_INCLUDE_DIRS})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM