Home > Backend Development > Golang > How to Build a Static CGO Executable with Oracle Libraries on Linux/Ubuntu?

How to Build a Static CGO Executable with Oracle Libraries on Linux/Ubuntu?

Barbara Streisand
Release: 2024-11-29 09:19:09
Original
154 people have browsed it

How to Build a Static CGO Executable with Oracle Libraries on Linux/Ubuntu?

Trying to Build Static CGO Executable with Oracle Libraries on Linux/Ubuntu: Unexpected Error

Problem:

Building a statically linked executable with CGO and Oracle libraries on Linux/Ubuntu results in an error during the build process, specifically failing to find the Oracle library -lclntsh.

Solution:

  1. Generate the Static Library (libclntst.a):
    a. Install the complete Oracle database package if not already done.
    b. Run $ORACLE_HOME/bin/genclntst to generate the missing static library libclntst12.a.
  2. Link with the Generated Library:
    a. Modify your build command to include the generated library libclntst12.a.
    b. Example: go build -work -x -ldflags " -v -linkmode external -extldflags -static -L/usr/lib/oracle/12.1/client64/lib -lclntst12" ${MAIN_SRC}
  3. Handle Missing Symbols (if any):
    a. Use ldd to check for unresolved symbols in the statically linked executable.
    b. Use nm to find the source of missing symbols in the Oracle libraries.
    c. Link with additional libraries to resolve missing symbols.
  4. Additional Notes:
    a. Static linking requires resolving all dependencies manually.
    b. For older Oracle versions, additional static libraries from ICC's runtime may be needed.

The above is the detailed content of How to Build a Static CGO Executable with Oracle Libraries on Linux/Ubuntu?. 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