-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trouble loading dynamically as a shared library #695
Comments
You're linking in the wrong order. Link to your direct dependencies first, and indirect dependencies after. (I think the examples document it correctly as |
I had tried the order you suggested originally and switched because it didn't work. Just tried switching it back but it doesn't seem to make a difference. I still get the same error. |
Oh wait, could you demangle that link symbol? Because I suspect it's complaining about Is there any chance you're trying to convert a single |
Yup, found an online demangler and it's a symbol in |
So does this mean I'm coding things incorrectly? I've taken my code initially written for libpqxx 5.0 as a windows dll and converted it to libpqxx 7.7.5 as a linux shared library. I wouldn't be surprised at all if I didn't convert it correctly on the first try. |
Upgrading two major versions is a fairly significant change. 5.0.0: libpqxx/include/pqxx/strconv.hxx Lines 42 to 66 in 23376d4
7.7.5: libpqxx/include/pqxx/strconv.hxx Lines 147 to 201 in 78e4f95
Please check your source code once to see where you are using |
I agree with @tt4g: your best bet right now is to search your code for an individual |
That was definitely it. Looks like my attempt at converting pqxx::binarystring was incorrect. I had this
and converted it to this
Any suggestions on that? |
What's the field's SQL type? A single byte!? |
Reading it more closely, I think the confusion is elsewhere... the Instead, just initialise your variable I say "just" but I realise it's still a bit of a mouthful. If it happens too often you may want to create an alias for |
(In #697 I attempt to trick your compiler into generating slightly more helpful error messages when this kind of problem pops up.) |
Thanks for this. I was able to get things to compile and load but haven't gotten to debugging that specific piece of code yet. I do have some other questions with my conversion from 5.0 to 7.7.5 if that's ok to ask here. I used to be able to run unprepare on a string even if I hadn't run prepare initially. Now it throws the error "prepared statement "something" does not exist". Thanks for the help. |
The reason is that |
That's what I figured, it just used to work differently in version 5.0. It wouldn't throw an error if I tried to remove a non-existent prepared statement. Is there a way to test if the statement is prepared? Thanks |
You can check prepared statement by too simple SQL: SELECT name FROM pg_prepared_statements WHERE name = $1;
Example PREPARE foo (int, text, bool, numeric) AS
SELECT one FROM (VALUES($1)) AS __foo(one);
--- Returns 'foo'
SELECT name FROM pg_prepared_statements WHERE name = 'foo';
--- No return results.
SELECT name FROM pg_prepared_statements WHERE name = 'bar'; |
Is there any way to do the what's in your example programmatically? Without running the select statement to search for the given prepared statement? I tried a try/catch block just around the unprepare but the original try/catch block fails with the following message: Failure during '[PREPARE something]': ERROR: current transaction is aborted, commands ignored until end of transaction block |
The cause of the Statements are simply executed as usual by libpqxx features. std::string statement_name = // prepared statement name.
pqxx::connection c;
pqxx::work w{c};
auto row = w.exec_params1("SELECT COUNT(*) AS _count FROM pg_prepared_statements WHERE name = $1;", statement_name);
if (row[0] == 1) {
// unprepare `statement_name`
} |
To suppress the error, you can run the "unprepare" before your transaction (in a separate transaction, or in a "nontransaction"). That would allow you to catch the exception and continue as normal. If you can't move the unprepare outside of your transaction, you can get the same effect by wrapping it in a "subtransaction." |
I know it's been a while on this. Your subtransaction method worked for me to remove the errors on the lib side. What I didn't notice is I'm getting the following error on the database side now. ERROR: prepared statement "NameOfPreparedStatement" does not exist STATEMENT: DEALLOCATE "NameOfPreparedStatement" I believe this is because I may not have the prepared statement created and I'm blindly unpreparing it. Is there a way to suppress the error on the database side? Thanks |
You should always create prepared statements in your application before executing them. |
I can't think of a way to suppress it completely, unfortunately... It'd be great to have a I'll be at PGDay FOSDEM tomorrow. I'll see if anyone can help. |
@chunter2 I had a search around and found this thread... Looks like the outcome of this conversation is always the same: "your application should know which statements it has prepared." I don't necessarily agree with that — sometimes you just don't want that extra leak in your abstractions. But I don't have the time to push the issue and produce a patch. |
Thanks for looking into this. It's been helpful. Just to follow up, any idea what's changed from version 5.0 of libpqxx to version 7.7.5? Would the patch you're talking about having to produce basically restore how it used to work? I think my real fix would be to use prepared statements properly instead of just trying to carry over code that used version 5.0. Thanks |
Just looking for some help with using your library. I'm trying to create a "plugin" to wrap libpqxx using a shared library and dynamically opening it with dlopen. This is all on 64-bit linux. I've done this with other databases using OCCI for Oracle and unixODBC as a generic one and they work with my application. I'm compiling the libpqxx one using the following command.
g++ -shared -fpic -Wall -std=c++17 -o pqxx77.so *.cpp -lpq -lpqxx
I needed to add the -std=c++17 to get it to compile. When I try to load with dlopen I get the following error.
undefined symbol: _ZN4pqxx13string_traitsISt4byteE11from_stringESt17basic_string_viewIcSt11char_traitsIcEE
I've tried to compile my application that calls dlopen with the -std=c++17 but still get the same error.
Any hints would be appreciated.
Thanks
The text was updated successfully, but these errors were encountered: