我想建立一个C程序,需要在PostgreSQL libecpg-dev软件包下列库的静态可执行文件:libecpg,那么libpq和libpgtypes。静态库libecpg.a,libpq.a和libpgtypes.a都与动态版本/ usr/lib位于同一位置。无论如何,我尝试添加-L选项作为他们的路径,但我得到了相同的结果。链接到静态库来构建静态可执行
我的可执行文件必须是静态的,这样二进制可以手提,使用户不必安装库到他们的系统中使用它。当我使用下面的命令与动态库该方案建立罚款:(使用-i目录必须包括对于一些PostgreSQL函数我使用)
gcc main.o -lecpg -lpq -lpgtypes -I/usr/include/postgresql -o program_name
当我尝试链接到静态图书馆,我使用下面的命令:
gcc -static main.o -lecpg -lpq -lpgtypes -I/usr/include/postgresql -o program_name
编译器,但是,给我的“未定义的引用”错误,输出一个长长的清单。有这么多,但这里是一个小样本:
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libecpg.a(descriptor.o):
In function `get_descriptors':
(.text+0xc3): undefined reference to `pthread_once'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libecpg.a(descriptor.o): In function `ECPGdeallocate_desc':
(.text+0x2c6): undefined reference to `pthread_setspecific'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libecpg.a(descriptor.o): In function `ECPGallocate_desc':
(.text+0x376): undefined reference to `pthread_setspecific'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libecpg.a(descriptor.o): In function `get_descriptors':
(.text+0xd2): undefined reference to `pthread_getspecific'
当我更改顺序如下:
gcc -I/usr/include/postgresql -static -lecpg -lpq -lpgtypes -o program_name main.o
编译器输出,而不是看起来像下面的(再次,只是一小部分):
main.c:(.text+0x5c6): undefined reference to `ECPGconnect'
main.c:(.text+0x83e): undefined reference to `ECPGdo'
main.c:(.text+0x843): undefined reference to `ECPGget_sqlca'
main.c:(.text+0x85c): undefined reference to `ECPGdisconnect'
main.c:(.text+0x87c): undefined reference to `ECPGget_sqlca'
我已经尝试使用-I选项四周(以及所有其他选项),但似乎没有任何工作。