# libsmbclient-php



## JOAO BATISTA (Apr 14, 2016)

Greetings

I'm new in FreeBSD and I'm trying to set up libsmbclient-php, but found that it does not exist through the network installation portsnap and through pkg. In this way, I managed to find the https://github.com/eduardok/libsmbclient-php site to build but did not work.

Does anyone know help me?

Thank you!


----------



## zirias@ (Apr 15, 2016)

You should at least elaborate on the "did not work" part to get _some_ help. Of course, the first step should be to try and build it manually on your machine. So, if it doesn't work for you, tell us exactly what you did and what was the result.

For actually creating a port once you managed to build it manually, refer to the excellent 
FreeBSD Porter's Handbook. There are helpers for PHP modules available, maybe have a look at existing ports like archivers/php5-snappy. But that's just generic hints, as I said, if compiling manually doesn't work, tell us exactly _how_ it "doesn't work".


----------



## JOAO BATISTA (Apr 15, 2016)

Hi Zirias, thanks for answering.
Below is the error that is occurring when I try to compile the code:


```
root@RN-CLOUD01:/tmp # git clone git://github.com/eduardok/libsmbclient-php.git
Cloning into 'libsmbclient-php'...
remote: Counting objects: 571, done.
remote: Total 571 (delta 0), reused 0 (delta 0), pack-reused 571
Receiving objects: 100% (571/571), 186.96 KiB | 127.00 KiB/s, done.
Resolving deltas: 100% (359/359), done.
Checking connectivity... done.
root@RN-CLOUD01:/tmp # cd libsmbclient-php ; phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
root@RN-CLOUD01:/tmp/libsmbclient-php # ./configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
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 cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... amd64-unknown-freebsd10.3
checking host system type... amd64-unknown-freebsd10.3
checking target system type... amd64-unknown-freebsd10.3
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/lib/php/20131226
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable smbclient support... yes, shared
checking for libsmbclient support... yes, shared
checking for libsmbclient.h in default paths... found in /usr/local/include
checking for smbc_getOptionUserData in -lsmbclient... no
configure: error: Could not find libsmbclient.so or symbol smbc_getOptionUserData. Check version and config.log for more information.
root@RN-CLOUD01:/tmp/libsmbclient-php #
```

I researched on a website how to solve this problem and found the link below:

https://github.com/eduardok/libsmbclient-php/issues/14

But when I open the file to remove the parameter as indicated, this parameter does not exist in the file. Possibly it should have been updated.

Just to reinforce, I installed samba4 and samba36 to see if it solves the issue.

Using the locate(1) command, I managed to find the libsmbclient.so but still could not solve.

It is in this directory:
/usr/local/lib/libsmbclient.so


Can you help me?

Thank you!


----------



## cpm@ (Apr 15, 2016)

To look for libsmbclient in /usr/local/lib

`./configure --with-libsmbclient=/usr/local`


----------



## JOAO BATISTA (Apr 15, 2016)

Thanks for the help, cpm,

I did what you suggested and ran ./configure, but now when I try to run `make` shows the error below:


```
root@RN-CLOUD01:/tmp/libsmbclient-php # ./configure --with-libsmbclient=/usr/local
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
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 cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... amd64-unknown-freebsd10.3
checking host system type... amd64-unknown-freebsd10.3
checking target system type... amd64-unknown-freebsd10.3
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/lib/php/20131226
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable smbclient support... yes, shared
checking for libsmbclient support... yes, shared
checking for smbc_setOptionUseNTHash in -lsmbclient... no
checking for smbc_setPort in -lsmbclient... no
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
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 dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 196608
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... yes
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... freebsd10.3 ld.so
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... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
root@RN-CLOUD01:/tmp/libsmbclient-php # make
/bin/sh /tmp/libsmbclient-php/libtool --mode=compile cc  -I. -I/tmp/libsmbclient-php -DPHP_ATOM_INC -I/tmp/libsmbclient-php/include -I/tmp/libsmbclient-php/main -I/tmp/libsmbclient-php -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local/include  -DHAVE_CONFIG_H  -g -O2   -c /tmp/libsmbclient-php/smbclient.c -o smbclient.lo
mkdir .libs
cc -I. -I/tmp/libsmbclient-php -DPHP_ATOM_INC -I/tmp/libsmbclient-php/include -I/tmp/libsmbclient-php/main -I/tmp/libsmbclient-php -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /tmp/libsmbclient-php/smbclient.c  -fPIC -DPIC -o .libs/smbclient.o
In file included from /tmp/libsmbclient-php/smbclient.c:49:
./php_smbclient.h:44:10: fatal error: 'libsmbclient.h' file not found
#include <libsmbclient.h>
         ^
1 error generated.
*** Error code 1

Stop.
make: stopped in /tmp/libsmbclient-php
```


Do you know how to help me?

Thank you!


----------



## zirias@ (Apr 15, 2016)

This seems to be a bug in the libsmbclient autoconf check .. what might work is running `make CPPFLAGS=-I/usr/local/include` instead.

Forget about that, I just saw it is already there ... are you sure /usr/local/include/libsmbclient.h exists on your system?


----------



## JOAO BATISTA (Apr 15, 2016)

Hi Zirias,

Yes, I'm sure.

As follows:


```
root@RN-CLOUD01:/tmp/libsmbclient-php # locate libsmbclient.h
/usr/local/include/samba4/libsmbclient.h
```

I tried to do it as you described. I put the exact path as I noted above, then, it started to build but now it's showing another error.


```
root@RN-CLOUD01:/tmp/libsmbclient-php # make CPPFLAGS=-I/usr/local/include/samba4
/bin/sh /tmp/libsmbclient-php/libtool --mode=link cc -DPHP_ATOM_INC -I/tmp/libsmbclient-php/include -I/tmp/libsmbclient-php/main -I/tmp/libsmbclient-php -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local/include  -I/usr/local/include/samba4  -g -O2   -o ./smbclient.la -export-dynamic -avoid-version -prefer-pic -module -rpath /tmp/libsmbclient-php/modules  smbclient.lo smb_streams.lo -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lsmbclient
cc -shared  .libs/smbclient.o .libs/smb_streams.o  -L/usr/local/lib -lsmbclient  -Wl,-rpath -Wl,/usr/local/lib -Wl,-soname -Wl,smbclient.so -o ./.libs/smbclient.so
/usr/bin/ld: cannot find -lsmbclient
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.
make: stopped in /tmp/libsmbclient-php
```

Thank you!


----------



## zirias@ (Apr 15, 2016)

The file to look for now is libsmbclient.so. But this is a bit strange, this _should_ be installed in /usr/local/lib. You could try if a simple `ldconfig` as root solves the problem. If not, check whether this lib is present on your system and where exactly it is ...

*edit:* and again, I answered a bit too quickly, because AFAIR `ldconfig` is only for the dynamic linker to find libraries at runtime, so it won't help you here. But if you find the library in a nonstandard place, you could try compiling with `make CPPFLAGS=-I/usr/[....] LDFLAGS=-L/usr/local/whereever` -- not sure whether this is really a solution because maybe the lib wouldn't be found later at runtime.


----------



## JOAO BATISTA (Apr 15, 2016)

Greetings!!

I am very grateful for the help !!! It worked to compile and install php-smbclient ..

I do a step by step and publish this topic teaching as I did for others when they need to succeed also compile?

Thank you!


----------



## zirias@ (Apr 15, 2016)

Please try to run it first  Where did you find the lib? I still see the risk it isn't found at runtime ... I can't check for it right now because I have no FreeBSD box with installed libsmbclient available ...

And if it really works and you feel compelled to help others, I'd suggest you really go for creating a port


----------

