This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

"multiple definition of " and "undeclared here (not in a function); did you mean" errors when including nvs library

Hi,

I am getting errors when attempting to include the nvs library to save data to flash storage on the nRF9160 DK. My CMakeLists.txt:

cmake_minimum_required(VERSION 3.13.1)

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(sample)

target_sources(app PRIVATE src/main.c)
#target_include_directories(app PRIVATE $ENV{ZEPHYR_BASE}/subsys/fs/nvs)

I get the same errors with or without the last line commented out. Errors:

When attempting to include the nvs library in the src folder of a project, I get these errors:

With this CMakeLists.txt:

#
# Copyright (c) 2019 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#

cmake_minimum_required(VERSION 3.13.1)

include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(project)

target_sources(app PRIVATE src/main.c)

#libraries
zephyr_include_directories(src)

target_sources(app PRIVATE src/call/maincall.c)
target_sources(app PRIVATE src/nvs/nvs.c)

Also, there a detailed tutorial or guide on including files and libraries into projects? If not, it would be very useful for one to exist. 

Thanks

  • Hello, 

    I am getting errors when attempting to include the nvs library to save data to flash storage on the nRF9160 DK

     Have you looked at the NVS example that is available in the Zephyr tree (zephyr\samples\subsys\nvs\)? Does this give the same errors?

    Edit: Pay especially attention to the NVS flags in prj.conf file (zephyr\samples\subsys\nvs\prj.conf). This should include the correct libraries in your project.

    Edit 2: Have a look at the Zephyr documentation, especially the section regarding Application Configuration

    Kind regards,

    Øyvind

  • Hi Øyvind, thanks for the response.

    I have looked at the nvs example in the Zephyr, and it builds correctly with no errors. I noticed copying the same files from the nvs example to a new folder in another location still builds with no errors. However, attempting to import the nvs library into other existing projects still causes the above issues. 

    The prj.conf file of my first program (with the "multiple definition" errors) contains that of the prj.conf file of the nvs example.

    The prj.conf file of my second program did not have the content from the prj.conf file from the nvs example. Copying the content from the nvs example prj.conf into the file for the second program replaced the "undeclared here" errors with the "multiple definition" errors I was having with my first program.

    Thank you for the documentation suggestion. Upon reading the Application Configuration section and examining the projects I have, everything seems to be configured correctly.

  • One thing I forgot to suggest what happens if you remove the following from you CMakeLists.txt?

    target_sources(app PRIVATE src/call/maincall.c)
    target_sources(app PRIVATE src/nvs/nvs.c)

    The prj.conf should handle all the files you need to include, especially if they are already part of the NCS distribution.

  • Just tried this and got the same errors. I remember reading on another ticket (How to include library in nRF9160?) that included files must be declared in CMakeLists.txt - is this an exception?

  • Hello,

    jlienau03 said:
    I remember reading on another ticket (How to include library in nRF9160?) that included files must be declared in CMakeLists.txt - is this an exception?

    No, there is no exception. In the case you are linking, the user wanted to include his own files. These need to be included via CMakeLists.txt See Modifying a sample application in NCS documentation for more information.

    In your case, you are using libraries included in NCS, and you should only need to add

    CONFIG_NVS=y
     to prj.conf. 
    This can also be done in SES via Project -> Config nRF Connect SDK project, and then search for NVS in "filter". 

    jlienau03 said:
    Just tried this and got the same errors.

     Did you rebuild the project?

    Edit: Also, see our nRF Connect SDK Tutorial, which covers the basics of building an nRF9160 application in the nRF Connect SDK.

Related