[Solved]-Issue regarding CMake Error: No source given to target-C++
For me (came here from Google), this error occurred when CMake target_sources had only PRIVATE sources, and no PUBLIC sources.
I had to make at least one PUBLIC source file:
target_sources($ PRIVATE External/dbscan.cpp main.cpp )
target_sources($ PRIVATE External/dbscan.cpp PUBLIC main.cpp )
The error says what it means: there are no sources for libraries.
#adding entries for lib_third_party_ti_mmcsdlib include_directories("$/lib/third_party/ti/mmcsdlib") include_directories("$/lib/third_party/ti/mmcsdlib/include") add_library(lib_third_party_ti_mmcsdlib "") # NO SOURCES HERE. target_compile_definitions(lib_third_party_ti_mmcsdlib PRIVATE -DBOOT=MMCSD -DCONSOLE=UARTCONSOLE ) subdirs("$/lib/third_party/ti/mmcsdlib") subdirs("$/lib/third_party/ti/mmcsdlib/include")
You should read the docs about add_library in cmake. If you don’t provide any source files, you should declare it as INTERFACE
In this case no compilation target would be generated. Otherwise, you can declare it as IMPORTED , then cmake will not try to create a target for compilation either.
For SHARED , STATIC or OBJECT you always need to supply sources.
You should check ProjectIncludes.cmake for what you really want to do: compile new libs or import them.
Sergey Kolesnik 2432
Related Query
- Issue regarding CMake Error: No source given to target
- CMake error — Target foo INTERFACE_SOURCES property contains path which is prefixed in the source directory
- Cmake link library target link error
- ‘ /usr/lib/i386-linux-gnu/qt5/bin/lrelease: not found WARNING: TARGET is empty’ Error when trying to compile Feathercoin from source
- opencv ubuntu 12.04 Cmake error : Source directory does not appear to contain CmakeLists.txt
- How to configure cmake to recompile a target when a non .cpp source file is modified
- cmake error «CMake Error: The source directory «. /p4c/build/[-DCMAKE_BUILD_TYPE=RELEASE» does not exist
- CMake add_subdirectory given source which is not an existing directory
- Add some header dependencies of source files to solution explorer for cmake target
- linking error with cmake project for bare metal target
- OpenCV CLion (Cmake) linking issue — cmake reports a strange error
- No soucers given to target error when adding sources in pybind11 and C++
- CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
- CMake with include and source paths — basic setup
- Template issue causes linker error (C++)
- CMake: target_include_directories() prints an error when I try to add the source directory itself, or one of its subdirectories
- How to read a CMake Variable in C++ source code
- CMake error no CMAKE_C_COMPILER could be found using Xcode and GLFW
- How do I add valgrind tests to my cmake «test» target
- linking problem: fatal error LNK1112: module machine type ‘x64’ conflicts with target machine type ‘X86’
- CMake add target for invoking clang analyzer
- «No source available for main()» error when debugging simple C++ in Eclipse with gdb
- Boost.Log with CMake causing undefined reference error
- cmake include header into every source file
- CMake Error: «add_subdirectory not given a binary directory»
- Copying assets directory from source to build directory in CMake
- CUDA compilation issue with CMake
- *** No rule to make target ‘class.cpp’, needed by `build/. x86/class.o` Stop. error in Ubuntu
- CMake add_executable target name is reserved
- CMake cannot find source file (add_executable)
More Query from same tag
- Why is this variadic function ambiguous?
- seekg cannot handle file of 4294967295 bytes properly
- Tokenizing an arithmetic expression?
- std::sort does not always call std::swap
- Is it possible to use explicit register variables in GCC with C++17?
- What is a Direct X Virtual Table?
- How to fix implicit conversion warnings?
- C++ Explanation for this delete[] Error?
- Multiple inheritance with the same variable name in the classes
- Assembly and template classes
- Qt equivalent to boost::ptr_vector?
- Comparing two int arrays in C
- How to compile WebAssembly into regular assembly / native code (or Cpp, etc)?
- How to use string::find to find either «+» or «-» in one operation
- Once an array-of-T has decayed into a pointer-to-T, can it ever be made into an array-of-T again?
- In C++, does adding a friend to a class change its memory layout?
- Server Design and Implementation
- C++ skipping functions
- What the author is trying to say in GotW #53?
- Why doesn’t an if constexpr make this core constant expression error disappear?
- Fill a C++ array with numbers according to a pattern
- Difference between pair of consts and const pair
- Why does the compiler warn about uninitialized edge iterator in some optimization levels?
- How to restrict template class to only specific specializations with type aliases
- When do I use std::random_device?
- Reference to «class» is ambigous
- Bad address in cv::Mat
- Lua get function from argument
- Why do I need static here?
- Can’t initialize OpenGL
Почему CMake не находит исходники?
Структура проекта:
CMakeLists.txt
cmake_minimum_required(VERSION 3.2) project(2DPrimitive CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) #add_subdirectory(tests/googletest) add_subdirectory(source)
cmake_minimum_required(VERSION 3.2) project(2DPrimitive) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(PROJECT_VERSION_MAJOR 0) set(PROJECT_VERSION_MINOR 1) set(SOURCES Point.cpp Window.cpp) set(HEADERS Point.hpp Window.hpp) set(EXTERN_LIBS ExternalDependencies/lib/libglad.a ExternalDependencies/lib/libglfw3.a) add_library(2DPrimitive STATIC $(SOURCES) $(HEADERS)) target_link_libraries(2DPrimitive $) set_target_properties(2DPrimitive PROPERTIES OUTPUT_NAME 2DPrimitive VERSION $.$ SOVERSION $ POSITION_INDEPENDENT_CODE ON FOLDER "../lib/")
CMake Error at source/CMakeLists.txt:23 (add_library): Cannot find source file: $(SOURCES) Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc CMake Error at source/CMakeLists.txt:23 (add_library): No SOURCES given to target: 2DPrimitive
Простой 1 комментарий
Во вложенных cmakelists.txt не нужно вновь объявлять проект и свойства компилятора, это все наследуется от вышестоящего листа. Имею ввиду эти строки:
cmake_minimum_required(VERSION 3.2) project(2DPrimitive) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(PROJECT_VERSION_MAJOR 0) set(PROJECT_VERSION_MINOR 1)
Возможно проблема связана с этим.
Обычно в головном cmakelists.txt устанавливаются все необходимые глобальные свойства для проекта, типа: версии стандарта, поиск внешних библиотек, дополнительные опции компилятора и т.п.
Во вложенных листах просто определяете соответсвующие цели, используя все то что уже объявлено в вышестоящем листе (и возможно в других вложенных листах).
No sources given to target main cpp
First time here? Check out the FAQ!
I am trying to compile a custom package but I am getting some errors with CMake. The error is the following:
-- +++ processing catkin package: 'kate_global' -- ==> add_subdirectory(kate_global) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy -- kate_global: 2 messages, 0 services -- Configuring done CMake Error at kate_global/CMakeLists.txt:140 (add_executable): Cannot find source file: catkin::rosconsole::wrapped-linker-option0 Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx CMake Error at kate_global/CMakeLists.txt:140 (add_executable): No SOURCES given to target: control_node_kate -- Build files have been written to: /home/pi/catkin_ws/build Invoking "cmake" failed
I don’t know what is wrong so I attach here CMakeLists and the directory of the files of executables:
cmake_minimum_required(VERSION 2.8.3) project(kate_global) find_package(catkin REQUIRED COMPONENTS controller_manager diff_drive_controller roscpp rospy message_generation std_msgs move_base ) add_message_files( FILES enc_msg.msg CAN.msg ) generate_messages( DEPENDENCIES std_msgs ) catkin_package() include_directories(include $) add_executable( control_node_kate src/kate_control_loop.cpp src/kate_hw_interface.cpp $ ) target_link_libraries( control_node_kate $ ) install(TARGETS control_node_kate RUNTIME DESTINATION $ )
pi@raspberrypi:~/catkin_ws/src/kate_global/src $ ls -l total 12 -rwxrwxrwx 1 pi pi 2450 Jun 11 12:53 kate_control_loop.cpp -rwxrwxrwx 1 pi pi 8060 Jun 11 13:17 kate_hw_interface.cpp
I am working on Raspberry Pi OS (64 bits) using ROS Noetic.
Почему CMake не находит исходники?
Структура проекта:
CMakeLists.txt
cmake_minimum_required(VERSION 3.2) project(2DPrimitive CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) #add_subdirectory(tests/googletest) add_subdirectory(source)
cmake_minimum_required(VERSION 3.2) project(2DPrimitive) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(PROJECT_VERSION_MAJOR 0) set(PROJECT_VERSION_MINOR 1) set(SOURCES Point.cpp Window.cpp) set(HEADERS Point.hpp Window.hpp) set(EXTERN_LIBS ExternalDependencies/lib/libglad.a ExternalDependencies/lib/libglfw3.a) add_library(2DPrimitive STATIC $(SOURCES) $(HEADERS)) target_link_libraries(2DPrimitive $) set_target_properties(2DPrimitive PROPERTIES OUTPUT_NAME 2DPrimitive VERSION $.$ SOVERSION $ POSITION_INDEPENDENT_CODE ON FOLDER "../lib/")
CMake Error at source/CMakeLists.txt:23 (add_library): Cannot find source file: $(SOURCES) Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc CMake Error at source/CMakeLists.txt:23 (add_library): No SOURCES given to target: 2DPrimitive
Простой 1 комментарий
Во вложенных cmakelists.txt не нужно вновь объявлять проект и свойства компилятора, это все наследуется от вышестоящего листа. Имею ввиду эти строки:
cmake_minimum_required(VERSION 3.2) project(2DPrimitive) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(PROJECT_VERSION_MAJOR 0) set(PROJECT_VERSION_MINOR 1)
Возможно проблема связана с этим.
Обычно в головном cmakelists.txt устанавливаются все необходимые глобальные свойства для проекта, типа: версии стандарта, поиск внешних библиотек, дополнительные опции компилятора и т.п.
Во вложенных листах просто определяете соответсвующие цели, используя все то что уже объявлено в вышестоящем листе (и возможно в других вложенных листах).