0

I have the following meson commands that installs a .db file into 'datadir' / 'database'.

install_data('data/database/product.db',
install_dir :
get_option('datadir') / 'database')

It all works well. But what I want to do now is access that file from my c source code. I have read here that one way to do it is to generate a configuration .h file which contains a definition for the path of pckdatadir: Meson working with data/assets and portable/relative paths

I have added these few lines to acheive that:

pkgdatadir = get_option('datadir')
conf = configuration_data()
conf.set_quoted('PACKAGE_DATADIR', join_paths(get_option('prefix'), pkgdatadir))
configure_file(
  output: 'config.h',
  configuration: conf
)

And the header file it generates is this:

/*
 * Autogenerated by the Meson build system.
 * Do not edit, your changes will be lost.
 */

#pragma once

#define PACKAGE_DATADIR "/app/share"

This doesn't really help much. Whenever I try to open my database file location using this PACKAGE_DATADIR path it righly says there is no such directory. Is there a way I can have access to the actual path of the file I have bundled with the project so that I can use it in code? Is there another way to approach this problem? Thanks for reading.

Vahan
  • 166
  • 13
  • This is little confusing. You want to hard code your database path created by build system in your source? Why don't you just provide that location in runtime? – Elvis Oric Jan 02 '21 at 12:31
  • how do you open the file, e.g. how do you build pathname that you use in "open", have you checked if file is installed ? – pmod Jan 02 '21 at 23:06

0 Answers0