一、报错信息
../exec/ProjectRun: symbol lookup error: ../exec/ProjectRun: undefined symbol: ComputeTimeDQL
二、Linux端测试
1、编译
[gbase@czg2 src]$ make
gcc -c -Wall -Wextra -fpic -O3 ./Gbase8aCApi.c -I ../include/Gbase8a/ -I ../../../Log/ -o ../temp/Gbase8aCApi.o
gcc -shared -Wall -Wextra -O3 ../temp/Gbase8aCApi.o -o ../libs/Gbase8a/x86_64_linux/libGbase8aCApi.so
gcc -Wall -Wextra -O3 -o ../exec/ProjectRun ../../../PublicFunction/PublicFunction.c ../../../Log/Log.c ./ProjectRun.c -I ../include/Gbase8a/ -I ../../../Log/ -L ../libs/Gbase8a/x86_64_linux/ -l Gbase8aCApi -l gbase -l gbaseclient
编译正常,没有出现任何报错和告警。
2、执行程序
[gbase@czg2 src]$ ../exec/ProjectRun
192.168.142.12 : Connect Db Ok!!!
client character set: utf8
../exec/ProjectRun: symbol lookup error: ../exec/ProjectRun: undefined symbol: ComputeTimeDQL
3、查看程序链接的动态库
[gbase@czg2 src]$ ldd ../exec/ProjectRun
linux-vdso.so.1 => (0x00007ffd16dcb000)
libGbase8aCApi.so => /opt/Developer/DataMigrationTool/C/Gbase8a-C-API/libs/Gbase8a/x86_64_linux/libGbase8aCApi.so (0x00007f2221971000)
libgbase.so.16 => /opt/Developer/ComputerLanguageStudy/C/DataStructureTestSrc/PublicFunction/Gbase8a/libs/Gbase8a/x86_64_linux/libgbase.so.16 (0x00007f222152a000)
libc.so.6 => /lib64/libc.so.6 (0x00007f222115c000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2220f40000)
libm.so.6 => /lib64/libm.so.6 (0x00007f2220c3e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2221b76000)
(1)排查思路
ldd ../exec/ProjectRun发现连接了一个同名的动态库libGbase8aCApi.so,这个同名的动态库中没有ComputeTimeDQL函数的定义,导致出现此错误。
(2)解决方法
方法一:修改文件名字和makefile文件,生成新的动态库名,治本。
方法二:修改环境变量$LD_LIBRARY_PATH中的两个同名动态库的前后顺序,治标,影响其他程序的运行。
我们选择第一种。
4、修改后
[gbase@czg2 src]$ make
gcc -c -Wall -Wextra -fpic -O3 ./Gbase8aOperate.c -I ../include/Gbase8a/ -I ../../../Log/ -o ../temp/Gbase8aOperate.o
gcc -shared -Wall -Wextra -O3 ../temp/Gbase8aOperate.o -o ../libs/Gbase8a/x86_64_linux/libGbase8aOperate.so
gcc -Wall -Wextra -O3 -o ../exec/ProjectRun ../../../PublicFunction/PublicFunction.c ../../../Log/Log.c ./ProjectRun.c -I ../include/Gbase8a/ -I ../../../Log/ -L ../libs/Gbase8a/x86_64_linux/ -l Gbase8aOperate -l gbase -l gbaseclient
[gbase@czg2 src]$ ldd ../exec/ProjectRun
linux-vdso.so.1 => (0x00007fffc15be000)
libGbase8aOperate.so => /opt/Developer/ComputerLanguageStudy/C/DataStructureTestSrc/PublicFunction/Gbase8a/libs/Gbase8a/x86_64_linux/libGbase8aOperate.so (0x00007f11f6693000)
libgbase.so.16 => /opt/Developer/ComputerLanguageStudy/C/DataStructureTestSrc/PublicFunction/Gbase8a/libs/Gbase8a/x86_64_linux/libgbase.so.16 (0x00007f11f624c000)
libc.so.6 => /lib64/libc.so.6 (0x00007f11f5e7e000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f11f5c62000)
libm.so.6 => /lib64/libm.so.6 (0x00007f11f5960000)
/lib64/ld-linux-x86-64.so.2 (0x00007f11f6896000)
[gbase@czg2 src]$ ../exec/ProjectRun
[2023-6]--[ Debug ]--Connect Db OK
[2023-6]--[ Debug ]--client character set: utf8
程序执行正常,我这里就不把程序结果打印出来了,大长了。