나는 libpqxx 코드 예제를 컴파일하려고 :libpqxx 코드 예제를 컴파일하는 동안 오류가 발생 했습니까?
#include <iostream>
#include <pqxx/pqxx>
int main(int, char *argv[])
{
pqxx::connection c("dbname=company user=accounting");
pqxx::work txn(c);
pqxx::result r = txn.exec(
"SELECT id "
"FROM Employee "
"WHERE name =" + txn.quote(argv[1]));
if (r.size() != 1)
{
std::cerr
<< "Expected 1 employee with name " << argv[1] << ", "
<< "but found " << r.size() << std::endl;
return 1;
}
int employee_id = r[0][0].as<int>();
std::cout << "Updating employee #" << employee_id << std::endl;
txn.exec(
"UPDATE EMPLOYEE "
"SET salary = salary + 1 "
"WHERE id = " + txn.quote(employee_id));
txn.commit();
}
사용하여 명령을
test2.cpp:(.text+0x162): undefined reference to `pqxx::transaction_base::exec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
test2.cpp:(.text+0x32e): undefined reference to `pqxx::transaction_base::exec(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cchvWstf.o: In function `pqxx::string_traits<int>::null()':
test2.cpp:(.text._ZN4pqxx13string_traitsIiE4nullEv[_ZN4pqxx13string_traitsIiE4nullEv]+0x47): undefined reference to `pqxx::internal::throw_null_conversion(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cchvWstf.o: In function `pqxx::connect_direct::connect_direct(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
test2.cpp:(.text._ZN4pqxx14connect_directC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN4pqxx14connect_directC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x1f): undefined reference to `pqxx::connectionpolicy::connectionpolicy(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cchvWstf.o: In function `pqxx::transaction<(pqxx::isolation_level)0, (pqxx::readwrite_policy)1>::transaction(pqxx::connection_base&)':
test2.cpp:(.text._ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEC1ERNS_15connection_baseE[_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEC1ERNS_15connection_baseE]+0xba): undefined reference to `pqxx::dbtransaction::fullname(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
test2.cpp:(.text._ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEC1ERNS_15connection_baseE[_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEC1ERNS_15connection_baseE]+0x190): undefined reference to `pqxx::basic_transaction::basic_transaction(pqxx::connection_base&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, pqxx::readwrite_policy)'
내가 그것을 어떻게 컴파일 할 수
c++ add_employee.cxx -lpqxx -lpq
불행하게도 나는 오류를 가지고있다? 플래그 순서를 변경하려고했지만 도움이되지 않습니다. 고맙습니다.