hyperrealm / libconfig

C/C++ library for processing configuration files
https://hyperrealm.github.io/libconfig/
GNU Lesser General Public License v2.1
1.12k stars 364 forks source link

failed to build with "libstdc++" on Mac osx 10.10.1 #29

Closed jiachenwang closed 7 years ago

jiachenwang commented 9 years ago

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?

hyperrealm commented 9 years ago

This must be a recent breakage as it was working fine on earlier versions of OS X. configure.ac will need to be updated to check if it needs to link in libstdc++.

hyperrealm commented 7 years ago

This must've been due to the out of sync generated files that were in the repo. I just tried building the code from head on my El Capitan system and it built clean. Please try again and open a new issue if you still have problems.