hyperrealm / libconfig Goto Github PK
View Code? Open in Web Editor NEWC/C++ library for processing configuration files
Home Page: https://hyperrealm.github.io/libconfig/
License: GNU Lesser General Public License v2.1
C/C++ library for processing configuration files
Home Page: https://hyperrealm.github.io/libconfig/
License: GNU Lesser General Public License v2.1
Sometimes I get the error "input in flex scanner failed" and by application exits. What can lead to this error and how could it ne catched?
In the latest version and release 1.6, LIBCONFIG{XX}_VER_MINOR is still defined to 5, making it difficult to check for an installed version.
For example, release 1.5 throws a linker error when the following code is compiled:
#include <string>
#include <libconfig.h++>
int main() {
std::string s = libconfig::Config().lookup("");
return 0;
}
undefined reference to `libconfig::Setting::operator std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >[abi:cxx11]() const'
This is with GCC 5.2.1. The same links fine with libconfig 1.6.
Please add a function to add new paths instead of simple child settings. Example: add("database.sql.port", TypeInt)
From the library website, I've found this config file example.
I'd like to know what kind of file format is that, if it's standardized or if it's a format you've just come up with for use in libconfig.
It would be convenient if the Config
class had a constructor taking a std::string
instead of having to construct it and then on the next line call readFile()
. What are your thoughts on this?
Hello,
I'm working on including this library to Tizen OS (www.tizen.org, www.review.tizen.org) and I find out that there is no tags in your repository which could show where each release has been made. Please consider creating such tags (at least for last release) it will help us to use gbs to build your code using upstream branch.
Thank you in advice
I can workaround the build failure below by touching lib/scanner.l
or just deleting lib/scanner.c
, which implies that those generated files need to be regenerated to prevent build failures. Also, there's a parallelization bug. If I run cd lib ; make maintainer-clean-generic ; make
it will fail unless I instead do cd lib ; make maintainer-clean-generic ; make -j1
.
==> make install
Making install in lib
/Applications/Xcode.app/Contents/Developer/usr/bin/make install-am
CC libconfig_la-libconfig.lo
CC libconfig_la-scanner.lo
CC libconfig_la-grammar.lo
CC libconfig_la-scanctx.lo
CC libconfig_la-strbuf.lo
CC libconfig___la-libconfig.lo
CC libconfig___la-scanner.lo
CC libconfig___la-grammar.lo
CC libconfig___la-scanctx.lo
CC libconfig___la-strbuf.lo
CXX libconfig___la-libconfigcpp.lo
scanner.l:137:59: error: too few arguments to function call, expected 4, have 3
&error);
^
./scanctx.h:66:1: note: 'scanctx_push_include' declared here
extern FILE *scanctx_push_include(struct scan_context *ctx, void *prev_buffer,
^
scanner.l:137:59: error: too few arguments to function call, expected 4, have 3
&error);
^
./scanctx.h:66:1: note: 'scanctx_push_include' declared here
extern FILE *scanctx_push_include(struct scan_context *ctx, void *prev_buffer,
^
1 error generated.
1 error generated.
make[2]: *** [libconfig_la-scanner.lo] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [libconfig___la-scanner.lo] Error 1
make[1]: *** [install] Error 2
make: *** [install-recursive] Error 1
/usr/local/Library/Homebrew/debrew.rb:11:in `raise'
BuildError: Failed executing: make install
We have in libconfig-1.6/lib/Makefile.am:
VERINFO = -version-info 11:1:3 (leading to libconfig++.so.8.3.1)
and in libconfig-1.6/lib/Makefile.in:
VERINFO = -version-info 11:0:2 (leading to libconfig.so.9.2.0)
It is considered bad style to have throw specifications on functions. There are several discussions on this (http://herbsutter.com/2007/01/24/questions-about-exception-specifications/, http://stackoverflow.com/questions/1055387/throw-keyword-in-functions-signature-c).
I am attempting to build libconfig using VS2013. After opening the provided .sln it goes through a conversion step to bring it up to 2013 format. That goes well enough.
The build of libconfig library fails as <sys/stat.h>
on Windows doesn't contain a definition for S_ISDIR
which is called in libconfig.c
in config_read_file()
.
I am able to coerce a build out of it by changing that line to if (!(statbuf.st_mode & S_IFDIR) != 0)
The examples all seem to work fine with this change.
(I could not install the latest version of libconfig (I got same problem here #53 ). I am using version 1.5 which has been installed by command line sudo apt-get install libconfig-dev
)
undefined reference to 'config_setting_lookup'
examples/example.cfg
and example/example1.c
to have many authors for a book:examples/example.cfg
books = ( { title = "Treasure Island";
author = ["Robert Louis Stevenson","Nobody"];
price = 29.99;
qty = 5; },
{ title = "Snow Crash";
author = ["Neal Stephenson"];
price = 9.99;
qty = 8; }
);
example/example1.c
config_setting_t *authors = config_setting_lookup(book, "author", &author);
if(!(config_setting_lookup_string(book, "title", &title)
&& author
&& config_setting_lookup_float(book, "price", &price)
&& config_setting_lookup_int(book, "qty", &qty)))
continue;
P/S: In the source code (version 1.5 I have grabbed here: https://launchpad.net/ubuntu/+source/libconfig/1.5-0.2 ), I could see there is config_setting_lookup
function: libconfig.h:270
and libconfig.c:1189
Hi, it would be nice if we could reuse a variable already defined in settings to set another.
Ex:
a = 1;
b = 1;
c = a + b;
Currently, to lookup a setting from a Config
object, one must use the lookup()
method, but for looking up a setting from a Setting
object, one must use operator[]
. It would make more sense if both classes implemented both ways of looking up settings so the interface is consistent between them.
The modification would be quite simple as each class could delegate the call to the method that is already implemented, or to keep the code clean, move the implementation to the lookup()
method in both classes and then have operator[]
invoke lookup()
.
In libconfig-1.5/build/share/config.site:
CXXFLAGS="-stdlib=libstdc++"
CPPFLAGS="-stdlib=libstdc++"
LDFLAGS="-stdlib=libstdc++"
Pass ./configure:
jiachen@toro:~/libconfig-1.5$ ./configure --prefix=$(pwd)/build
configure: loading site script /Users/jiachen/libconfig-1.5/build/share/config.site
checking build system type... x86_64-apple-darwin14.0.0
checking host system type... x86_64-apple-darwin14.0.0
checking target system type... x86_64-apple-darwin14.0.0
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... aux-build/install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
configure: libconfig - made with pride in California
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm
checking the name lister (/usr/bin/nm) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 196608
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-apple-darwin14.0.0 file names to x86_64-apple-darwin14.0.0 format... func_convert_file_noop
checking how to convert x86_64-apple-darwin14.0.0 file names to toolchain format... func_convert_file_noop
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld option to reload object files... -r
checking for objdump... no
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... no
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm output from gcc object... ok
checking for sysroot... no
checking for mt... no
checking if : is a manifest tool... no
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking for gcc option to produce PIC... -fno-common -DPIC
checking if gcc PIC flag -fno-common -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin14.0.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
checking whether the g++ linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking for g++ option to produce PIC... -fno-common -DPIC
checking if g++ PIC flag -fno-common -DPIC works... yes
checking if g++ static flag -static works... no
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin14.0.0 dyld
checking how to hardcode library paths into programs... immediate
checking for flex... flex
checking lex output file root... lex.yy
checking lex library... -ll
checking whether yytext is a pointer... yes
checking for bison... bison -y
checking for compiler switch to enable full C/C++ warnings... -Wall -Wshadow -Wextra -Wdeclaration-after-statement -Wno-unused-parameter, -Wall -Wshadow -Wextra -Wno-unused-parameter
checking for ANSI C header files... (cached) yes
checking for unistd.h... (cached) yes
checking for stdint.h... (cached) yes
checking xlocale.h usability... yes
checking xlocale.h presence... yes
checking for xlocale.h... yes
checking for an ANSI C-conforming const... yes
checking for newlocale... yes
checking for uselocale... yes
checking for freelocale... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating lib/Makefile
config.status: creating lib/libconfig.pc
config.status: creating lib/libconfig++.pc
config.status: creating doc/Makefile
config.status: creating examples/Makefile
config.status: creating examples/c/Makefile
config.status: creating examples/c++/Makefile
config.status: creating tinytest/Makefile
config.status: creating tests/Makefile
config.status: creating libconfig.spec
config.status: creating ac_config.h
config.status: ac_config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands
jiachen@toro:~/libconfig-1.5$
When "make":
libtool: compile: g++ -DHAVE_CONFIG_H -I. -I.. -DPARSER_PREFIX=\"libconfig_yy\" -D_REENTRANT -stdlib=libstdc++ -stdlib=libstdc++ -Wall -Wshadow -Wextra -Wno-unused-parameter -MT libconfig___la-libconfigcpp.lo -MD -MP -MF .deps/libconfig___la-libconfigcpp.Tpo -c libconfigcpp.c++ -fno-common -DPIC -o .libs/libconfig___la-libconfigcpp.o
libtool: compile: g++ -DHAVE_CONFIG_H -I. -I.. -DPARSER_PREFIX=\"libconfig_yy\" -D_REENTRANT -stdlib=libstdc++ -stdlib=libstdc++ -Wall -Wshadow -Wextra -Wno-unused-parameter -MT libconfig___la-libconfigcpp.lo -MD -MP -MF .deps/libconfig___la-libconfigcpp.Tpo -c libconfigcpp.c++ -o libconfig___la-libconfigcpp.o >/dev/null 2>&1
mv -f .deps/libconfig___la-libconfigcpp.Tpo .deps/libconfig___la-libconfigcpp.Plo
/bin/sh ../libtool --tag=CXX --mode=link g++ -stdlib=libstdc++ -Wall -Wshadow -Wextra -Wno-unused-parameter -version-info 11:0:2 -no-undefined -stdlib=libstdc++ -o libconfig++.la -rpath /Users/jiachen/libconfig-1.5/build/lib libconfig___la-libconfig.lo libconfig___la-scanner.lo libconfig___la-grammar.lo libconfig___la-scanctx.lo libconfig___la-strbuf.lo libconfig___la-libconfigcpp.lo
libtool: link: g++ -dynamiclib -o .libs/libconfig++.9.dylib .libs/libconfig___la-libconfig.o .libs/libconfig___la-scanner.o .libs/libconfig___la-grammar.o .libs/libconfig___la-scanctx.o .libs/libconfig___la-strbuf.o .libs/libconfig___la-libconfigcpp.o -install_name /Users/jiachen/libconfig-1.5/build/lib/libconfig++.9.dylib -compatibility_version 12 -current_version 12.0 -Wl,-single_module
Undefined symbols for architecture x86_64:
"std::string::c_str() const", referenced from:
libconfig::SettingException::SettingException(libconfig::Setting const&) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, int) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, char const*) in libconfig___la-libconfigcpp.o
libconfig::Setting::operator=(std::string const&) in libconfig___la-libconfigcpp.o
"std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::str() const", referenced from:
libconfig::SettingException::SettingException(libconfig::Setting const&) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, int) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, char const*) in libconfig___la-libconfigcpp.o
libconfig::Setting::getPath() const in libconfig___la-libconfigcpp.o
"std::ostream::tellp()", referenced from:
libconfig::__constructPath(libconfig::Setting const&, std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >&) in libconfig___la-libconfigcpp.o
"std::ostream::operator<<(int)", referenced from:
libconfig::__constructPath(libconfig::Setting const&, std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >&) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, int) in libconfig___la-libconfigcpp.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()", referenced from:
libconfig::Setting::operator std::string() const in libconfig___la-libconfigcpp.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
libconfig::SettingException::SettingException(libconfig::Setting const&) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, int) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, char const*) in libconfig___la-libconfigcpp.o
libconfig::Setting::operator std::string() const in libconfig___la-libconfigcpp.o
"std::string::operator=(char const*)", referenced from:
libconfig::Config::lookupValue(char const*, std::string&) const in libconfig___la-libconfigcpp.o
libconfig::Setting::operator std::string() const in libconfig___la-libconfigcpp.o
libconfig::Setting::lookupValue(char const*, std::string&) const in libconfig___la-libconfigcpp.o
"std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream(std::_Ios_Openmode)", referenced from:
libconfig::SettingException::SettingException(libconfig::Setting const&) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, int) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, char const*) in libconfig___la-libconfigcpp.o
libconfig::Setting::getPath() const in libconfig___la-libconfigcpp.o
"std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_stringstream()", referenced from:
libconfig::SettingException::SettingException(libconfig::Setting const&) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, int) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, char const*) in libconfig___la-libconfigcpp.o
libconfig::Setting::getPath() const in libconfig___la-libconfigcpp.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
libconfig::__constructPath(libconfig::Setting const&, std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >&) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, int) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, char const*) in libconfig___la-libconfigcpp.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)", referenced from:
libconfig::__constructPath(libconfig::Setting const&, std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >&) in libconfig___la-libconfigcpp.o
libconfig::SettingException::SettingException(libconfig::Setting const&, char const*) in libconfig___la-libconfigcpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [libconfig++.la] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
jiachen@toro:~/libconfig-1.5$
Maybe this is caused by there is no "-stdlib=libstdc++" in this line.
libtool: link: g++ -dynamiclib -o .libs/libconfig++.9.dylib .libs/libconfig___la-libconfig.o .libs/libconfig___la-scanner.o .libs/libconfig___la-grammar.o .libs/libconfig___la-scanctx.o .libs/libconfig___la-strbuf.o .libs/libconfig___la-libconfigcpp.o -install_name /Users/jiachen/libconfig-1.5/build/lib/libconfig++.9.dylib -compatibility_version 12 -current_version 12.0 -Wl,-single_module
Undefined symbols for architecture x86_64:
For now, I just add this command to be:
g++ -dynamiclib -o .libs/libconfig++.9.dylib .libs/libconfig___la-libconfig.o .libs/libconfig___la-scanner.o .libs/libconfig___la-grammar.o .libs/libconfig___la-scanctx.o .libs/libconfig___la-strbuf.o .libs/libconfig___la-libconfigcpp.o -install_name /Users/jiachen/libconfig-1.5/build/lib/libconfig++.9.dylib -compatibility_version 12 -current_version 12.0 -Wl,-single_module -stdlib=libstdc++
And I get the dylib and use it in the project.
I also looked in to Makefile and Makefile.am, but did not find to problem.
Could you please tell me how to compile libconfig with libstdc++ on mac in the right way?
It would be nice to have an "update()" function on Setting that can replace the given property with a new one. Currently I have to remove() it first, then add() again. The downside of this approach is that the new property is appended at the end of the file, rather than at the position of the one that I'm replacing.
I cloned the repo, ran ./configure
then make
and I get the following error I have no idea what this issue is:
make[3]: Entering directory `/home/nigel/git/libconfig/lib'
CC libconfig_la-libconfig.lo
CC libconfig_la-scanner.lo
scanner.l: In function 'libconfig_yylex':
scanner.l:137:53: warning: passing argument 3 of 'scanctx_push_include' from incompatible pointer type [enabled by default]
char c[2] = { (char)(strtol(yytext + 2, NULL, 16) & 0xFF),
^
In file included from scanner.l:46:0:
scanctx.h:66:14: note: expected 'const char *' but argument is of type 'const char **'
extern FILE *scanctx_push_include(struct scan_context *ctx, void *prev_buffer,
^
scanner.l:137:53: error: too few arguments to function 'scanctx_push_include'
char c[2] = { (char)(strtol(yytext + 2, NULL, 16) & 0xFF),
^
In file included from scanner.l:46:0:
scanctx.h:66:14: note: declared here
extern FILE *scanctx_push_include(struct scan_context *ctx, void *prev_buffer,
^
make[3]: *** [libconfig_la-scanner.lo] Error 1
make[3]: Leaving directory `/home/nigel/git/libconfig/lib'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/nigel/git/libconfig/lib'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/nigel/git/libconfig'
make: *** [all] Error 2
Hi, I'm trying to build a static library with mingw (4.9.2) on windows with msys. I open msys env. with this build command line:
$ ./configure --prefix=c:/usr CFLAGS="-static -static-libgcc -static-libstdc++" CXXFLAGS="-static -static libgcc -static-libstdc++" LIBS="-lpthread" --disable-examples
These are the errors:
libconfig_tests-tests.o:tests.c:(.text+0x47): undefined reference to _imp__config_init' libconfig_tests-tests.o:tests.c:(.text+0x5c): undefined reference to
_imp__config_set_include_dir'
libconfig_tests-tests.o:tests.c:(.text+0x70): undefined reference to _imp__config_read_file' libconfig_tests-tests.o:tests.c:(.text+0xe7): undefined reference to
_imp__config_write_file'
libconfig_tests-tests.o:tests.c:(.text+0x1ef): undefined reference to _imp__config_destroy' libconfig_tests-tests.o:tests.c:(.text+0x207): undefined reference to
_imp__config_init'
libconfig_tests-tests.o:tests.c:(.text+0x21b): undefined reference to _imp__config_read_file' libconfig_tests-tests.o:tests.c:(.text+0x2b7): undefined reference to
_imp__config_destroy'
libconfig_tests-tests.o:tests.c:(.text+0x393): undefined reference to _imp__config_init' libconfig_tests-tests.o:tests.c:(.text+0x3a7): undefined reference to
_imp__config_read_string'
libconfig_tests-tests.o:tests.c:(.text+0x43c): undefined reference to `_imp__config_destroy'
any help?
HI this is more of a clarification request - than an issue.
Please do indulge me as I didn't find an IRC channel.
I'm trying to change some grammar rules in scanner.l and grammar.y - and try to regenerate grammar.[ch] and scanner.[ch](added new tokens and such.)
While grammar.[ch] - get generated during a make - the scanner.c doesn't. And I'm unable to figure how to re-generate scanner code. Can anyone please help me ?
I can see there is a new configure script. However, while trying to use it, I'm getting error:
config.status: error: cannot find input file: `Makefile.in'
hi
I compile libconfig use vs2015, errors: _S_ISDIR symbol not found!
Background: we have a build system based on Boost Build in a C++ code base. We have custom commands that allow building autotools targets within boost build such that we can just add them as dependencies for other projects. It works well in general, but does rely on the thirdparty projects being able to build successfully with ./configure --prefix=<absolute path to location in build system dir>
.
libconfig builds the library just fine but fails to build the tests due to this line: https://github.com/hyperrealm/libconfig/blob/master/tests/Makefile.am#L8
If I change -I../lib
to -I$(top_srcdir)/lib
, it works fine. Seems that is an oversight.
I can make a pull request if you like but I suspect it's as quick for you to make the change directly unless I've missed some reason that would be problematic.
Thanks for the great lib.
Hi,
I'm trying to link an application in c++ using libconfig.
When I try to do it static,
g++ -Wl,-subsystem,console -mthreads -o debug\Sim.exe object_script.Sim.Debug C:/MinGW/msys/1.0/local/lib/libconfig++.a
i get,
./debug\Confi.o: In function ZN12ConfiguradorC2EP9Sim': ./Confi.cpp:8: undefined reference to
_imp___ZN9libconfig6ConfigC1Ev'
And when I do it with the shared library,
g++ -Wl,-subsystem,console -mthreads -o debug\Sim.exe object_script.Sim.Debug C:/MinGW/msys/1.0/local/lib/libconfig++.dll.a
It links without errors.
Any help?
When I let a user set a new property to add to a setting, I don't know the type in advance. For example, the user may want to add the config setting balance=42, name="My Name", or loadPlugin=True. The problem is, when I go to store this property in a config file I need to supply a type according to the function definition Setting & add(const std::string &name, Setting::Type type).
Would it please be possible to add a function that selects the type automatically based on the new value that I want to store?
current config format is not so friendly ,for example when I try to write 1.57 using program, it will write something like 1.569876,so I plan to add printf like interface to libconfig,
such as
config_setting_t *pcs=config_settting_add(*flt,"pw",CONFIG_TYPE_FLOAT);
config_set_print_format("%.2f");
Will you accept that feature?
I suggest changing one line in libconfig documentation:
"Function: config_setting_t * config_root_setting (const config_t * config)
This function returns the root setting for the configuration config. "
into
"Function: config_setting_t * config_root_setting (const config_t * config)
This function, which is implemented as a macro, returns the root setting for the configuration config. "
Due to the Setting
class having a cast operator for char*
as well as std::string
, when assigning to a std::string
, the call is ambiguous. For example:
std::string str;
str = conf.lookup("someStringSetting");
fails to compile. The workaround currently is to call .c_str()
on the setting. I propose the removal of the cast to std::string
operator as the std::string
constructor already has an overload taking a char *
. What are your thoughts?
When I write a configuration to disk using "void writeFile(const char *filename);" comments are not preserved. This is a problem, because I'd like to edit files both with a text editor and libconfig (from a C++ program).
Is it possible to preserve comments?
In release 1.6, compiled on 32-bit Ubuntu with gcc 4.9.3:
Making all in tests
CC libconfig_tests-tests.o
tests.c: In function ‘BigInt5’:
tests.c:349:3: warning: this decimal constant is unsigned only in ISO C90
TT_ASSERT_INT64_EQ(llval, 2147483648);
^
tests.c: In function ‘BigInt6’:
tests.c:373:3: warning: this decimal constant is unsigned only in ISO C90
TT_ASSERT_INT_EQ(ival, -2147483648);
^
tests.c:377:3: warning: this decimal constant is unsigned only in ISO C90
TT_ASSERT_INT64_EQ(llval, -2147483648);
^
tests.c: In function ‘BigInt7’:
tests.c:407:3: warning: this decimal constant is unsigned only in ISO C90
TT_ASSERT_INT64_EQ(llval, -2147483649);
^
And running the tests:
$ make test
cd tests && ./libconfig_tests
[TEST] ParsingAndFormatting
parsing testdata/input_0.cfg
parsing testdata/input_1.cfg
parsing testdata/input_2.cfg
parsing testdata/input_3.cfg
parsing testdata/input_4.cfg
parsing testdata/input_5.cfg
parsing testdata/input_6.cfg
[ OK ] ParsingAndFormatting
[TEST] ParseInvalidFiles
[ OK ] ParseInvalidFiles
[TEST] ParseInvalidStrings
[ OK ] ParseInvalidStrings
[TEST] BigInt1
[ OK ] BigInt1
[TEST] BigInt2
[ OK ] BigInt2
[TEST] BigInt3
[ OK ] BigInt3
[TEST] BigInt4
[ OK ] BigInt4
[TEST] BigInt5
[ OK ] BigInt5
[TEST] BigInt6
tests.c:377: failed assert: (llval) [-2147483648] == (-2147483648) [2147483648]
[FAIL] BigInt6
[TEST] BigInt7
tests.c:407: failed assert: (llval) [-2147483649] == (-2147483649) [2147483647]
[FAIL] BigInt7
[TEST] RemoveSetting
[ OK ] RemoveSetting
*** FAILURES! ***
11 tests; 9 passed, 2 failed
Makefile:859: recipe for target 'test' failed
make: *** [test] Error 1
Adding an "LL" suffix to the offending constants clears up the problem(s).
Currently, all of the functions for the C++ wrapper take const char*
which causes a compiler error whenever you pass a std::string
which means that .c_str()
must be called on any string passed to one of these functions. By changing all functions to take a std::string
and then calling .c_str()
internally when passing the string to the C API, it would make the usage of the library much cleaner.
Since Version 1.7 won't build due to it's use of dirent.h, I tried to download the v1.5 tarball and build that in Visual Studio. The build is failing with the error:
libconfig.obj : error LNK2019: unresolved external symbol S_ISDIR referenced in function config_read_file
Apparently S_ISDIR is a posix macros and does not work on Windows. Is there libconfig source that will build on Windows?
As suggested elsewhere (issue #47) I have removed scanner.c
and scanner.h
(otherwise I get the error mentioned there).
If I then compile, I get this error:
scanner.l:187:63: error: 'alphasort' undeclared (first use in this function) if(scanctx_dirscan(yyextra, basedir, filter_dotfiles, alphasort) < 0)
Don't know how to fix...
trying
./configure --host=arm-linux-gnueabi --with-sysroot=/usr/arm-linux/gnueabi
then
make
results in
make[2]: Entering directory '/home/osboxes/libconfig/lib'
YACC grammar.c
byacc: e - line 24 of "/home/osboxes/libconfig/lib/grammar.y", syntax error
%defines
^
I've installed libconfig in OSX via brew install libconfig
so it gets compiled with clang. Then I include <libconfig.h++>
in my C++ project and link with -lconfig++
.
If I compile my project with clang++ there is no problem, but if I compile it with g++ (4.8 or 4.9) I get this error:
Undefined symbols for architecture x86_64:
"libconfig::Config::lookupValue(char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&) const", referenced from:
MyProject::ReadConfigFile() in ccquVmsS.o
ld: symbol(s) not found for architecture x86_64
This is the usage of lookupValue
within my code:
libconfig::Config* config = new libconfig::Config();
[...]
std::string str_value;
config->lookupValue("logLevel", str_value);
Taking a look into libconfig++.h
it seems that the inline methods receiving a string (or char*) as second argument are causing this problem.
Hi. Actually if we doesn't specify an absolute path for the include directive, it loads included configuration file from the path where the binary which loads the main configuration file is executed.
In some cases, I think it would be useful to be able to load included configuration files from the place where the main configuration file is without specifying the absolute path.
#include <iostream>
#include <libconfig.h++>
using namespace std;
using namespace libconfig;
int main (void) {
Config cfg;
cfg.getRoot().add("avalue", Setting::TypeFloat);
cfg.getRoot()["avalue"] = (double) 4.1837;
cfg.writeFile("test.cfg");
return 0;
}
results in:
avalue = 4.18;
Hi ! I've just clone your repository and noticed that the 'configure' file is missing. Did you changed the way to compile your library ?
Thanks in advance for your help.
This was reported in http://freecode.com/projects/libconfigduo:
valgrind complains that libconfig uses calloc() wrongly:
#define _new(T) (T *)calloc(sizeof(T), 1) /* zeroed */
corrected:
#define _new(T) (T *)calloc(1, sizeof(T)) /* zeroed */
From the manpage:
void *
calloc(size_t count, size_t size);
This is in file:
lib/libconfig.c
49:#define _new(T) (T *)calloc(sizeof(T), 1) /* zeroed */
I'm trying to overwrite a setting that can be from another type of the original. To do that, I first try to remove the existing and add a new one using the new type. However, when I remove a setting, all the siblings are removed as well.
This small test program:
#include <string>
#include <iostream>
#include <libconfig.h++>
int main(int argc, char* argv[])
{
std::string szConfig = "a:{b:3;c:4;}";
libconfig::Config libConfig;
try
{
libConfig.readString(szConfig);
libConfig.getRoot().remove("a.b");
libConfig.writeFile("/tmp/testconfig.cfg");
libConfig.lookup("a.c"); //<--- SettingNotFoundException
}
catch(std::exception const& ex)
{
std::cerr << ex.what() << std::endl;
return -1;
}
return 0;
}
Gives me the following output:
SettingNotFoundException
Is that an expected behavior? IMHO, no, if I trust the documentation "a.b" is not a group and a SettingTypeException shall be thrown... But that is not the case! The created file is empty!
Instead of having to loop through a list or array of Setting
s by index, it would be convenient if there was an iterator class defined as well as a begin()
and end()
method for the Setting
class, obviously only valid if the setting represents a container type. For example, from example1.cpp
:
const Setting &books = root["inventory"]["books"];
int count = books.getLength();
for(int i = 0; i < count; ++i)
{
const Setting &book = books[i];
// Do stuff with book.
}
could be replaced with:
const Setting &books = root["inventory"]["books"];
for (Setting const& book : books)
// Do stuff with book.
If a directory is given in config->readFile(file)
(instead of a text file) then libconfig exist with error:
input in flex scanner failed
I suggest that, in that case, it throws a libconfig::FileIOException
exception.
There seems like a problem in Mac where i cannot get cfg.readFile to work. I'm not sure is it because im using clang? Or does anyone have any clue. Though compiling/building isn't an issue. But it just won't let me run applications that use libconfig. I get File I/O errors.
Hi hyperrealm,
When using @include to get nested configuration files, it can be somehow cumbersome to get it right:
especially when the user wants to use relative paths (and/or absoute paths). Currently the behaviour
of libconfig is also dependend on the current working directory.
One can set a include dir, but that can also confuses libconfig as it will always use that path,
regardless if an absolute or relative path is given.*
It would be great if libconfig could be a little smarter when parsing includes:
-> when the path of the include starts with "/" the set include dir should be ignored and an absoute path assumed
-> maybe, additionally, if the path starts with "./" consider this a relative path to the currently parsed configuration file?
Thanks!
*for example:
with include-dir set to /etc/foo/
@include bar.conf
will include /etc/foo/bar.conf
but
@include /etc/bar.conf
will (try to) include /etc/foo//etc/bar.conf
(this report applies to 1.4.9; I did not check against trunk but a brief check of the commit messages looks like that this feature request is still valid. If not, sorry for the noise)
Kudos for your fine library!
tobi
Hi,
I try to build libconfig-1.6 with VC10 and I got this:
scanner.l(137): warning C4047: 'function' : 'const char ' differs in levels of indirection from 'const char *'
1>scanner.l(137): warning C4024: 'scanctx_push_include' : different types for formal and actual parameter 3
1>scanner.l(137): error C2198: 'scanctx_push_include' : too few arguments for call
Thanks
Hubert
I want to use libconfig in my project, but I don't know how to build this library.
I use Qt Creator on Windows with Cmake for my projects.
Currently I've added the following code to my CMakeList.txt :
set(CONFIG "${SRCROOT}/libconfig/lib/grammar.c"
"${SRCROOT}/libconfig/lib/libconfig.c"
"${SRCROOT}/libconfig/lib/libconfigcpp.c++"
"${SRCROOT}/libconfig/lib/scanctx.c"
"${SRCROOT}/libconfig/lib/scanner.c"
"${SRCROOT}/libconfig/lib/strbuf.c")
add_library(libconfig STATIC ${CONFIG})
SET_TARGET_PROPERTIES(libconfig PROPERTIES LINKER_LANGUAGE C)
setup_library_target(libconfig "${CODEROOT}/lib")
add_executable(TV_1_Validate_ODE_Solver "${SRCROOT}/TV_1_Validate_ODE_Solver.cpp")
setup_executable_target(TV_1_Validate_ODE_Solver "${SRCROOT}")
target_link_libraries(TV_1_Validate_ODE_Solver
tudat_numerical_integrators
libconfig
${TUDAT_CORE_LIBRARIES}
${Eigen_LIBRARIES}
${Boost_LIBRARIES})
I start my executable source file with:
The CMake File runs, but I get an error when building the executable. I get the following error:
\TV_1_Validate_ODE_Solver.cpp:162: error: undefined reference to `_imp___ZN9libconfig6ConfigC1Ev'
While I only construct cfg on that line:
Line 162: libconfig::Config cfg;
I get similar errors on the lines:
cfg.readFile("TV_1_Config.cfg");
catch(const libconfig::ParseException &pex)
In addition, I get the following error:
collect2.exe:-1: error: error: ld returned 1 exit status
Any Idea on how to fix this?
fclose(stream) will not work on NULL pointers.
I changed to:
if(!ok)
{
if (stream != NULL)
{
fclose(stream);
}
config->error_text = __io_error;
config->error_type = CONFIG_ERR_FILE_IO;
return(CONFIG_FALSE);
}
It would be nice if there was a way to tell libconfig how the config file should be structured - the same idea as XSD for XML. This way config files validation could be done by calling an API function.
ps; Sorry if this isn't the right place to put this comment.
Regards,
Hello. I get this error when I run 'make'. The 'configure' phase seems to be successful.
I don't have automake 1.14 installed on this machine, but I don't think I should. I have 1.13, but even after uninstalling it nothing changes.
An even weirder thing is that on another machine, where only automake 1.11 is installed, this error is not thrown and the compilation succeeds.
Here is the full error message:
[marco@localhost source]$ make
cd . && /bin/sh /home/marco/Scaricati/libconfig-1.5/source/aux-build/missing automake-1.14 --gnu
/home/marco/Scaricati/libconfig-1.5/source/aux-build/missing: line 81: automake-1.14: command not found
WARNING: 'automake-1.14' is missing on your system.
You should only need it if you modified 'Makefile.am' or
'configure.ac' or m4 files included by 'configure.ac'.
The 'automake' program is part of the GNU Automake package:
<http://www.gnu.org/software/automake>
It also requires GNU Autoconf, GNU m4 and Perl in order to run:
<http://www.gnu.org/software/autoconf>
<http://www.gnu.org/software/m4/>
<http://www.perl.org/>
make: *** [Makefile.in] Errore 1
Thank you.
Hi
First: thanks for your work.
So I parse a configuration file with a key that can either be a scalar
somekey=X
or a table of scalar values:
somekey=[X,Y.Z]
The following compiles and work properly, for X,Y,Z strings:
static int parse_devices(void)
{
const config_setting_t *devs=NULL;
const char *dev=NULL;
int i, ret;
devs=config_lookup(&cfg, "devices");
if(!devs){
return -EINVAL;
}
dev=config_setting_get_string(devs);
if(dev){
return add_dev(dev);
}
for(i=0;i<config_setting_length(devs);++i){
dev=NULL;
dev=config_setting_get_string_elem(devs, i);
ret=add_dev(dev);
if(ret){
return ret;
}
}
return 0;
}
Now while the above provides the desired functionality, the following will compile but not work as intended :
static int parse_nodes(void)
{
int i, ret, node;
config_setting_t *nodes=NULL;
nodes=config_lookup(&cfg, "nodes");
if(!nodes){
return -EINVAL;
}
node=config_setting_get_int(nodes);
if(node){
return add_node(node);
}
for(i=0;i<config_setting_length(nodes);++i){
node=config_setting_get_int_elem(nodes, i);
ret=add_node(node);
if(ret){
return ret;
}
}
return 0;
}
The problem is that there is no way of knowing if config_setting_get_int
succeeded or not, because any error code returned can also be a valid number that was parsed. How can I implement the same functionality as defined in the first code snippet for int/int64 types in a somewhat proper way ?
Or am I missing something?
thanks
Hi,
It would be convenient to have a constructor that reads a file automatically. Reading a config file is usually an operation that is executed only once and prevents doing other things with Config until it's done.
It would also allow the following code:
class MyClass
{
Config cfg;
const int myparam;
MyClass(const char *configfile) : cfg(configfile), myparam(cfg.lookup("myparam")) {};
}
Best regards,
Denis Shulyaka
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.