Thread: C++ Background Workers?

C++ Background Workers?

From
Quinlan Pfiffer
Date:
I'm trying to build a custom background worker for 9.3 in C++. I'm having trouble getting it running, mostly due to what I think is some weird name mangling. The code is pretty simple and works fine if I compile it as a C background worker, but the plan is to link this worker to some other C++ libraries.

I guess I should first ask if this is even possible to do, at a glance it seems like it but I've been at it for a while and it's not working out.

Here is the output for compilation of a simple CPP project:


Recompiling for -fPIC (as it says to) correctly builds the shared library, but then when I try to run Postgres with my .so file being loaded I get this:


The cpp, header and make files are all here if that would prove useful:


Any input would be greatly appreciated. 

QP

Re: C++ Background Workers?

From
Tom Lane
Date:
Quinlan Pfiffer <quinlan@aquameta.com> writes:
> I'm trying to build a custom background worker for 9.3 in C++.
> Recompiling for -fPIC (as it says to) correctly builds the shared library,
> but then when I try to run Postgres with my .so file being loaded I get
> this:
> https://gist.github.com/qpfiffer/e59c9260b687a23e2743

Is it really necessary to make us go visit some random website for a
two-line error log?

For the archives (since I bet the above link will be 404 soon), the
failure looked like this:

2014-07-03 12:08:42 PDT FATAL:  could not load library "/usr/lib/postgresql/9.3/lib/pg_webrtc.so":
/usr/lib/postgresql/9.3/lib/pg_webrtc.so:undefined symbol: _Z30BackgroundWorkerUnblockSignalsv 

It looks to me like you need extern "C" { ... } around the
Postgres header files you're importing, so that the C++
compiler won't think it should mangle function names
declared therein.

            regards, tom lane


Re: C++ Background Workers?

From
Quinlan Pfiffer
Date:
On Thu, Jul 3, 2014 at 2:00 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Quinlan Pfiffer <quinlan@aquameta.com> writes:
> I'm trying to build a custom background worker for 9.3 in C++.
> Recompiling for -fPIC (as it says to) correctly builds the shared library,
> but then when I try to run Postgres with my .so file being loaded I get
> this:
> https://gist.github.com/qpfiffer/e59c9260b687a23e2743

Is it really necessary to make us go visit some random website for a
two-line error log?

Sorry, wasn't sure on etiquette for that sort of thing. I guess two lines is harmless enough. 

For the archives (since I bet the above link will be 404 soon), the
failure looked like this:

2014-07-03 12:08:42 PDT FATAL:  could not load library "/usr/lib/postgresql/9.3/lib/pg_webrtc.so": /usr/lib/postgresql/9.3/lib/pg_webrtc.so: undefined symbol: _Z30BackgroundWorkerUnblockSignalsv

It looks to me like you need extern "C" { ... } around the
Postgres header files you're importing, so that the C++
compiler won't think it should mangle function names
declared therein.

That worked, thanks for your help.

QP