[英]Build with libpqxx in C++11 on Kdevelop
我正在尝试构建一个需要lipqxx功能的C ++程序。 我在Ubuntu上,正在尝试使用Kdevelop。
我使用Code :: Blocks成功完成了此操作,但我正在尝试寻找更好的IDE。
现在,我对Kdevelop所做的工作。 我创建了一个简单的示例:
#include <pqxx/pqxx>
int main(int argc, char **argv) {
pqxx::connection c("dbname=xx host=localhost user=xx password=xx");
return 0;
}
我修改了CmakeList.txt以包含pqxx目录并与libpqxx.so链接:
cmake_minimum_required(VERSION 2.6)
project(testkdev)
include_directories ("/usr/include/pqxx")
LINK_DIRECTORIES("/usr/lib")
add_executable(testkdev main.cpp)
TARGET_LINK_LIBRARIES(testkdev libpqxx.so)
install(TARGETS testkdev RUNTIME DESTINATION bin)
在这一点上,构建过程的工作 。
但是我需要做其他事情,我想在C ++ 11中工作。 因此,我添加了-std = c ++ 11选项,右键单击我的项目,打开配置> Cmake>高级值> CMAKE_CXX_FLAGS。
我收到以下错误:
/home/francis/projects/testKDEV/build> make -j2
[100%] Building CXX object CMakeFiles/testkdev.dir/main.cpp.o
In file included from /usr/include/c++/4.9/memory:79:0,
from /usr/include/c++/4.9/tr1/memory:39,
from /usr/include/pqxx/util.hxx:31,
from /usr/include/pqxx/util:18,
from /usr/include/pqxx/except.hxx:27,
from /usr/include/pqxx/except:19,
from /usr/include/pqxx/result.hxx:33,
from /usr/include/pqxx/result:19,
from /usr/include/pqxx/binarystring.hxx:26,
from /usr/include/pqxx/binarystring:18,
from /usr/include/pqxx/pqxx:17,
from /home/francis/projects/testKDEV/main.cpp:2:
/usr/include/c++/4.9/functional:1034:20: error: expected template-name before ‘<’ token
: tuple_element<__i, _Tuple> { };
^
/usr/include/c++/4.9/functional:1034:20: error: expected ‘{’ before ‘<’ token
/usr/include/c++/4.9/functional:1034:20: error: expected unqualified-id before ‘<’ token
/usr/include/c++/4.9/functional:1054:17: error: ‘tuple_size’ was not declared in this scope
(__i < tuple_size<_Tuple>::value)>
^
/usr/include/c++/4.9/functional:1054:35: error: ‘::value’ has not been declared
(__i < tuple_size<_Tuple>::value)>
并不断出现错误...有人可以帮我了解我在做什么错吗?
我不了解Kdevelop,但我也遇到类似的问题。 我使用Eclipse。 有我的问答。 那是波兰语,所以找一个可以翻译的人。 我的英语不太好,但我会尽力翻译。
您需要libpqxx-4.0.1。 下载以下软件包:
下一个:
您可以选择“ / usr / local”以外的路径。 将安装libpqxx。
现在您应该在/ usr / local / include和libpqxx.a中有头文件,在/ usr / local / lib中有libpqxx.so。 如果一切正常,请在IDE中链接库。 我不知道如何在IDE中执行此操作,但这通常是相同的,但是属性位于不同的位置。 例如,在Eclipse CDT中:
现在尝试编译。 如果可以,请尝试运行程序。 如果您遇到问题,例如#15
error while loading shared libraries: libpqxx-4.0.so: cannot open shared object file: No such file or directory
在我的情况下,使用libpqxx和C ++ 11与PostgreSQL进行连接就是一切。 祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.