使用libpq与Visual Studios 2013,编译为DLL [英] Using libpq with Visual Studios 2013, Compiling to a DLL
问题描述
我正在使用Visual Studios 2013创建一个.dll。该项目包括libpq功能。
对于其他stackoverflow文章,以及我在互联网上发现的其他来源,我已经(据我所知)正确添加了postgres lib和include目录到项目。但是,当我去构建项目时,它返回一些未解决的外部符号错误。
我的路径是 C:\Program Files\PostresSQL\9.3\ ...
所以我让它们在附加库/包含目录字段中用引号括起来。我在项目中包含了 libpq-fe.h
头文件...我只是不知道我做错了什么。另一个注意事项,我可以使用带有-I,-L和-lpq标志的g ++从命令行编译一个测试程序,但是我不知道如何从命令行编译到.dll(加上它增加了我不想处理的复杂性)。
这些是我的具体错误得到:
1&sql_arma.obj:error LNK2001:未解析的外部符号_PQconnectdb
1> sql_arma.obj:错误LNK2001:未解决的外部符号_PQstatus
1> sql_arma.obj:错误LNK2001:未解析的外部符号_PQerrorMessage
1> sql_arma.obj:错误LNK2001:未解决的外部符号_PQfinish
1> C:\ Users\tills13\documents\visual studio 2013\Projects\sql_arma\Release\sql_arma.dll:致命错误LNK1120:4个未解决的外部文件
如下所述,我已经在源文件中包含了 #pragma comment(lib,libpq.lib)
对于我的项目,我sti会收到这些错误。
我已经成功编译了示例程序通过设置这些项目属性:
- 添加
< pgsql安装路径> \include
和\lib
到 VC ++目录 - >包含和 - >库相应地 - 将
libpq.lib
添加到链接器 - >输入 - >其他依赖关系
这是引用第三方库的标准方式。只是他们建议为基础目录使用环境变量,以避免在VCS下修补项目。
- 能够从VS中运行应用程序(无论是否进行调试),我还在调试中指定了
PATH =%PATH%;< pgsql安装路径> \bin
- >环境,因为该目录不在我的系统上的PATH
中。
I'm trying to create a .dll with Visual Studios 2013. The project includes libpq functionality.
Per other stackoverflow posts, and other sources I've found on the internet, I've (as far as I'm aware) correctly added the postgres lib and include directories to the project. However, when I go to build the project, it returns a number of "unresolved external symbol" errors.
My paths are C:\Program Files\PostresSQL\9.3\...
so I have them surrounded by quotation marks in the Additional Library/Include Directory fields. I've included the libpq-fe.h
header file in the project... I'm just not sure what I'm doing wrong.
Another note, I can compile a test program from the command line using g++ with the -I, -L, and -lpq flags, but I'm not sure how to compile to a .dll from the command line (plus it adds complexity that I just don't want to deal with).
These are the specific errors I'm getting:
1>sql_arma.obj : error LNK2001: unresolved external symbol _PQconnectdb
1>sql_arma.obj : error LNK2001: unresolved external symbol _PQstatus
1>sql_arma.obj : error LNK2001: unresolved external symbol _PQerrorMessage
1>sql_arma.obj : error LNK2001: unresolved external symbol _PQfinish
1>C:\Users\tills13\documents\visual studio 2013\Projects\sql_arma\Release\sql_arma.dll : fatal error LNK1120: 4 unresolved externals
I have, as suggested below, included #pragma comment(lib, "libpq.lib")
in the source file for my project, I still receive these errors.
I've successfully compiled the sample program by setting these project properties:
- Add
<pgsql install path>\include
and\lib
to VC++ Directories->Include and ->Library, correspondingly - Add
libpq.lib
to Linker->Input->Additional dependencies
This is the standard way to reference 3rd-party libs. It's just that they recommend using environment variables for their "base dirs" to avoid patching the project when it's under a VCS.
- To be able to run the app from VS (both with and without debugging), I also specified
PATH=%PATH%;<pgsql install path>\bin
in Debugging->Environment since this dir isn't inPATH
on my system.
这篇关于使用libpq与Visual Studios 2013,编译为DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!