golang go-oci8 configuration and problem solving

Up to now (2020.01.19), golang language which connected the most suitable oracle driver is github.com/godror/godror , the library uses open source oracle official odpi-c, there is no messy configuration process, we recommend using.

Next is the go-oci8 this article to introduce, and to use this stuff to configure a lot of trouble, configure the recording process below.

Development environment configuration

1. The first step in preparation for the oracle oci8 related lib and include c language header files, etc.

   In fact, go-oci8 official documents written in concise or complete installation oracle client, or install oracle instant client alone. Most programmers will be installed inside the computer oracle client, pay attention to the installation of a few options:

If you install oracle client time before your machine is not installed inside InstantClient, you can run oracle client installation program again, select InstantClient then install it again, or choose to pay attention when installing the original path, not for the individual then get hold of a new path .

The second way is the oracle instantClient solution for download from the website alone compressed using oracle, oracle instantclient about 70 M, need extra attention to download a 2M much SDK header files, or you download oracle instantClient missing include and lib files.

Optimistic about the second you need to download the SDK is as above with the text archive as a 2.7M.

Above two methods you can make your machine inside oracle instantclient and .h header files need to use the compiler.

2. Second, the configuration related pkg-config

   I was inside the machine pkg-config in mingw64 inside, you can knock where pkg-config to view the file location, as shown below:

 同时我发现我机器里面的mingw32的bin里面就没有这个pkg-config.exe文件,如果你的机器用的是mingw32的话看看是否换成mingw64就能找到这个文件了。 

3.第三步,配置oci8.pc文件

    如果编译程序时找不到oci8.pc文件会提示下面这样的错误:

解决办法是新建一个PKG_CONFIG_PATH的环境变量,随便指向一个位置,后续把oci8.pc放到那个对应的位置即可。

oci8.pc这个文件可以从go-oci8目录里面找到。

oci8.pc文件复制过去以后,需要用文本编辑工具修改oci8.pc里面的路径,把include和lib两个路径改为自己本机安装的oracle instant client路径。

然后验证一下pkg-config能不能找到这个oci8,可以在命令行敲pkg-config --cflags --libs oci8

如果出现的结果是这样的:

并且后续编译的时候提示:

这是因为oci8.pc里面的路径符号写的不对,windows平台不能用\,要用/ ,这是我的oci8.pc里面的配置内容:

prefix=/devel/target/1.0
exec_prefix=${prefix}
oralib=D:/oracle/instantclient_12_2/sdk/lib/msvc
orainclude=D:/oracle/instantclient_12_2/sdk/include
gcclib=d:/mingw64/lib
gccinclude=d:/mingw64/include
glib_genmarshal=glib-genmarshal
gobject_query=gobject-query
glib_mkenums=glib-mkenums

Name: oci8
Version: 12.2
Description: oci8 library
Libs: -L${oralib} -L${gcclib} -loci
Libs.private: 
Cflags: -I${orainclude} -I${gccinclude}

再次强调,即便是windows平台,路径符号也要用“/”!

最后的最后,go-oci8能正常编译了,但是有中文乱码问题,换成用github.com/godror/godror就啥事没有,非常的好用。

发布了177 篇原创文章 · 获赞 21 · 访问量 50万+

Guess you like

Origin blog.csdn.net/peihexian/article/details/104016061