gcc and g++

-bash-3.2$ LD_RUN_PATH=/lib/perl/current/lib:$LD_RUN_PATH; export LD_RUN_PATH
-bash-3.2$ g++ -I /lib/perl/current/include/ *.cpp -o genlic -lcrypto -L /lib/perl/current/lib/ -Wl,-V

The LD_RUN_PATH needs to be exported before compilation if non-standard library paths (i.e. other than /lib) are needed.
The first path (-I) above is for the .h include files necessary for compilation.
The second path (-L) is for the shared object files necessary for linking.
The -lcrypto specifies that the crypto shared object will be pulled in.
The -Wl,-V options specify verbosity of of linker output. ld is the linker, type `man ld` for more information.

About ldd

List dynamic dependencies of executable files or shared objects.

For example, for the genlic executable we created above
ldd genlic
linux-gate.so.1 => (0x00ed1000)
libcrypto.so.6 => /lib/libcrypto.so.6 (0x02808000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x0027b000)
libm.so.6 => /lib/libm.so.6 (0x00b88000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00cd7000)
libc.so.6 => /lib/libc.so.6 (0x009db000)
libdl.so.2 => /lib/libdl.so.2 (0x00b20000)
libz.so.1 => /usr/lib/libz.so.1 (0x00bd5000)
/lib/ld-linux.so.2 (0x009bd000)