Msphpsql: unable to install version 4.0.7+ on ubuntu 16.04 using pecl

Created on 25 Dec 2016  Â·  28Comments  Â·  Source: microsoft/msphpsql

Hi,
I'm trying to install sqlsrv and pdo_sqlsrv using pecl on php 7.0.14 however it fails with an error.
I was also following the tutorial at https://www.microsoft.com/en-us/sql-server/developer-get-started/php-ubuntu
Is anyone else experiencing the same issue?

The latest installable version for me is 4.0.6 and here's the part from pecl output

running: make
/bin/sh /tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/libtool --mode=compile g++ -std=c++11 -I. -I/tmp/pear/temp/sqlsrv -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/include -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/main -I/tmp/pear/temp/sqlsrv -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/main -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/TSRM -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext/date/lib -I/tmp/pear/temp/sqlsrv/shared/  -DHAVE_CONFIG_H  -g -O0 -std=c++11   -c /tmp/pear/temp/sqlsrv/conn.cpp -o conn.lo
mkdir .libs
 g++ -std=c++11 -I. -I/tmp/pear/temp/sqlsrv -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/include -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/main -I/tmp/pear/temp/sqlsrv -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/main -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/TSRM -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext/date/lib -I/tmp/pear/temp/sqlsrv/shared/ -DHAVE_CONFIG_H -g -O0 -std=c++11 -c /tmp/pear/temp/sqlsrv/conn.cpp  -fPIC -DPIC -o .libs/conn.o
/tmp/pear/temp/sqlsrv/conn.cpp:152:75: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
 char* ss_sqlsrv_conn::resource_name = static_cast<char *>("ss_sqlsrv_conn");
                                                                           ^
/bin/sh /tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/libtool --mode=compile g++ -std=c++11 -I. -I/tmp/pear/temp/sqlsrv -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/include -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/main -I/tmp/pear/temp/sqlsrv -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/main -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/TSRM -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext/date/lib -I/tmp/pear/temp/sqlsrv/shared/  -DHAVE_CONFIG_H  -g -O0 -std=c++11   -c /tmp/pear/temp/sqlsrv/util.cpp -o util.lo
 g++ -std=c++11 -I. -I/tmp/pear/temp/sqlsrv -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/include -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/main -I/tmp/pear/temp/sqlsrv -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/main -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/TSRM -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext/date/lib -I/tmp/pear/temp/sqlsrv/shared/ -DHAVE_CONFIG_H -g -O0 -std=c++11 -c /tmp/pear/temp/sqlsrv/util.cpp  -fPIC -DPIC -o .libs/util.o
/bin/sh /tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/libtool --mode=compile g++ -std=c++11 -I. -I/tmp/pear/temp/sqlsrv -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/include -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/main -I/tmp/pear/temp/sqlsrv -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/main -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/TSRM -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext/date/lib -I/tmp/pear/temp/sqlsrv/shared/  -DHAVE_CONFIG_H  -g -O0 -std=c++11   -c /tmp/pear/temp/sqlsrv/init.cpp -o init.lo
 g++ -std=c++11 -I. -I/tmp/pear/temp/sqlsrv -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/include -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/main -I/tmp/pear/temp/sqlsrv -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/main -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/TSRM -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext/date/lib -I/tmp/pear/temp/sqlsrv/shared/ -DHAVE_CONFIG_H -g -O0 -std=c++11 -c /tmp/pear/temp/sqlsrv/init.cpp  -fPIC -DPIC -o .libs/init.o
In file included from /root/.phpbrew/php/phpbrew7.0.14.dev/include/php/main/php_ini.h:24:0,
                 from /root/.phpbrew/php/phpbrew7.0.14.dev/include/php/main/fopen_wrappers.h:26,
                 from /root/.phpbrew/php/phpbrew7.0.14.dev/include/php/main/php.h:390,
                 from /tmp/pear/temp/sqlsrv/shared/core_sqlsrv.h:34,
                 from /tmp/pear/temp/sqlsrv/php_sqlsrv.h:25,
                 from /tmp/pear/temp/sqlsrv/init.cpp:19:
/tmp/pear/temp/sqlsrv/init.cpp: In function ‘int zm_activate_sqlsrv(int, int)’:
/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend/zend_ini.h:139:62: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
 #define INI_INT(name) zend_ini_long((name), sizeof(name)-1, 0)
                                                              ^
/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend/zend_ini.h:142:37: note: in expansion of macro ‘INI_INT’
 #define INI_BOOL(name) ((zend_bool) INI_INT(name))
                                     ^
/tmp/pear/temp/sqlsrv/init.cpp:639:45: note: in expansion of macro ‘INI_BOOL’
     SQLSRV_G( warnings_return_as_errors ) = INI_BOOL( INI_PREFIX INI_WARNINGS_RETURN_AS_ERRORS);
                                             ^
/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend/zend_ini.h:139:62: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
 #define INI_INT(name) zend_ini_long((name), sizeof(name)-1, 0)
                                                              ^
/tmp/pear/temp/sqlsrv/init.cpp:640:32: note: in expansion of macro ‘INI_INT’
     SQLSRV_G( log_severity ) = INI_INT( INI_PREFIX INI_LOG_SEVERITY);
                                ^
/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend/zend_ini.h:139:62: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
 #define INI_INT(name) zend_ini_long((name), sizeof(name)-1, 0)
                                                              ^
/tmp/pear/temp/sqlsrv/init.cpp:641:34: note: in expansion of macro ‘INI_INT’
     SQLSRV_G( log_subsystems ) = INI_INT( INI_PREFIX INI_LOG_SUBSYSTEMS);
                                  ^
/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend/zend_ini.h:139:62: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
 #define INI_INT(name) zend_ini_long((name), sizeof(name)-1, 0)
                                                              ^
/tmp/pear/temp/sqlsrv/init.cpp:642:40: note: in expansion of macro ‘INI_INT’
     SQLSRV_G( buffered_query_limit ) = INI_INT( INI_PREFIX INI_BUFFERED_QUERY_LIMIT);
                                        ^
/bin/sh /tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/libtool --mode=compile g++ -std=c++11 -I. -I/tmp/pear/temp/sqlsrv -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/include -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/main -I/tmp/pear/temp/sqlsrv -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/main -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/TSRM -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext/date/lib -I/tmp/pear/temp/sqlsrv/shared/  -DHAVE_CONFIG_H  -g -O0 -std=c++11   -c /tmp/pear/temp/sqlsrv/stmt.cpp -o stmt.lo
 g++ -std=c++11 -I. -I/tmp/pear/temp/sqlsrv -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/include -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/main -I/tmp/pear/temp/sqlsrv -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/main -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/TSRM -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext/date/lib -I/tmp/pear/temp/sqlsrv/shared/ -DHAVE_CONFIG_H -g -O0 -std=c++11 -c /tmp/pear/temp/sqlsrv/stmt.cpp  -fPIC -DPIC -o .libs/stmt.o
/tmp/pear/temp/sqlsrv/stmt.cpp:31:75: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
 char* ss_sqlsrv_stmt::resource_name = static_cast<char *>("ss_sqlsrv_stmt");   // not const for a reason.  see sqlsrv_stmt in php_sqlsrv.h
                                                                           ^
/bin/sh /tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/libtool --mode=compile g++ -std=c++11 -I. -I/tmp/pear/temp/sqlsrv -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/include -I/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/main -I/tmp/pear/temp/sqlsrv -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/main -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/TSRM -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/Zend -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext -I/root/.phpbrew/php/phpbrew7.0.14.dev/include/php/ext/date/lib -I/tmp/pear/temp/sqlsrv/shared/  -DHAVE_CONFIG_H  -g -O0 -std=c++11   -c /tmp/pear/temp/sqlsrv/shared/core_conn.cpp -o shared/core_conn.lo
/tmp/pear/temp/pear-build-rootbDXuVK/sqlsrv-4.0.8/libtool: line 1283: shared/core_conn.loT: No such file or directory
mkdir shared/.libs
mkdir: cannot create directory 'shared/.libs': No such file or directory
Makefile:202: recipe for target 'shared/core_conn.lo' failed
make: *** [shared/core_conn.lo] Error 1
ERROR: `make' failed
resolved

Most helpful comment

I have the same error, I could solve the issue with installing sudo apt install unixodbc-dev
After this I was able to install sqlsrv and pdo_sqlsrv without any problems.

All 28 comments

Same error on oficial PHP docker image (debian)

Same issue on docker image php:7.0-fpm with updated libc6 package.
The creation of the hidden .libs folder with mkdir shared/.libs seems like the culprit. (the -p flag is missing)

@ioweb-gr Can you try out the install instruction in README? it is the most recent file.

OK I have some further info regarding this issue. I installed a fresh virtual machine using Ubuntu 16.04 as in my original machine and tested on that system.

The pecl install sqlsrv seems to work with the provided php version on Ubuntu 16.04 from the repositories.

However, I then also tried to compile a new php version from source and and try to install sqlsrv on that one using pecl. It always fails when you try to install to the custom php version no matter what options you build php with.

Probably that's similar to what's happening using docker image.

@Hadis-Fard all the prerequisites on the link you sent are installed on both my Ubuntu 16.04 systems and although I can't try on my main system using the default php version, the result is consistent when compiling from source in both machines with the same error. I can confirm it worked OK for the fresh Ubuntu system with default PHP from repos.

@vandammeb I can confirm this. I tested it in a php:7.1 Docker container. _pecl install sqlsrv_ failed with the "cannot create directory 'shared/.libs'" error message. When I quickly create a "mkdir /tmp/pear/temp/pear-build-defaultuserXXXXXX/sqlsrv-4.0.8/shared" folder manually the build process completed successfully.

I have the same problem on php7.1-fpm docker image. sqlsrv-4.0.6 works perfect, both 4.0.7 and 4.0.8 fail on mkdir.

@GodWolen Seems like there in an issue with our 4.0.6+ PECL packages. We are looking into this actively.

@GodWolen @bla-kw @ioweb-gr Can you try the latest PECL package (4.1.6.1)?

sudo pecl install sqlsrv-4.1.6.1

@meet-bhagdev , I actually came across this issue today when attempting to install sqlsrv-4.0.8 on a docker image from pecl. I updated to 4.1.6.1 and the fail did not occur.

Cheers.

I've managed to install it as well. Nice job

Awesome! @all we are going to close this now. v4.1.6 fixes this issue. Feel free to reopen if you are still running into problems.

Im getting the following error

cc1plus: error: unrecognized command line option "-std=c++11"
cc1plus: error: unrecognized command line option "-std=c++11"
make: * [conn.lo] Error 1
ERROR: `make' failed

config

PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012

gcc -v
gcc version 4.8.2 20140120 (Red Hat 4.8.2-15) (GCC)

@jebarco1 What is the output for g++ -v?

Hi,
I'm getting the following when trying sudo pecl install sqlsrv (also with sudo pecl install sqlsrv-4.1.6.1) :

libtool: link: cc -shared -fPIC -DPIC .libs/conn.o .libs/util.o .libs/init.o .libs/stmt.o shared/.libs/core_conn.o shared/.libs/core_results.o shared/.libs/core_stream.o shared/.libs/core_init.o shared/.libs/core_stmt.o shared/.libs/core_util.o shared/.libs/FormattedPrint.o shared/.libs/localizationimpl.o shared/.libs/StringFunctions.o -lstdc++ -lodbc -lodbcinst -g -O2 -Wl,-soname -Wl,sqlsrv.so -o .libs/sqlsrv.so
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libodbc.a(SQLAllocHandle.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libodbc.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:223: recipe for target 'sqlsrv.la' failed
make: * [sqlsrv.la] Error 1
ERROR: 'make' failed

My config :
PHP 7.0.18-0ubuntu0.16.04.1 (cli) ( NTS )
Zend Engine v3.0.0 (with Zend OPcache v7.0.18-0ubuntu0.16.04)
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)

I also placed php_pdo_sqlsrv_7_nts.so in /usr/local/lib/ but don't know how to manually install it in PHP or in odbc ini file..

Can you help me ?
What I need is accessing a remote MS SQL server

Hi @Meloman-zz ,

Please follow these steps to load php_pdo_sqlsrv_7_nts.so

  1. Get the path php.ini location.

    php --ini | grep "Loaded Configuration"

  2. Add the driver to php.ini file.

    echo "extension=path_to_driver/php_pdo_sqlsrv_7_nts.so" >> path_to_ini/php.ini

  3. Verify that the driver is loaded.

    php --ri pdo_sqlsrv

Regarding the PECL install issue, looks like you are missing a shared dependency or it is static. Let me know if you were able to load php_pdo_sqlsrv_7_nts.so.

Hi,
Thanks for answering me :+1:

So, the command for me is :
echo "extension=/usr/local/lib/php_pdo_sqlsrv_7_nts.so" >> /etc/php/7.0/apache2/php.ini

After that I restarted apache and run php --ri pdo_sqlsrv :
Extension 'pdo_sqlsrv' not present.

If I execute php --ri pdo I have :
PDO
PDO support => enabled
PDO drivers => mysql

So I just found that I need to insert it in the cli/php.ini instead of the apache2/php.ini but the same error comes again about the libodbc.so.2 missing when I execute php --ri pdo_sqlsrv :

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php_pdo_sqlsrv_7_nts.so' - libodbc.so.2: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/odbc.so' - libodbc.so.2: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/pdo_odbc.so' - libodbc.so.2: cannot open shared object file: No such file or directory in Unknown on line 0
Extension 'pdo_sqlsrv' not present.

I suspect unixODBC is not properly installed in your machine. Please post the output of the following commands:

1. odbcinst -j
2. odbcinst -q -d -n "ODBC Driver 13 for SQL Server"
3. sudo find /usr 2>/dev/null -name "libodbc*"
4. php -i | grep "Configure Command"

odbcinst -j
unixODBC 2.3.1
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/servadm/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
servadm@demo-ws-int:~$

odbcinst -q -d -n "ODBC Driver 13 for SQL Server"
[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.8.0
UsageCount=1

sudo find /usr 2>/dev/null -name "libodbc*"
/usr/local/freetds-0.91/vms/libodbc.opt
/usr/share/doc/libodbc1
/usr/lib/x86_64-linux-gnu/libodbc.so
/usr/lib/x86_64-linux-gnu/libodbcinst.so.2.0.0
/usr/lib/x86_64-linux-gnu/libodbc.a
/usr/lib/x86_64-linux-gnu/libodbcinst.so.1
/usr/lib/x86_64-linux-gnu/libodbccr.so
/usr/lib/x86_64-linux-gnu/libodbcinst.a
/usr/lib/x86_64-linux-gnu/libodbcinst.so
/usr/lib/x86_64-linux-gnu/libodbccr.a
/usr/lib/x86_64-linux-gnu/libodbcinst.so.2
/usr/lib/x86_64-linux-gnu/odbc/libodbcdrvcfg1S.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcdrvcfg2S.so
/usr/lib/x86_64-linux-gnu/odbc/libodbctxtS.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcnnS.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcminiS.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcpsqlS.so

php -i | grep "Configure Command"
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php_pdo_sqlsrv_7_nts.so' - libodbc.so.2: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/odbc.so' - libodbc.so.2: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/pdo_odbc.so' - libodbc.so.2: cannot open shared object file: No such file or directory in Unknown on line 0

@Meloman-zz ,

Your unixODBC installation is missing libodbc.so.2. You might have accidentally removed that file or unixODBC installation did not finish properly. You can run apt-cache policy unixodbc to display the package information.

I would suggest to uninstall unixodbc and install the latest package. If the current unixodbc package was installed with apt-get, you can run sudo apt-get purge unixodbc && sudo apt autoremove. If you installed unixodbc from a different source, you will need to remove its files manually. After uninstalling the package, run sudo find /usr 2>/dev/null -name "libodbc*" to make sure that, there are no libodbc files in /usr/lib/x86_64-linux-gnu/ folder.

Once uninstall is done, you can run sudo apt-get update && sudo apt-get install unixodbc to install the new package.

You can also check this page for end to end installation instructions.

Let me know if this helps.

Well, Yes I know that a file is missing, but not why and how to fix it :unamused:

So, thanks a lot for your help :+1:

Running apt-cache policy unixodbc gives :
unixodbc:
Installed: 2.3.1-4.1
Candidate: 2.3.1-4.1
Version table:
* 2.3.1-4.1 500
500 http://ch.archive.ubuntu.com/ubuntu xenial/main amd64 Packages
100 /var/lib/dpkg/status


I just run sudo apt-get purge unixodbc && sudo apt autoremovefollowed by sudo apt-get update && sudo apt-get install unixodbc It seems to be OK.


Now When I execute again odbcinst -q -d -n "ODBC Driver 13 for SQL Server" :
odbcinst: SQLGetPrivateProfileString failed with .

And for find /usr 2>/dev/null -name "libodbc*" :
/usr/local/freetds-0.91/vms/libodbc.opt
/usr/share/doc/libodbc1
/usr/lib/x86_64-linux-gnu/libodbcinst.so.2.0.0
/usr/lib/x86_64-linux-gnu/libodbcinst.so.1
/usr/lib/x86_64-linux-gnu/libodbcinst.so.2
/usr/lib/x86_64-linux-gnu/odbc/libodbcdrvcfg1S.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcdrvcfg2S.so
/usr/lib/x86_64-linux-gnu/odbc/libodbctxtS.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcnnS.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcminiS.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcpsqlS.so


I called this first sudo pecl search sqlsrv :
Retrieving data...0%
.Matched packages, channel pecl.php.net:
Package Stable/(Latest) Local
pdo_sqlsrv 4.2.0preview (devel) Microsoft Drivers for PHP for SQL Server (PDO_SQLSRV)
sqlsrv 4.2.0preview (devel) Microsoft Drivers for PHP for SQL Server (SQLSRV)


So, I'll try to install the SQL driver again with command pecl install sqlsrv and it stops with following error (same result with pecl install pdo_sqlsrv) :
downloading sqlsrv-4.0.8.tgz ...
Starting to download sqlsrv-4.0.8.tgz (192,155 bytes)
.........................................done: 192,155 bytes
33 source files, building
running: phpize
Configuring for:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012
building in /tmp/pear/temp/pear-build-rootQz2kj5/sqlsrv-4.0.8
running: /tmp/pear/temp/sqlsrv/configure --with-php-config=/usr/bin/php-config
...
In file included from /tmp/pear/temp/sqlsrv/shared/typedefs_for_linux.h:23:0,
from /tmp/pear/temp/sqlsrv/shared/winnls.h:24,
from /tmp/pear/temp/sqlsrv/shared/FormattedPrint.h:24,
from /tmp/pear/temp/sqlsrv/shared/core_sqlsrv.h:40,
from /tmp/pear/temp/sqlsrv/php_sqlsrv.h:25,
from /tmp/pear/temp/sqlsrv/conn.cpp:20:
/tmp/pear/temp/sqlsrv/shared/xplat.h:36:17: fatal error: sql.h: No such file or directory
#include
^
compilation terminated.
Makefile:194: recipe for target 'conn.lo' failed
make: * [conn.lo] Error 1
ERROR: `make' failed


I installed missing unixodbc-dev and run again, now the error is not the same :
libtool: link: cc -shared -fPIC -DPIC .libs/pdo_dbh.o .libs/pdo_parser.o .libs/pdo_util.o .libs/pdo_init.o .libs/pdo_stmt.o shared/.libs/core_conn.o shared/.libs/ce_results.o shared/.libs/core_stream.o shared/.libs/core_init.o shared/.libs/core_stmt.o shared/.libs/core_util.o shared/.libs/FormattedPrint.o shared/.libs/localizaonimpl.o shared/.libs/StringFunctions.o -lstdc++ -lodbc -g -O2 -Wl,-soname -Wl,pdo_sqlsrv.so -o .libs/pdo_sqlsrv.so
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libodbc.a(SQLAllocHandle.o): relocation R_X86_64_32 against '.rodata.str1.8' can not be used wn making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libodbc.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:225: recipe for target 'pdo_sqlsrv.la' failed
make:
[pdo_sqlsrv.la] Error 1
ERROR: 'make' failed
*

The same as 7 days ago !
This is going to make me crazy.

Hi @Meloman-zz,

This is what find /usr 2>/dev/null -name "libodbc*" returns on my clean Ubuntu 16.04 VM after installing unixodbc with sudo apt-get install unixodbc

/usr/lib/x86_64-linux-gnu/libodbccr.so.1
/usr/lib/x86_64-linux-gnu/libodbccr.so.2.0.0
/usr/lib/x86_64-linux-gnu/libodbc.so.2
/usr/lib/x86_64-linux-gnu/libodbccr.so.2
/usr/lib/x86_64-linux-gnu/libodbcinst.so.2
/usr/lib/x86_64-linux-gnu/odbc/libodbcnnS.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcpsqlS.so
/usr/lib/x86_64-linux-gnu/odbc/libodbctxtS.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcdrvcfg2S.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcdrvcfg1S.so
/usr/lib/x86_64-linux-gnu/odbc/libodbcminiS.so
/usr/lib/x86_64-linux-gnu/libodbc.so.2.0.0
/usr/lib/x86_64-linux-gnu/libodbcinst.so.1
/usr/lib/x86_64-linux-gnu/libodbc.so.1
/usr/lib/x86_64-linux-gnu/libodbcinst.so.2.0.0
/usr/share/lintian/overrides/libodbc1
/usr/share/doc/libodbc1

Your unixodbc installation is still broken. Please post the full stacktrace of the following commands in the same order, I will try to figure out what went wrong.

1. sudo apt-get purge unixodbc && sudo apt autoremove
2. find /usr 2>/dev/null -name "libodbc*"
3. sudo apt-get update && sudo apt-get install unixodbc
4. find /usr 2>/dev/null -name "libodbc*"
5. dpkg-query -L libodbc1

Ok @ulvii I run this 5 steps in this order :

  1. sudo apt-get purge unixodbc && sudo apt autoremove
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following packages will be REMOVED:
    msodbcsql* mssql-tools* unixodbc* unixodbc-dev*
    0 upgraded, 0 newly installed, 4 to remove and 11 not upgraded.
    After this operation, 1,822 kB disk space will be freed.
    Do you want to continue? [Y/n] Y
    (Reading database ... 111612 files and directories currently installed.)
    Removing mssql-tools (14.0.6.0-1) ...
    Purging configuration files for mssql-tools (14.0.6.0-1) ...
    Removing msodbcsql (13.1.8.0-1) ...
    Purging configuration files for msodbcsql (13.1.8.0-1) ...
    dpkg: warning: while removing msodbcsql, directory '/opt' not empty so not removed
    Removing unixodbc-dev (2.3.1-4.1) ...
    Removing unixodbc (2.3.1-4.1) ...
    Processing triggers for man-db (2.7.5-1) ...
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.

  1. find /usr 2>/dev/null -name "libodbc*"
    /usr/local/freetds-0.91/vms/libodbc.opt
    /usr/share/doc/libodbc1
    /usr/lib/x86_64-linux-gnu/libodbcinst.so.2.0.0
    /usr/lib/x86_64-linux-gnu/libodbcinst.so.1
    /usr/lib/x86_64-linux-gnu/libodbcinst.so.2
    /usr/lib/x86_64-linux-gnu/odbc/libodbcdrvcfg1S.so
    /usr/lib/x86_64-linux-gnu/odbc/libodbcdrvcfg2S.so
    /usr/lib/x86_64-linux-gnu/odbc/libodbctxtS.so
    /usr/lib/x86_64-linux-gnu/odbc/libodbcnnS.so
    /usr/lib/x86_64-linux-gnu/odbc/libodbcminiS.so
    /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
    /usr/lib/x86_64-linux-gnu/odbc/libodbcpsqlS.so

  1. sudo apt-get update && sudo apt-get install unixodbc
    Hit:1 http://ch.archive.ubuntu.com/ubuntu xenial InRelease
    Get:2 http://ch.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
    Get:3 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
    Get:4 http://ch.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
    Get:5 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [291 kB]
    Get:6 http://ch.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [565 kB]
    Hit:7 https://packages.microsoft.com/ubuntu/16.04/prod xenial InRelease
    Hit:8 https://apt-mo.trafficmanager.net/repos/mssql-ubuntu-xenial-release xenial InRelease
    Get:9 http://security.ubuntu.com/ubuntu xenial-security/main i386 Packages [275 kB]
    Hit:10 https://packages.microsoft.com/ubuntu/16.04/mssql-server xenial InRelease
    Get:11 http://ch.archive.ubuntu.com/ubuntu xenial-updates/main i386 Packages [547 kB]
    Get:12 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en [124 kB]
    Get:13 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [139 kB]
    Get:14 http://security.ubuntu.com/ubuntu xenial-security/universe i386 Packages [125 kB]
    Get:15 http://security.ubuntu.com/ubuntu xenial-security/universe Translation-en [72.2 kB]
    Get:16 http://ch.archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [228 kB]
    Get:17 http://ch.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [488 kB]
    Get:18 http://ch.archive.ubuntu.com/ubuntu xenial-updates/universe i386 Packages [470 kB]
    Get:19 http://ch.archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [193 kB]
    Fetched 3,824 kB in 3s (1,161 kB/s)
    Reading package lists... Done
    W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-release.list:1
    W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-release.list:1
    W: Target Translations (main/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-release.list:1
    W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-release.list:1
    W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-tools.list:1
    W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-tools.list:1
    W: Target Translations (main/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-tools.list:1
    W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-tools.list:1
    W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-release.list:1
    W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-release.list:1
    W: Target Translations (main/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-release.list:1
    W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-release.list:1
    W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-tools.list:1
    W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-tools.list:1
    W: Target Translations (main/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-tools.list:1
    W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list.d/msprod.list:1 and /etc/apt/sources.list.d/mssql-tools.list:1
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following NEW packages will be installed:
    unixodbc
    0 upgraded, 1 newly installed, 0 to remove and 22 not upgraded.
    Need to get 0 B/20.5 kB of archives.
    After this operation, 88.1 kB of additional disk space will be used.
    Selecting previously unselected package unixodbc.
    (Reading database ... 111550 files and directories currently installed.)
    Preparing to unpack .../unixodbc_2.3.1-4.1_amd64.deb ...
    Unpacking unixodbc (2.3.1-4.1) ...
    Processing triggers for man-db (2.7.5-1) ...
    Setting up unixodbc (2.3.1-4.1) ...

  1. find /usr 2>/dev/null -name "libodbc*"
    /usr/local/freetds-0.91/vms/libodbc.opt
    /usr/share/doc/libodbc1
    /usr/lib/x86_64-linux-gnu/libodbcinst.so.2.0.0
    /usr/lib/x86_64-linux-gnu/libodbcinst.so.1
    /usr/lib/x86_64-linux-gnu/libodbcinst.so.2
    /usr/lib/x86_64-linux-gnu/odbc/libodbcdrvcfg1S.so
    /usr/lib/x86_64-linux-gnu/odbc/libodbcdrvcfg2S.so
    /usr/lib/x86_64-linux-gnu/odbc/libodbctxtS.so
    /usr/lib/x86_64-linux-gnu/odbc/libodbcnnS.so
    /usr/lib/x86_64-linux-gnu/odbc/libodbcminiS.so
    /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
    /usr/lib/x86_64-linux-gnu/odbc/libodbcpsqlS.so

  1. dpkg-query -L libodbc1
    /.
    /usr
    /usr/share
    /usr/share/doc
    /usr/share/doc/libodbc1
    /usr/share/doc/libodbc1/changelog.gz
    /usr/share/doc/libodbc1/README.Debian
    /usr/share/doc/libodbc1/copyright

Hi @Meloman-zz ,

Apparently apt-get purge unixodbc did not succeed. Otherwise the second step would have had no output. You need to uninstall libodbc1, odbcinst and odbcinst1debian2 packages as well, because looks they were installed separately (or some other packages that you have installed on the system require them). Since the packages I mentioned above can be a dependency for some other packages, you should be careful when removing them.

I have the same error, I could solve the issue with installing sudo apt install unixodbc-dev
After this I was able to install sqlsrv and pdo_sqlsrv without any problems.

@schmanat thanks bro u saved my day

@schmanat thanks a lot

@schmanat thanks mate

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benyanke picture benyanke  Â·  6Comments

parite picture parite  Â·  3Comments

luizzz picture luizzz  Â·  5Comments

Grglrglrg picture Grglrglrg  Â·  4Comments

arunchandarQA picture arunchandarQA  Â·  3Comments