# PAM module example - build



## izotov (Nov 11, 2010)

Hi, 
How should I build the example PAM module found in http://www.freebsd.org/doc/en/articles/pam/pam-sample-module.html?

I used the following commands to build:

```
$ gcc -fPIC -c pam_module.c
$ ld -x --shared -o pam_module.so pam_module.o
```

And when I try to use the module I get the following message in /var/log/messages though the module is at the right place:

```
openpam_load_module(): no pam_module.so found
```


----------



## expl (Nov 11, 2010)

The sample module depends on libcrypt.
You can use Makefile like this to build your module easily:


```
NO_PROFILE=
NO_INSTALLLIB=
.include <bsd.own.mk>

LIB=	pam_module
SHLIB_NAME?=	${LIB}.so.1
SRCS=	pam_module.c

DPADD= ${LIBCRYPT}
LDADD= -lcrypt

.include <bsd.lib.mk>
```


----------



## izotov (Nov 12, 2010)

Yes, -lcrypt was missing, thanks!
I am a bit newbie in things like this so please help me: how should I know that my module depends on libcrypt?


----------



## expl (Nov 12, 2010)

izotov said:
			
		

> Yes, -lcrypt was missing, thanks!
> I am a bit newbie in things like this so please help me: how should I know that my module depends on libcrypt?



When you are writing your own module you should know what functions belong to what library. But when you are building someone else's code like now you can simply link the module as executable and watch for linker errors regarding missing symbols OR write a simple program using dlopen(3) to debug shared libraries.


----------

