Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: How to link C++ task with Oracle and Postgres clients
2 points by scrubs on April 2, 2021 | hide | past | favorite | 4 comments
I ran into an unexpected problem: I need a Linux task which handles Postgres (over libpq) Db queries and Oracle (over libclntst.so) Db queries. Creating a program to do one without the other is straightforward/routine.

However, a program that links in libpq and its dependent libraries plus Oracle's shared client library cores in OCIServerAttach.

Now if I try to make the same program by linking in only archive versions of libpq, libpq's dependent libs like ssh/ldap/crypto --and-- libclntst.a there's a zillion duplicated symbols mostly of the ssh/ldap/crypto variety. I'm guessing the shared library approach hides those conflicts and incorrectly resolves them at runtime.

I am versant with OCI, and libpq calls. All this code is doing is connecting resp. to a PG db and an Oracle Db ... 100% sure it's not the code itself but rather linking issues. Indeed, if I remove the PG PQconnect/PQfinish call and libpq from the linker line ... Oracle works as expected. And vice-versa.

We're migrating an extremely large Oracle Db to Postgres and would prefer to do it by use-case ... therefore our main task sometimes needs to hit PG and sometimes needs to hit Oracle.

Any ideas? I considered ODBC for Oracle ... but ultimately ODBC is just another library which still requires libclntst.a which will hit into the same issue. Is there a modular way to link Oracle to get Oracle APIs without ssl/ldap/crypto? Another author recommended using dlopen to hand-load the Oracle shared library with a special flag. I tried that ... but didn't get too far. I don't believe dlsym is a recursive loader anyway ... and we're talking serious numbers of function calls for Oracle.




Update: By specifying only .a libs I've eliminated all undefined symbols. The last linker issue: 'ERR_load_strings' is duplicated between Oracle libs and libpq's dependent libs. This symbol cannot be stripped (it's in a relocation) nor can the one of the libs it appears in be removed without leading to undefined symbols.


Take a look at SOCI. Is an open source lib under Boost Software License (one of the most non-restrictive licenses at all).

This lib is designed especially for C++ with the idea of generic programming and type safety in mind.

https://igarageband.org/


Thank you for the input but alas I don't think this would take one far. SOCI like ODBC has its advantages to be sure. But ultimately you still have to link in libpq, it's deps, and Oracle libs hence same challenge.


Update: I resolved this problem by fixing the link line.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: