Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation fails on Msys2 / Windows 10 system due to libconfig.h not found #6

Open
bill-e-ghote opened this issue Jun 28, 2023 · 8 comments

Comments

@bill-e-ghote
Copy link

I installed libconfig using pacman, I installed it again using sources taken from https://github.com/hyperrealm/libconfig. I've tried using symbolic links to the installed libconfig.h in the core, site, and vendor lib/share folders, and I've following your instructions with regard to passing the include path on the make command line, I even tried using Devel::Trace module to attempt to debug it but admit defeat there - I'm not knowledgeable enough in Perl. Nothing works for me - it is always the same error.

Can you offer some guidance?

bill.e.ghote@COMPUTER MSYS /c/Users/bill.e.ghote/Malware/source/repos/Conf-Libconfig
$ perl Makefile.PL LIBS=-L/usr/local/lib INC=-I/usr/local/include 2>&1 | tee -a err
Can't link/include 'libconfig.h', 'config'

bill.e.ghote@COMPUTER MSYS /c/Users/bill.e.ghote/Malware/source/repos/Conf-Libconfig
$ ls /usr/local/lib/libconfig*
/usr/local/lib/libconfig++.dll.a /usr/local/lib/libconfig.dll.a

bill.e.ghote@COMPUTER MSYS /c/Users/bill.e.ghote/Malware/source/repos/Conf-Libconfig
$ ls /usr/local/include/libconfig*
/usr/local/include/libconfig.h /usr/local/include/libconfig.h++ /usr/local/include/libconfig.hh

bill.e.ghote@COMPUTER MSYS /c/Users/bill.e.ghote/Malware/source/repos/Conf-Libconfig
$ perl -V
Summary of my perl5 (revision 5 version 36 subversion 0) configuration:

Platform:
osname=msys
osvers=3.3.6-341.x86_64
archname=x86_64-msys-thread-multi
uname='msys_nt-10.0-20348 fv-az449-938 3.3.6-341.x86_64 2022-10-24 08:25 utc x86_64 msys '
config_args='-des -Dusethreads -Doptimize=-march=x86-64 -mtune=generic -O2 -pipe -Dprefix=/usr -Dvendorprefix=/usr -Dprivlib=/usr/share/perl5/core_perl -Darchlib=/usr/lib/perl5/core_perl -Dsitelib=/usr/share/perl5/site_perl -Dsitearch=/usr/lib/perl5/site_perl -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib/perl5/vendor_perl -Dscriptdir=/usr/bin/core_perl -Dsitescript=/usr/bin/site_perl -Dvendorscript=/usr/bin/vendor_perl -Dinc_version_list=none -Dman1ext=1perl -Dman3ext=3perl -Darchname=-msys-threads -Dmyarchname=-msys -Dlibperl=msys-perl5_36.dll -Dcc=gcc -Dld=g++ -Accflags=-march=x86-64 -mtune=generic -O2 -pipe -fwrapv'
hint=recommended
useposix=true
d_sigaction=define
useithreads=define
usemultiplicity=define
use64bitint=define
use64bitall=define
uselongdouble=undef
usemymalloc=n
default_inc_excludes_dot=define
Compiler:
cc='gcc'
ccflags ='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -D_GNU_SOURCE -march=x86-64 -mtune=generic -O2 -pipe -fwrapv -fno-strict-aliasing -fstack-protector-strong -D_FORTIFY_SOURCE=2'
optimize='-march=x86-64 -mtune=generic -O2 -pipe'
cppflags='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -D_GNU_SOURCE -march=x86-64 -mtune=generic -O2 -pipe -fwrapv -fno-strict-aliasing -fstack-protector-strong'
ccversion=''
gccversion='11.3.0'
gccosandvers=''
intsize=4
longsize=8
ptrsize=8
doublesize=8
byteorder=12345678
doublekind=3
d_longlong=define
longlongsize=8
d_longdbl=define
longdblsize=16
longdblkind=3
ivtype='long'
ivsize=8
nvtype='double'
nvsize=8
Off_t='off_t'
lseeksize=8
alignbytes=8
prototype=define
Linker and Libraries:
ld='g++'
ldflags =' -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector-strong'
libpth=/usr/lib
libs=-lpthread -lgdbm -ldb -ldl -lcrypt -lgdbm_compat
perllibs=-lpthread -ldl -lcrypt
libc=/usr/lib/libmsys-2.0.a
so=dll
useshrplib=true
libperl=msys-perl5_36.dll
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs
dlext=dll
d_dlsymun=undef
ccdlflags=' '
cccdlflags=' '
lddlflags=' --shared -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector-strong'

Characteristics of this binary (from libperl):
Compile-time options:
HAS_TIMES
MULTIPLICITY
PERLIO_LAYERS
PERL_COPY_ON_WRITE
PERL_DONT_CREATE_GVSV
PERL_OP_PARENT
PERL_PRESERVE_IVUV
PERL_USE_SAFE_PUTENV
USE_64_BIT_ALL
USE_64_BIT_INT
USE_ITHREADS
USE_LARGE_FILES
USE_LOCALE
USE_LOCALE_COLLATE
USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC
USE_LOCALE_TIME
USE_PERLIO
USE_PERL_ATOF
USE_REENTRANT_API
USE_THREAD_SAFE_LOCALE
Built under msys
Compiled at Oct 26 2022 09:46:57
@inc:
/usr/lib/perl5/site_perl
/usr/share/perl5/site_perl
/usr/lib/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib/perl5/core_perl
/usr/share/perl5/core_perl

bill.e.ghote@COMPUTER MSYS /c/Users/bill.e.ghote/Malware/source/repos/Conf-Libconfig
$

@bill-e-ghote
Copy link
Author

I will quickly add, I also tried using CPAN.

bill.e.ghote@COMPUTER MSYS /c/Users/bill.e.ghote/Malware/source/repos/Conf-Libconfig
$ cpan -i Conf::Libconfig
Loading internal logger. Log::Log4perl recommended for better logging
Reading '/home/bill.e.ghote/.cpan/Metadata'
Database was generated on Wed, 28 Jun 2023 18:29:01 GMT
Running install for module 'Conf::Libconfig'
Checksum for /home/bill.e.ghote/.cpan/sources/authors/id/C/CN/CNANGEL/Conf-Libconfig-1.0.0.tar.gz ok
'YAML' not installed, will not store persistent state
Configuring C/CN/CNANGEL/Conf-Libconfig-1.0.0.tar.gz with Makefile.PL
Can't link/include 'libconfig.h', 'config'
No 'Makefile' created CNANGEL/Conf-Libconfig-1.0.0.tar.gz
/usr/bin/perl Makefile.PL INSTALLDIRS=site -- NOT OK

bill.e.ghote@COMPUTER MSYS /c/Users/bill.e.ghote/Malware/source/repos/Conf-Libconfig
$

@bill-e-ghote
Copy link
Author

I laboriously stepped through the code using Perl in debug mode, and have isolated the underlying problem. For whatever (yet for me to determine) reason, Msys2 environment does not like the includes that are pulled in by the test .c program. When I execute the same test gcc compile from a Cygwin terminal, all works as it should. So, this is specific to my (and perhaps every) Msys2 environment. I will dig further and attempt to resolve it.

Thanks for tolerating.

@cnangel
Copy link
Owner

cnangel commented Jun 30, 2023

I think you can try to edit Makefile.PL , you can add some codes after:

eval {
    @inc_paths = map {s/-I//; $_} split(' ', ExtUtils::PkgConfig->cflags_only_I('libconfig'));
    @lib_paths = map {s/-L//; $_} split(' ', ExtUtils::PkgConfig->libs_only_L('libconfig'));
};

like this:

push @inc_paths, '-I/usr/local/include';
push @lib_paths, '-L/usr/local/lib';

Usually, you can get cc compile and link options, which include -I/usr/local/include and -L/usr/local/lib.
Best wishes.

@bill-e-ghote
Copy link
Author

TL;DR:
This is not an issue with Conf-Libconfig so I will suggest this support request be closed.

In my default Msys2 shell started with "C:\Users\USER\msys64\msys2_shell.cmd", the underlying call to test compile is (for this instance - the filenames are dynamically generated, as you know):
/usr/bin/gcc.exe -DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -D_GNU_SOURCE -march=x86-64 -mtune=generic -O2 -pipe -fwrapv -fno-strict-aliasing -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector-strong assertlibv1becJbP.c -I/mingw64/include -o assertlibunhkC3UZ.exe

This fails with errors such as:
In file included from /mingw64/include/_cygwin.h:14,
from /mingw64/include/_mingw.h:15,
from /mingw64/include/corecrt.h:10,
from /mingw64/include/corecrt_stdio_config.h:10,
from /mingw64/include/stdio.h:9,
from /mingw64/include/libconfig.h:46,
from assertlibv1becJbP.c:1:
/mingw64/include/stddef.h:18:10: error: expected ‘;’ before ‘extern’
18 | _CRTIMP extern int *__cdecl _errno(void);
| ^~~~~~~
| ;

What is frustrating about this situation is that compiling the test C file without any includes works just fine.
$ /usr/bin/gcc.exe assertlibv1becJbP.c -o assertlibunhkC3UZ.exe
... no errors and output is generated.

... moving on...

If I start Msys2 shell with:
C:\Useres\USER\msys64\msys2_shell.cmd -mingw64 -here

... and then compile as one would do normally, everything works as expected:

$ perl Makefile.PL
Use of uninitialized value in split at Makefile.PL line 27.
Use of uninitialized value in split at Makefile.PL line 28.
*** Module::AutoInstall version 1.03
*** Checking for Perl dependencies...
[Core Features]

  • Test::Deep ...loaded. (1.204 >= 0.1)
  • Test::More ...loaded. (1.302190 >= 0.6)
  • Test::Warn ...loaded. (0.37 >= 0.1)
  • Test::Exception ...loaded. (0.43 >= 0.25)
  • ExtUtils::PkgConfig ...loaded. (1.16)
  • XSLoader ...loaded. (0.31 >= 0.05)
    *** Module::AutoInstall configuration finished.
    Checking if your kit is complete...
    Warning: the following files are missing in your kit:
    Libconfig.bs
    Please inform the author.
    Generating a Unix-style Makefile
    Writing Makefile for Conf::Libconfig
    Writing MYMETA.yml and MYMETA.json

Bottom line: My own inexperience with Msys2 led to this "issue." Apologies for the noise, but perhaps this will help someone down the road.

@bill-e-ghote
Copy link
Author

bill-e-ghote commented Jun 30, 2023

PS: To actually make the build with the resulting Makefile, I had to switch shells another time (back to msys shell), otherwise gcc could not load sys/wait.h. This is apparently a known issue, as Google pointed me to: msys2/MSYS2-packages#1086

@bill-e-ghote
Copy link
Author

push @inc_paths, '-I/usr/local/include';
push @lib_paths, '-L/usr/local/lib';

Also, I think you meant:
push @inc_paths, '/usr/local/include';
push @lib_paths, '/usr/local/lib';

...as otherwise I wind up with -I-I/usr/local/include in the internal call to gcc, the test compile fails for all Msys2 shells, even.

@bill-e-ghote
Copy link
Author

bill-e-ghote commented Jun 30, 2023

So, I guess I'll just add this comment here. I thought everything had built correctly, but at run-time it's bombing with a segmentation fault. Here's my debug output. Any ideas?

$ perl -d ./conf2struct eg_conf.cfg | tee -a trace.out

Loading DB routines from perl5db.pl version 1.73
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(./conf2struct:3): my $license = <<EOF;
DB<1> b 59
DB<2> c
main::(./conf2struct:59): my $hr = {
main::(./conf2struct:60): header => $header,
main::(./conf2struct:61): parser => $parser,
main::(./conf2struct:62): printer => $printer,
main::(./conf2struct:63): conffile_option => $conf->fetch_array("conffile_option"),
main::(./conf2struct:64): includes => $conf->fetch_array("includes"),
main::(./conf2struct:65): config => $conf->fetch_hashref("config"),
main::(./conf2struct:66): cl_groups => $conf->fetch_array("cl_groups"),
DB<2> s
Conf::Libconfig::fetch_array(/usr/share/perl5/core_perl/Carp.pm:262):
262: local($!, $^E);
DB<2>

...of course we could continue to step through it but that call to Carp means it's already dead, obviously. But, why?

@cnangel
Copy link
Owner

cnangel commented Jul 12, 2023

I think you should use 'n' for the next step, if you are familiar with gdb, 'c' means continue until the end of the program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants