I tried to to use ODB within my project. Therefore I used VS2015 to compile the windows sources for their odb and odb-pgsql library choosing the Release and x64 configuration. I linked the libraries from my standard postgres installation(prebuilt binaries 64bit).
My project is managed by cmake and QtCreator. Here is the compiler setup from the Kit I use.
I set up a very simple project that replicates the error. Here is the CMakeLists.txt
project(minimal_odb CXX)
INCLUDE_DIRECTORIES(
"C:/Users/micha/Downloads/libodb-2.4.0/libodb-2.4.0/"
"C:/Users/micha/Downloads/libodb-pgsql-2.4.0/libodb-pgsql-2.4.0/")
add_executable(exec main.cpp)
target_link_libraries(exec
"C:/Users/micha/Downloads/libodb-2.4.0/libodb-2.4.0/lib64/odb.lib"
"C:/Users/micha/Downloads/libodb-pgsql-2.4.0/libodb-pgsql-2.4.0/lib64/odb-pgsql.lib")
Running cmake will print the used compiler.
-- The CXX compiler identification is MSVC 19.0.23506.0
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
here the main.cpp
#include "odb/pgsql/database.hxx"
int main() {
const std::string pg = "postgres";
::odb::pgsql::database db(pg, pg, pg, pg, 0);
return 0;
}
Already during compiliation I get confusing warnings.
At runtime the DLLs are found from the modified path environemt
C:\Users\micha\Downloads\libodb-2.4.0\libodb-2.4.0\bin64;
C:\Users\micha\Downloads\libodb-pgsql-2.4.0\libodb-pgsql-2.4.0\bin64
However my program instantly terminates with a bad_alloc exception. I debugged the application and here is my call stack.
The error occurs just when the string is copied into a local user_
variable from ::odb::pgsql::database
.
If I go deeper into the copy assignment I can see the handed string from my main is not really setup and points to 0x0 reading random values from memory.
The application prints the following to my terminal.
Exception at 0x7ffd148d1f08, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) at f:\dd\vctools\crt\vcstartup\src\heap\throw_bad_alloc.cpp:33
Exception at 0x7ffd148d1f08, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) at f:\dd\vctools\crt\vcstartup\src\heap\throw_bad_alloc.cpp:33
Exception at 0x7ffd148d1f08, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) at c:\program files (x86)\microsoft visual studio 14.0\vc\include\xstring:2185
Exception at 0x7ffd148d1f08, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) in ntdll!RcConsolidateFrames
Exception at 0x7ffd148d1f08, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) in ntdll!RcConsolidateFrames
I do not wonder getting a bad_alloc
with this _Num
value but I wonder why my string is messed up. I tried some different compiler like the amd64
and compiled odb, odb-pgsql using UNICODE and Multi-Byte character-set but nothing helped. At least using the amd64
I did not get the first 5 warnings mentioned above.
Does it help to change
const std::string pg = "postgres";
tostd::string pg = "postgres";
?Otherwise it looks like a linking problem.(Will edit/delete answer if this does not help)