Resolving Static Oracle Library Issue for CGO Executable
Issue Overview:
When compiling a Go application with CGO enabled and Oracle libraries, errors occur during static link. Specifically, the GCC linker cannot find the required Oracle library, libclntsh. Despite specifying the library path during compilation, the issue persists.
Solution:
Follow these steps to resolve the issue:
Example:
For 11gR2, the following command successfully resolves the issue:
/usr/bin/c++ -Wall -ggdb3 -fPIC \ CMakeFiles/opassgen.dir/opassgen.cpp.o \ CMakeFiles/opassgen.dir/dbutils.cpp.o \ CMakeFiles/opassgen.dir/common.cpp.o \ CMakeFiles/opassgen.dir/crypto.cpp.o \ n.o -o opassgen \ -rdynamic -static-libgcc -L. -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic \ /home/oracle/ivan/openssl-1.0.1t/libcrypto.a \ /oracle/u01/db/11.2.0.4/lib/libclntst11.a \ /oracle/u01/db/11.2.0.4/lib/libippdcmerged.a \ /oracle/u01/db/11.2.0.4/lib/libippsmerged.a \ -Wl,--whole-archive libtrotl.a -Wl,--no-whole-archive \ -lpthread -ldl
Remember, manually resolving dependencies is necessary when statically linking. In this example, libclntst11.a depends on libippdcmerged.a and libippsmerged.a.
The above is the detailed content of How to Resolve Static Linking Errors with Oracle Libraries in CGO Applications?. For more information, please follow other related articles on the PHP Chinese website!