作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试构建一个 C 程序的静态可执行文件,它需要 Postgresql libecpg-dev 包中的以下库:libecpg、libpq 和 libpgtypes。静态库 libecpg.a、libpq.a、libpgtypes.a 都位于与其动态版本/usr/lib 相同的位置。无论如何,我已经尝试添加 -L 选项作为它们的路径,但我得到了相同的结果。
我的可执行文件需要是静态的,以便二进制文件可以移植,这样用户就不必将库安装到他们的系统上就可以使用它。当我对动态库使用以下命令时,程序构建良好:(对于我正在使用的某些 Postgresql 函数,必须包含 -I 目录)
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
然而,编译器给我一长串“ undefined reference ”错误作为输出。有很多,但这里只是一小部分:
/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 选项(以及所有其他选项),但似乎没有任何效果。
最佳答案
我认为您不能再在现代 Linux 发行版中创建完全静态的非平凡可执行文件。但是you can statically include some specific libraries .
关于postgresql - 链接到静态库以构建静态可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17329796/
我正在开发一个 voip 调用应用程序。我需要做的是在接到来电时将 Activity 带到前台。我在应用程序中使用 Twilio,并在收到推送消息时开始调用。 问题是我试图在接到任何电话时显示 Act
我是一名优秀的程序员,十分优秀!