Compilation error: /usr/bin/ld: cannot find -lclnt

2019-07-20 18:07发布

问题:

While trying to compile a C program using make file, I am facing the following linking error described below.

I know this kind of issues are already discussed in many other posts, but I tried with solutions suggested in them but they all did not work.

/usr/bin/ld: cannot find -lclntsh

libclntsh.so and libclntsh.so.10.1 are present in oracle path /u01/app/oracle/product/10.2.0/lib and that is being given as -L option in make file. Still I am facing the issue:-

Linking yieldrpt ...
cc -v -g -D_HPUX_SOURCE -DPARETO -Wl,-aarchive -L/u01/app/oracle/product/10.2.0/lib/         yieldrpt.o  -lclntsh `cat /u01/app/oracle/product/10.2.0/lib/ldflags`   -lmalloc -ldl -lm   \
                -lmalloc -o yieldrpt
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --disable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-54)
/usr/libexec/gcc/i386-redhat-linux/4.1.2/collect2 --eh-frame-hdr -m elf_i386 --hash-style=gnu -dynamic-linker /lib/ld-linux.so.2 -o yieldrpt /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crti.o /usr/lib/gcc/i386-redhat-linux/4.1.2/crtbegin.o -L/u01/app/oracle/product/10.2.0/lib/ -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2/../../.. -aarchive yieldrpt.o -lclntsh -lnbeq10 -lnhost10 -lnus10 -lnldap10 -lldapclnt10 -lnsslb10 -lntcp10 -lntcps10 -lnsslb10 -lntcp10 -lntns10 -lmalloc -ldl -lm -lmalloc -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i386-redhat-linux/4.1.2/crtend.o     /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crtn.o
/usr/bin/ld: cannot find -lclntsh
collect2: ld returned 1 exit status
make: *** [yieldrpt] Error 1

Please let me know if any other info is needed. Thank you

回答1:

You are passing -aarchive to the linker. This is an HP/UX compatibility option that is synonymous with -Bstatic, which directs the linker not to link dynamic libraries. Hence your libclntsh.so is ignored. See the documentation

If you don't know why this option is there you may well remove it and try again. If you know it is necessary then you will have to find static libraries, including libclntsh.a to link against.



回答2:

If you have libclntsh.so.12.1 or similar is already installed you may try symlinking the library to libclntsh.so with the following command: ln -s /usr/lib/oracle/12.1/client64/lib/libclntsh.so.12.1 /usr/lib/oracle/12.1/client64/lib/libclntsh.so



回答3:

[oracle@em12c bin]$ pwd
/u01/em12c/middleware/oms/bin
[oracle@em12c bin]$ export ORACLE_HOME=/u01/em12c/middleware/oms
[oracle@em12c bin]$ ./genclntsh

[oracle@em12c bin]$ ls -l /u01/em12c/middleware/oms/lib32//libclntsh.so
lrwxrwxrwx. 1 oracle oinstall 17 Oct 23 22:16 /u01/em12c/middleware/oms/lib32//libclntsh.so -> libclntsh.so.11.1