How to build DBD::mysql with DBI in a custom #INC? - mysql

I'm building DBI and DBD::mysql in a continuous integration build server. The build of DBI is successful, as seen in the excerpt of the build log below. It clearly installs DBI/DBD.pm in the correct location.
pushd DBI-1.643
perl Makefile.PL INSTALL_BASE=/data/pods/mysql-tools/mysql-tools/current
...
Installing /data/pods/mysql-tools/mysql-tools/current/lib/perl5/x86_64-linux-thread-multi/DBI/DBD.pm
...
Appending installation info to /data/pods/mysql-tools/mysql-tools/current/lib/perl5/x86_64-linux-thread-multi/perllocal.pod
But the next part of the build for DBD::mysql fails because it can't find the files installed by DBI.
pushd DBD-mysql-4.050
perl Makefile.PL INSTALL_BASE=/data/pods/mysql-tools/mysql-tools/current --ssl
Can't locate DBI/DBD.pm in #INC (#INC contains:
/usr/local/lib64/perl5
/usr/local/share/perl5
/usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib64/perl5
/usr/share/perl5 .)
at Makefile.PL line 15.
You can see, MakeMaker for DBD::mysql isn't adding the install location to its #INC at all. It just has default directories.
Is there a way to pass an argument to MakeMaker to add the install directory to #INC? I suppose I could hard-code it, but that seems improper and hard to maintain. Is there a better way to automatically add INSTALL_BASE/lib/perl5/<arch> to #INC?
Environment:
CentOS 7 Linux
Perl 5.16.3
I would have preferred to use cpanm of course. But the CI build server is isolated from the internet because of my employer's security policy. No http proxying is allowed from CI.

According to the documentation, INSTALL_BASE is used for telling make install where to put the installed module:
INSTALL_BASE
INSTALL_BASE can be passed into Makefile.PL to change where your
module will be installed. INSTALL_BASE is more like what everyone else
calls "prefix" than PREFIX is.
but it does not tell perl where to look for installed modules. To do that you can use the environment variable PERL5LIB, according to the documentation :
PERL5LIB
A list of directories in which to look for Perl library files before
looking in the standard library. Any architecture-specific and
version-specific directories, such as version/archname/, version/, or
archname/ under the specified locations are automatically included if
they exist, with this lookup done at interpreter startup time. In
addition, any directories matching the entries in
$Config{inc_version_list} are added.

Related

Perl to mysql connectivity on Windows 10

I have a process that works in the production environment, that I need to get working on my local Windows 10 environment. It is a Perl script that calls mySql stored procedures.
I have installed ActivePerl 5.26.3 (64-Bit) from Active State. When I attempt to execute the script I get an error:
Can't locate DBD/mysql.pm (you may need to install the DBD::mysql module)...
So, I went to https://metacpan.org/release/DBD-mysql and found instructions that indicated I needed to do the following:
perl -MCPAN -e shell
install DBD::mysql
But, when I type the first command I get a message stating:
It looks like you don't have a C compiler and make utility installed. Trying to install dmake and the MinGW gcc compiler using the Perl Package Manager. This may take several minutes....
Then it goes thru what appears to be a successful installation. So I type in the second command. It scrolls by for a while, but ends with:
Failed during this command
DVEEDEN/DBD-mysql-4.050.tar.gz: writemakefile NO 'C:\Perl64\bin\perl.exe MakeFile.PL INSTALLDIRS=site' returned status 512
Not sure how to proceed.
For ActivePerl, use their package manager PPM.
Or, use Strawberry Perl for a more unixy experience. It comes with all the stuff to compile and install modules.
No matter which Perl you use, on Windows or elsewhere, modules typically need to be compiled the same. Mixing compilers (such as Visual Studio and gcc) or options can lead to incompatible binaries. The same might happen across Perl versions too. That means to use the same Perl (and compilation method) for everything in your project).
The cpan utility doesn't figure out those things for you. It does whatever it's configured to do.
For what it's worth, the cpan method to install modules can be simpler:
$ cpan DBD::mysql

install_driver(mysql) failed: Can't locate DBD/mysql.pm

Question is not repeated, first read the problem which I am facing, then mark it if it is repeated, will be helpful if repeatation of my question helps me in solving my problem, As I have been through all the links and solutions mentioned on other similar questions and problems but no luck.
I am trying to setup redmine git on my ec2-aws-instance with help of below link
https://docs.bitnami.com/installer/how-to/configure-advanced-integration-git-redmine/
I am able to properly connect redmine projects with my git repositories but once I reach third step on above link I am facing issue as below
step :- 3 Configure Git Access Control
Below is the error when try to secure my git repository with redmine user credentials.
[Thu Feb 21 17:46:26.918619 2019] [perl:error] [pid 26820:tid
139790464616192] [client 127.0.0.1:50156] install_driver(mysql)
failed: Can't locate DBD/mysql.pm in #INC (#INC contains:
/opt/bitnami/git/lib/site_perl/5.16.3
/opt/bitnami/perl/lib/5.16.3/x86_64-linux-thread-multi
/opt/bitnami/perl/lib/5.16.3
/opt/bitnami/perl/lib/site_perl/5.16.3/x86_64-linux-thread-multi
/opt/bitnami/perl/lib/site_perl/5.16.3
/opt/bitnami/perl/lib/5.16.3/x86_64-linux-thread-multi
/opt/bitnami/perl/lib/site_perl/5.16.3/x86_64-linux-thread-multi
/bitnami/ruby23stack-linux-x64/output/perl/lib/site_perl/5.16.3/x86_64-linux-thread-multi
/bitnami/ruby23stack-linux-x64/output/perl/lib/site_perl/5.16.3
/bitnami/ruby23stack-linux-x64/output/perl/lib/5.16.3/x86_64-linux-thread-multi
/bitnami/ruby23stack-linux-x64/output/perl/lib/5.16.3 .
/opt/bitnami/apache2) at (eval 6) line 3.\nPerhaps the DBD::mysql perl
module hasn't been fully installed,\nor perhaps the capitalisation of
'mysql' isn't right.\nAvailable drivers: DBM, ExampleP, File, Gofer,
Proxy, Sponge.\n at
/opt/bitnami/perl/lib/site_perl/5.16.3/x86_64-linux-thread-multi/Apache/Redmine.pm
line 557.\n App 26921 stdout:
Without third step my repositories are public, any who knows the repo url can clone my repos or perform other operations on my git repos. So third step is for security purpose as per above document link and which is important for me.
Once I add below line into apache config as per documentation mentioned I am getting above error in my bitnami log when I try to clone a repository
<Location "/">
AuthType Basic
AuthName "Redmine git repositories"
Require valid-user
PerlAccessHandler Apache::Authn::Redmine::access_handler
PerlAuthenHandler Apache::Authn::Redmine::authen_handler
RedmineDSN "DBI:mysql:database=bitnami_redmine;host=localhost;mysql_socket=installdir/mysql/tmp/mysql.sock"
RedmineDbUser "REDMINE_DB_USERNAME"
RedmineDbPass "REDMINE_DB_PASSWORD"
RedmineGitSmartHttp yes
</Location>
When I run a following command to clone a repo, without third step on documentation, I am properly able to clone the repo, but with third step I am failing and getting above error in log and below error on command line.
bitnami#127.0.0.1:/tmp$ git clone http://git.domain.com/test2
Cloning into 'test2'...
fatal: unable to access 'http://git.domain.com/test2/': The requested URL returned error: 500
I have even tried installing below package but no luck
sudo apt-get install libdbd-mysql-perl
my os is
Ubuntu 16.04.5 LTS \n \l
In order for a Perl installation to talk to a MySQL database, it needs to use the DBD::mysql module. This module isn't part of the standard Perl installation and needs to be installed separately. When you install it using the CPAN command line tool (cpan DBD::mysql) or using apt-get (apt-get install libdbd-mysql-perl) it is installed in the library directories used by the system Perl (the one that is installed as part of your operating system). You can confirm that this has been installed correctly by running the following commands:
$ perldoc DBD::mysql
$ perl -MDBD::mysql -le'print $DBD::mysql::VERSION'
If DBD::mysql is installed correctly, the first command will show you the documentation for the module and the second will give the version number.
But, as I said, this is installed for use by the system Perl installation. It appears from the error message you're seeing that your Bitnami installation isn't using the system Perl. It is, instead, using a separate Perl installation which is installed in /opt/bitnami.
So you need to get DBD::mysql installed in the module library for this Perl installation. It's possible to ask cpan to install a module in a different directory, but I'd be wary about just installing stuff into Bitnami's directory tree. I strongly suspect that an installation step has been skipped far earlier in the process. If Bitnami needs to use MySQL from a Perl program and installs its own Perl distribution complete with its own module library, then it should either include DBD::mysql in its installation or provide clear instructions on how to install it.
My suggestion would be to carefully go over the installation instructions for Bitnami and see what they have to say about installing MySQL support. If that doesn't work, you should take this question to Bitnami's support channels.

TCL_LIB_SPEC missing in modules install

I'm trying to install modules from SourceForge and I'm getting an error that a variable named TCL_LIB_SPEC is not set. What is this supposed to be set to?
The answer here is to install the TCL development package
% yum install tcl-devel
This gives you a tclConfig.sh file at /usr/lib64/tcl8.5
So
% cd /usr/lib64/tcl8.5
% . ./tclConfig.sh
Then configure works.
It's supposed to be set to the instructions to use with your compiler for linking against the Tcl C library, and it should (conventionally) be generated by running the relevant configure script inside a Tcl source distribution. Or a distribution of Tcl (e.g., on Linux perhaps called tcl-dev) may have alternate correct values already set up.

"Fatal error: 'EXTERN.h' file not found" while installing Perl modules

While trying to install Perl modules like JSON::XS or YAML::XS, i receive the same error:
XS.xs:1:10: fatal error: 'EXTERN.h' file not found
I use MacBook, xCode is up to date, everything else that could help is up to date too.
Since OS X El Capitan, Apple introduced System Integrity Protection which restricts writing to /usr/lib /usr/bin and other sensitive directories (even to root or sudo user) that are used by the installation of Perl bundled with the Operating System. This can cause issues when it comes to installing new modules and also if trying to install XS modules ( those linked to external C libraries ).
For this reason you should not consider the default Perl installation as a working development environment, especially if you are installing custom modules.
Check out this thread on PM and others. I had since El-Capitan managed to solve this before by manually building from tarball and adding a few params or environment variables to set the paths believing that it would be best to retain use of the system Perl but this is not the way to go. This makes your environment difficult to build but also brittle and sensitive to OS updates that may either break things in many different ways.
The best practice seems to be starting with a Perl using brew install perl and work in this environment, remembering to setup your bash_profile as directed by the installer.
Also worth remembering to do a brew link perl. If you receive warnings about this clobbering what looks like system Perl libraries don't worry - these are likely modules that were installed by you over the top and it will cause you less trouble to link over these. If you have concerns, make a note of which module installs will be cleared and re-install them once your environment is configured ( ie your module installer approach is configured using cpanm or sticking with the old perl -MCPAN -e shell etc)
This new Perl setup from brew eliminates the need to continuing running sudo which adds another layer of things that can go wrong as environment variables don't follow through and permission conflicts arise etc.
Finally to simplify package/module installation I suggest doing a brew install cpanminus. If you had previously already installed this, you can ensure the paths etc are configured by doing a brew reinstall cpanminus
If you want to take it another step further then you can install perlbrew as well which will give you the ability to run multiple versions of Perl as your user and configure these with their own libs and modules which can be very useful particularly if aligning with your production environment for testing etc.
One problem you may face if moving from system Perl to this kind of approach is needing to deal with any hangovers from installing things with sudo. It wis worth taking a little time to get all this set up right though and your issues going forward will be greatly reduced and you won't be left with that nagging feeling that you don't want to change anything for fear of it all breaking.
I have also come across a Perl Blog Article that suggests a fix for XS issues with perlbrew on Mojave
This Gist described updating your cpan shell install root though this shouldn't be necessary unless your cpan is stuck in an old config after taking steps above.
I've also raised this as a new issue on PerlMonks
After reading https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes#3035624 and installing the Additional headers via
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
I successfully compiled without the missing 'EXTERN.h' error
In order to follow the common advice I also tried with Perlbrew to install a dedicated development version of Perl. Especially with the advice in mind First, do not use the system Perl on MacOS. The installed version is for Apple, not for you (see the discussion here: https://www.perlmonks.org/?node_id=1224727).
Unfortunately, the following error occurred:
Test Summary Report
-------------------
porting/libperl.t (Wstat: 65280 Tests: 35 Failed: 0)
Non-zero exit status: 255
Parse errors: No plan found in TAP output
Files=2653, Tests=1217766, 708 wallclock secs (52.74 usr 9.40 sys + 395.38 cusr 49.90 csys = 507.42 CPU)
Result: FAIL
make: *** [test_harness] Error 1
##### Brew Failed #####
Therefore, I decided to install it the following way (and not following the advice due to the error).
Even after having the above mentioned macOS SDK headers already installed on Catalina (macOS 10.15.2) it didn't work for me. I faced the issue during the installation of the Perl module Mac-SystemDirectory-0.13. The following steps (by identifying the missing file in hope of having a more generic approach for more or less equivalent issues) did the trick:
Locate the header file (in this case EXTERN.h)
sudo find /Library -type f -name EXTERN.h
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE/EXTERN.h
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Perl/5.28/darwin-thread-multi-2level/CORE/EXTERN.h
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE/EXTERN.h
Ensure the installed Perl version (here 5.18) match the header file:
perl -v | grep version
This is perl 5, version 18, subversion 4 (v5.18.4) built for darwin-thread-multi-2level
Export the path for the C-Compiler (note MacOSX10.15.sdk for Catalina and Perl Version 5.18)
export CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE
Invoke the Makefile.PL with perl
perl Makefile.PL
BTW — For anybody who's still struggling with this, my workaround was:
bash% module="Sub::Util" # For example
bash% cpanm --configure-args="INC=-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE" "$module"
Please try this
CPATH=$(dirname $(find /usr/local/Cellar/ -name EXTERN.h)) cpan JSON::XS
For Big Sur and perl 5.30, EXTERN.h is at /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/System/Library/Perl/5.30/darwin-thread-multi-2level/CORE
I'm trying to upgrade CPAN itself and got that error. But I have /usr/bin/cpan and I can't write there so I have to tweak it to write the updated version to /usr/local/bin/cpan.
No promises, but yum install perl-devel worked for me.
As #huyz has helpfully pointed out, if you hit this error on a Mac, you don't have this option, even though this is probably your issue, and you need to follow one of the above methods of getting a version of Perl that isn't missing important chunks, as per other answers.
But if, dear reader, you hit this error on a linux host, as I did, then this might be an option for you.
Building on what E Lisse suggested, you might also have luck looking in
/System/Volumes/Data/Library/Developer/CommandLineTools/SDKs/
For example:
CPATH=$(dirname $(find /System/Volumes/Data/Library/Developer/CommandLineTools/SDKs/ -name EXTERN.h)) cpan JSON::XS
You could also find where EXTERN.h is located and add that to your shell by default, e.g. in your .bashrc or .zshrc file:
export CPATH=/System/Volumes/Data/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE/

Equivalent to libmysqldev FreeBSD

I have compiled a program in fedora using the mysql dev library (include mysql.h in header file). I need to compile in on FreeBSD. I do not want to download from source and compile but rather would like to download from ports or something equivalent to facilitate removing it if need be.
Does anyone know the equivalent of the libmysql-dev in FreeBSD. I have not found it in ports?
You do not need a special package for this. The standard mysql client package/port already includes the libraries and the header files you will need. The header files will end up, by
default, in /usr/local/include/mysql/ directory, while
the libraries will go to /usr/local/lib/mysql/.
So - just install a client from ports or packages, and you are set.
mysql.h is included in the mysql-client-xx port.
assuming you have a configure script or makefile you should set the LDFLAGS and CPPFLAGS environment variables to:
export LDFLAGS='-l /usr/local/lib'
export CPPFLAGS='-I /usr/local/include'
(or setenv, if using csh)
then ./configure and make as normal.
if you are compiling from the command line "gcc -o myprog mysource.c" just add the -I and -l options to your command and it should compile fine.
try: find /usr/local -iname 'mysql' to see files (headers, shared objects and binaries) you in fact have installed on your system.