سؤال

I'm trying a very basic C++ program using Code::Blocks. I'm on Ubuntu 12.04 and installed pqxx from the software manager. Here's the code.

#include <pqxx/pqxx>
#include <iostream>

using namespace std;
int main()
{

    pqxx::connection MyConn ("dbname=dbESM user=postgres");


    cout << "Hello world!" << endl;

    return 0;
}

But I get the following error on hitting F9 to compile and run:

/usr/include/pqxx/connection.hxx|87|undefined reference to `pqxx::connectionpolicy::connectionpolicy(std::basic_string, std::allocator > const&)'

The above message is from the file connection.hxx and the line highlighted is this:

  explicit connect_direct(const PGSTD::string &opts) : connectionpolicy(opts) {}

The connection.hxx file is not mine - I think it's part of pqxx.

I'm pretty new to this platform so I'm avoiding the terminal to compile code. Any help would be greatly appreciated.

هل كانت مفيدة؟

المحلول

You need to add the reference to the libpqxx library to the project.

Inside Code::blocks, when the project is open, locate Project in the menus, then follow Build options, then open the tab called Linker settings, then hit Add, then enter pqxx.

If you were using the libpq C library instead, the procedure would be identical except the name would be pq.

نصائح أخرى

You need to link against the according library, just #including the header files isn't enough. If available, you could use pkg-config to determine the according libraries. Further, what IDE are you using? Without that, the "on hitting F9" reference is useless. Also, compiling this on the commandline might even be easier, since it is clearer what exactly is happening.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top