Defining the path for multiple files

Hello,

I am starting to work on a sample project, wherein I need to include multiple C++ files, all present under a common folder.
Can I define that common file path under a variable like "app_sources", so that in CMakelists.txt I can define as: 

target_sources(app PRIVATE
  ${app_sources/sample.cpp}
  )

where can I define this path "app_sources"..?

I am using nRF Connect extension on VScode.

Parents
  • Hi,

    Here is an example of how to set and use a variable as part of a path:

    set(MY_APP_SOURCES C:/ncs/v1.7.0/zephyr/samples/hello_world/src)
    
    target_sources(app PRIVATE ${MY_APP_SOURCES}/main.c)

  • Hello ,

    Thanks for clearing this up, an extension to this query is, 

    How to resolve SDK file inclusion errors in main.cpp:

    For example, I am using the same hello_world sample app, where I added main.cpp by excluding main.c
    And copying contents of main.c into main.cpp

    Now I am getting the below error in main.cpp:

     my CMakeLists.txt looks like this:

    # SPDX-License-Identifier: Apache-2.0
    
    cmake_minimum_required(VERSION 3.20.0)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(hello_world)
    #src/main.c
    target_sources(app PRIVATE D:/CPP_Test/cpp_files/main.cpp)

    Kindly help me in solving this.!

Reply
  • Hello ,

    Thanks for clearing this up, an extension to this query is, 

    How to resolve SDK file inclusion errors in main.cpp:

    For example, I am using the same hello_world sample app, where I added main.cpp by excluding main.c
    And copying contents of main.c into main.cpp

    Now I am getting the below error in main.cpp:

     my CMakeLists.txt looks like this:

    # SPDX-License-Identifier: Apache-2.0
    
    cmake_minimum_required(VERSION 3.20.0)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(hello_world)
    #src/main.c
    target_sources(app PRIVATE D:/CPP_Test/cpp_files/main.cpp)

    Kindly help me in solving this.!

Children
Related