[Libpqxx-general] Fix for libpqxx-3.0.0 under Mac OSX 10.5.2 and Xcode 3.0
Matthew Fanto
mfanto at gmail.com
Thu Aug 7 15:38:59 UTC 2008
I posted a message to the list a couple weeks ago about libpqxx crashing on
creating the connection object under Mac OSX 10.5.2 and Xcode 3.0. I've
since discovered the cause of the problem, and how to fix it for Mac users.
First a bit of background, from what I understand.
libstdc++ has introduced a debug mode, GLIBCXX_DEBUG, that allows for debug
checks of many of the C++ containers and algorithms:
"The libstdc++ debug mode performs checking for many areas of the C++
standard, but the focus is on checking interactions among standard
iterators, containers, and algorithms..."
From:
http://www.opensource.apple.com/darwinsource/Current/gcc_os-1823/libstdc++-v3/docs/html/debug.html
One of the side effects of this is that container sizes and behavior
changes, and linking against code not built with this flag can cause
crashes:
"Note that this flag changes the sizes and behavior of standard class
templates such as std::vector, and therefore you can only link code compiled
with debug mode and code compiled without debug mode if no instantiation of
a container is passed between the two translation units."
From:
http://www.xs4all.nl/~carlo17/libcwd/reference-manual/group__enable__glibcxx__debug.html
Rather then turning this feature off for each project, libpqxx can be built
to correctly work with these flags enabled. I was able to reproduce the
crash on the test apps (provided by libpqxx), and then by adding
GLIBCXX_DEBUG=1 to the library build, the test apps worked correctly.
First showing the crash with the test application:
Newton:test mfanto$ g++ -I../include -L/usr/local/pgsql/lib
../src/.libs/libpqxx.a -lpq test001.cxx -o test001 -D_GLIBCXX_DEBUG=1
Newton:test mfanto$ ./test001
Segmentation fault
I then modified the library Makefile's CXXFLAGS to include
-D_GLIBCXX_DEBUG=1 -D_GLIBCXX_DEBUG_PEDANTIC=1
[sample output of build]
g++ -DHAVE_CONFIG_H -I../include -I../include -I/usr/local/pgsql/include -g
-O2 -Werror -D_GLIBCXX_DEBUG=1 -D_GLIBCXX_DEBUG_PEDANTIC=1 -MT connection.lo
-MD -MP -MF .deps/connection.Tpo -c connection.cxx -o connection.o
Now running the same test again:
Newton:test mfanto$ g++ -I../include -L/usr/local/pgsql/lib
../src/.libs/libpqxx.a -lpq test001.cxx -o test001 -D_GLIBCXX_DEBUG=1
Newton:test mfanto$ ./test001
Exception: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Would it be possible to get this check added in when building the Debug
version of the library under OSX?
Best,
Matthew Fanto
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://pgfoundry.org/pipermail/libpqxx-general/attachments/20080807/160e2334/attachment.html
More information about the Libpqxx-general
mailing list