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:
-
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.
-
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}
-
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.
-
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!