cygwin 中的 SQLite3 导致链接器错误
我正在尝试在 cygwin 中运行一个基本的“hello world”sqlite3 程序。我最初是通过 setup.exe 安装的,但是当我运行该程序时,我收到了链接器错误,例如“对 `_sqlite3_open' 的未定义引用”。我在编译时使用 -lsqlite3 开关。
位置在这里:
$ ls /usr/lib/ | grep sql
libsqlite3.a
libsqlite3.dll.a
libsqlite3.la
然后我尝试下载 sqlite3 源并手动编译它,但我得到了相同的错误。它安装到 /usr/local/lib
$ ls /usr/local/lib/ | grep sql
libsqlite3.a
libsqlite3.dll.a
libsqlite3.la
但我仍然收到这些链接器错误,而且我似乎不知道如何修复它?
$ gcc -lsqlite3 test.cc
test.cc: In function ‘int main()’:
test.cc:41: warning: deprecated conversion from string constant to ‘char*’
/tmp/ccKA3ZFa.o:test.cc:(.text+0x2d): undefined reference to `_sqlite3_open'
/tmp/ccKA3ZFa.o:test.cc:(.text+0x41): undefined reference to `_sqlite3_errmsg'
/tmp/ccKA3ZFa.o:test.cc:(.text+0xb6): undefined reference to `_sqlite3_prepare_v2'
/tmp/ccKA3ZFa.o:test.cc:(.text+0xca): undefined reference to `_sqlite3_errmsg'
/tmp/ccKA3ZFa.o:test.cc:(.text+0x10e): undefined reference to `_sqlite3_step'
/tmp/ccKA3ZFa.o:test.cc:(.text+0x12a): undefined reference to `_sqlite3_column_bytes'
/tmp/ccKA3ZFa.o:test.cc:(.text+0x140): undefined reference to `_sqlite3_column_text'
/tmp/ccKA3ZFa.o:test.cc:(.eh_frame+0x11): undefined reference to `___gxx_personality_v0'
collect2: ld returned 1 exit status
感谢您提供的任何帮助。干杯:)
I'm trying to get a basic "hello world" sqlite3 program going in cygwin. I had originally installed it from the setup.exe, but when I ran the program I got linker errors such as "undefined reference to `_sqlite3_open'". I AM using the -lsqlite3 switch when compiling.
The location is here:
$ ls /usr/lib/ | grep sql
libsqlite3.a
libsqlite3.dll.a
libsqlite3.la
Then I tried downloading the sqlite3 source and compiling it manually, but i get the same errors. It installed to /usr/local/lib
$ ls /usr/local/lib/ | grep sql
libsqlite3.a
libsqlite3.dll.a
libsqlite3.la
I'm still getting these linker errors though, and I can't seem to figure out how to fix it?
$ gcc -lsqlite3 test.cc
test.cc: In function ‘int main()’:
test.cc:41: warning: deprecated conversion from string constant to ‘char*’
/tmp/ccKA3ZFa.o:test.cc:(.text+0x2d): undefined reference to `_sqlite3_open'
/tmp/ccKA3ZFa.o:test.cc:(.text+0x41): undefined reference to `_sqlite3_errmsg'
/tmp/ccKA3ZFa.o:test.cc:(.text+0xb6): undefined reference to `_sqlite3_prepare_v2'
/tmp/ccKA3ZFa.o:test.cc:(.text+0xca): undefined reference to `_sqlite3_errmsg'
/tmp/ccKA3ZFa.o:test.cc:(.text+0x10e): undefined reference to `_sqlite3_step'
/tmp/ccKA3ZFa.o:test.cc:(.text+0x12a): undefined reference to `_sqlite3_column_bytes'
/tmp/ccKA3ZFa.o:test.cc:(.text+0x140): undefined reference to `_sqlite3_column_text'
/tmp/ccKA3ZFa.o:test.cc:(.eh_frame+0x11): undefined reference to `___gxx_personality_v0'
collect2: ld returned 1 exit status
Thanks for any help you can provide. Cheers :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是导致您出现问题的
-l
选项的位置。尝试执行此操作:按照以下记录:
您可以看到,当
-l
跟随其他参数时,不存在链接器错误。手册页中的相关位是(在
-l
的描述下):换句话说,在您指定
-lsqlite3
时,没有对任何 SQLite 函数的未解析引用,因此它们都不会被加载。稍后,当您加载
test.o
时,它确实有未解析的引用。不幸的是,由于您已经查看了 SQLite3 库并对其打了折扣,因此它们永远不会得到解决。因此你的错误。It's the placement of the
-l
option which is causing your problem. Try executing this instead:As per the following transcript:
You can see that, when the
-l
follows the other arguments, there is no linker error.The relevant bit from the man page is (under the description of
-l
):In other words, at the point where you specify
-lsqlite3
, there are no unresolved references to any of the SQLite functions so none of them are loaded.Later on, when you load
test.o
, it does have unresolved references. Unfortunately, since you've already looked at the SQLite3 library and discounted it, they will never be resolved. Hence your error.您可能在命令末尾需要您的库:
链接器通常从左到右搜索符号,并且 SQLite 符号在
test.cc
中引用,但在libsqlite3 中定义。一个。
You probably need your library at the end of the command:
The linker usually searches for symbols from the left to the right and the SQLite symbols are being referenced in
test.cc
but defined inlibsqlite3.a
.