c++ - CLion can't find CMake generated headers? -


going through cmake tutorial:

├── cmakelists.txt ├── src │   └── main.cpp └── templates     └── fooconf.h.in 

cmakelists.txt

cmake_minimum_required(version 3.2) project(foo)  set(cmake_cxx_flags "${cmake_cxx_flags} -std=c++11")  set(project_source_dir src) set(project_template_dir templates)  set(source_files ${project_source_dir}/main.cpp) set(${project_name}_major 0) set(${project_name}_minor 1) set(${project_name}_micro 1) configure_file (   "${project_template_dir}/fooconf.h.in"   "${project_source_dir}/fooconf.h" )  add_executable(foo ${source_files}) 

templates/fooconf.h.in

#define @project_name@_version_major @project_name@@_version_major@ #define @project_name@_version_minor @project_name@@_version_minor@ #define @project_name@_version_micro @project_name@@_version_micro@ 

src/main.cpp

#include <iostream>  #include "src/fooconf.h" // tried: "fooconf.h"  int main() {     std::cout << foo_version_major;     return 0; } 

[error]

fatal error: src/fooconf.h: no such file or directory 

your fooconf.h header file generated in binary tree (precisely, under ${cmake_binary_dir}/src/). should issue corresponded include_directories() command use file in #include. e.g.:

cmakelists.txt

.... include_directories(${cmake_binary_dir}) add_executable(foo ${source_files}) 

src/main.cpp

.... #include "src/fooconf.h" 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -