Home > Backend Development > Golang > How to Resolve Static Linking Errors with Oracle Libraries in CGO Applications?

How to Resolve Static Linking Errors with Oracle Libraries in CGO Applications?

Patricia Arquette
Release: 2024-11-20 22:01:13
Original
811 people have browsed it

How to Resolve Static Linking Errors with Oracle Libraries in CGO Applications?

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:

  1. Generate Libclntst Library: Run the genclntst tool located in Oracle's bin directory to create a static version of libclntst: $ORACLE_HOME/bin/genclntst.
  2. Link to Generated Library: Recompile the application and link it with the newly generated libclntst library.
  3. Identify Missing Symbols: Use the nm tool to analyze the linker errors and identify missing symbols.
  4. Resolve Remaining Symbols: In some cases, additional static libraries may be necessary to resolve the missing symbols. For older Oracle versions, these can include ICC runtime libraries.

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template