Hello,
we experienced an issue with the latest SOCI version from git: On
Windows (Visual C++ 2010), we link against SOCI DLLs. Since SOCI itself
links the C++ Run-Time Library dynamically (/MDd and /MD for debug and
release, respectively), it is crucial to use the same C++ Run-Time
linking options in our application. Since we want to do both debug and
release builds of our application, we need both debug and release
versions of the SOCI libraries -- using debug SOCI libs with a release
build application (or vice versa) will crash.
Alternatively, SOCI could statically link the C++ Run-Time.
I attached a patch that introduces a "_debug" postfix for SOCI debug
libraries (on Windows only, I don't know if the problem occurs on other
platforms as well).
Please let me know what you think of the patch, or if you see other
solutions to the problem.
Cheers,
Guido
PS: The patch is not as big as it might seem, most of it are whitespace
changes in the backend CMakeLists.txt, resulting from de-tabbifying the
file.
--
Guido Lorenz
Research & Development
[rmh] new media GmbH
Gilbachstr. 29a
50672 Köln
>From afec6d82ea11fe606bf267f23b1839b590546803 Mon Sep 17 00:00:00 2001
From: Guido Lorenz <[email protected]>
Date: Wed, 23 Mar 2011 11:27:32 +0100
Subject: [PATCH] Add "_debug" postfix to libraries on Windows
When built on Windows, the CMake DEBUG_POSTFIX property will add a "_debug"
postfix to the core and backend libraries, so they can be distinguished.
The naming convertion is adopted by the dynamic backend loader.
---
src/cmake/SociBackend.cmake | 92 +++++++++++++++++++++++-------------------
src/core/CMakeLists.txt | 2 +
src/core/backend-loader.cpp | 4 ++
3 files changed, 56 insertions(+), 42 deletions(-)
diff --git a/src/cmake/SociBackend.cmake b/src/cmake/SociBackend.cmake
index d34d152..fbdf46e 100644
--- a/src/cmake/SociBackend.cmake
+++ b/src/cmake/SociBackend.cmake
@@ -95,22 +95,22 @@ macro(soci_backend NAME)
# Backend-specific include directories
list(APPEND THIS_BACKEND_DEPENDS_INCLUDE_DIRS ${SOCI_SOURCE_DIR}/core)
set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES
- "${THIS_BACKEND_DEPENDS_INCLUDE_DIRS}")
+ "${THIS_BACKEND_DEPENDS_INCLUDE_DIRS}")
# Backend-specific preprocessor definitions
add_definitions(${THIS_BACKEND_DEPENDS_DEFS})
# Backend installable headers and sources
if (NOT THIS_BACKEND_HEADERS)
- file(GLOB THIS_BACKEND_HEADERS *.h)
+ file(GLOB THIS_BACKEND_HEADERS *.h)
endif()
file(GLOB THIS_BACKEND_SOURCES *.cpp)
set(THIS_BACKEND_HEADERS_VAR SOCI_${NAMEU}_HEADERS)
set(${THIS_BACKEND_HEADERS_VAR} ${THIS_BACKEND_HEADERS})
- # Group source files for IDE source explorers (e.g. Visual Studio)
+ # Group source files for IDE source explorers (e.g. Visual Studio)
source_group("Header Files" FILES ${THIS_BACKEND_HEADERS})
- source_group("Source Files" FILES ${THIS_BACKEND_SOURCES})
+ source_group("Source Files" FILES ${THIS_BACKEND_SOURCES})
source_group("CMake Files" FILES CMakeLists.txt)
# Backend target
@@ -127,21 +127,22 @@ macro(soci_backend NAME)
# Shared library target
add_library(${THIS_BACKEND_TARGET}
- SHARED
- ${THIS_BACKEND_SOURCES}
- ${THIS_BACKEND_HEADERS})
+ SHARED
+ ${THIS_BACKEND_SOURCES}
+ ${THIS_BACKEND_HEADERS})
target_link_libraries(${THIS_BACKEND_TARGET}
- ${SOCI_CORE_TARGET}
- ${THIS_BACKEND_DEPENDS_LIBRARIES})
+ ${SOCI_CORE_TARGET}
+ ${THIS_BACKEND_DEPENDS_LIBRARIES})
if(WIN32)
- set_target_properties(${THIS_BACKEND_TARGET}
+ set_target_properties(${THIS_BACKEND_TARGET}
PROPERTIES
OUTPUT_NAME ${THIS_BACKEND_TARGET_OUTPUT_NAME}
+ DEBUG_POSTFIX "_debug"
DEFINE_SYMBOL SOCI_DLL)
else()
- set_target_properties(${THIS_BACKEND_TARGET}
+ set_target_properties(${THIS_BACKEND_TARGET}
PROPERTIES
SOVERSION ${${PROJECT_NAME}_SOVERSION})
endif()
@@ -153,29 +154,36 @@ macro(soci_backend NAME)
# Static library target
add_library(${THIS_BACKEND_TARGET}-static
- STATIC
- ${THIS_BACKEND_SOURCES}
- ${THIS_BACKEND_HEADERS})
+ STATIC
+ ${THIS_BACKEND_SOURCES}
+ ${THIS_BACKEND_HEADERS})
set_target_properties(${THIS_BACKEND_TARGET}-static
- PROPERTIES
- OUTPUT_NAME ${THIS_BACKEND_TARGET_OUTPUT_NAME}
- PREFIX "lib"
- CLEAN_DIRECT_OUTPUT 1)
+ PROPERTIES
+ OUTPUT_NAME ${THIS_BACKEND_TARGET_OUTPUT_NAME}
+ PREFIX "lib"
+ DEBUG_POSTFIX "_debug"
+ CLEAN_DIRECT_OUTPUT 1)
+ if(WIN32)
+ set_target_properties(${THIS_BACKEND_TARGET}-static
+ PROPERTIES
+ DEBUG_POSTFIX "_debug")
+ endif()
+
# Backend installation
install(FILES ${THIS_BACKEND_HEADERS}
- DESTINATION
- ${INCLUDEDIR}/${PROJECTNAMEL}/${NAMEL})
+ DESTINATION
+ ${INCLUDEDIR}/${PROJECTNAMEL}/${NAMEL})
install(TARGETS ${THIS_BACKEND_TARGET} ${THIS_BACKEND_TARGET}-static
- RUNTIME DESTINATION ${BINDIR}
- LIBRARY DESTINATION ${LIBDIR}
- ARCHIVE DESTINATION ${LIBDIR})
+ RUNTIME DESTINATION ${BINDIR}
+ LIBRARY DESTINATION ${LIBDIR}
+ ARCHIVE DESTINATION ${LIBDIR})
- else()
+ else()
colormsg(HIRED "${NAME}" RED "backend disabled, since")
- endif()
+ endif()
endif(NOT_FOUND_COUNT GREATER 0)
@@ -228,7 +236,7 @@ endfunction(soci_backend_test_create_vcxproj_user)
#
# soci_backend_test(BACKEND mybackend SOURCE mytest1.cpp
# NAME mytest1
-# CONNSTR "my test connection"
+# CONNSTR "my test connection"
# DEPENDS library1 library2)
#
macro(soci_backend_test)
@@ -245,10 +253,10 @@ macro(soci_backend_test)
# Test name
if(THIS_TEST_NAME)
- string(TOUPPER "${THIS_TEST_NAME}" NAMEU)
- set(TEST_FULL_NAME SOCI_${BACKENDU}_TEST_${NAMEU})
- else()
- set(TEST_FULL_NAME SOCI_${BACKENDU}_TEST)
+ string(TOUPPER "${THIS_TEST_NAME}" NAMEU)
+ set(TEST_FULL_NAME SOCI_${BACKENDU}_TEST_${NAMEU})
+ else()
+ set(TEST_FULL_NAME SOCI_${BACKENDU}_TEST)
endif()
set(TEST_CONNSTR_VAR ${TEST_FULL_NAME}_CONNSTR)
@@ -265,18 +273,18 @@ macro(soci_backend_test)
# TODO: Find more generic way of adding Boost to core and backend tests
only.
# Ideally, from within Boost.cmake.
- set(SOCI_TEST_DEPENDENCIES)
+ set(SOCI_TEST_DEPENDENCIES)
if(Boost_FOUND)
- include_directories(${Boost_INCLUDE_DIRS})
- if(Boost_DATE_TIME_FOUND)
- set(SOCI_TEST_DEPENDENCIES ${Boost_DATE_TIME_LIBRARY})
- add_definitions(-DHAVE_BOOST_DATE_TIME=1)
- endif()
- endif()
+ include_directories(${Boost_INCLUDE_DIRS})
+ if(Boost_DATE_TIME_FOUND)
+ set(SOCI_TEST_DEPENDENCIES ${Boost_DATE_TIME_LIBRARY})
+ add_definitions(-DHAVE_BOOST_DATE_TIME=1)
+ endif()
+ endif()
string(TOLOWER "${TEST_FULL_NAME}" TEST_TARGET)
- set(TEST_HEADERS ${PROJECT_SOURCE_DIR}/core/test/common-tests.h)
+ set(TEST_HEADERS ${PROJECT_SOURCE_DIR}/core/test/common-tests.h)
add_executable(${TEST_TARGET} ${TEST_HEADERS} ${THIS_TEST_SOURCE})
add_executable(${TEST_TARGET}_static ${TEST_HEADERS} ${THIS_TEST_SOURCE})
@@ -285,14 +293,14 @@ macro(soci_backend_test)
${SOCI_CORE_TARGET}
${SOCI_${BACKENDU}_TARGET}
${${BACKENDU}_LIBRARIES}
- ${SOCI_TEST_DEPENDENCIES})
+ ${SOCI_TEST_DEPENDENCIES})
target_link_libraries(${TEST_TARGET}_static
${SOCI_CORE_TARGET}-static
${SOCI_${BACKENDU}_TARGET}-static
${${BACKENDU}_LIBRARIES}
${SOCI_CORE_STATIC_DEPENDENCIES}
- ${SOCI_TEST_DEPENDENCIES})
+ ${SOCI_TEST_DEPENDENCIES})
add_test(${TEST_TARGET}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TEST_TARGET}
@@ -306,8 +314,8 @@ macro(soci_backend_test)
soci_backend_test_create_vcxproj_user(${TEST_TARGET}
"\"${${TEST_CONNSTR_VAR}}\"")
soci_backend_test_create_vcxproj_user(${TEST_TARGET}_static
"\"${${TEST_CONNSTR_VAR}}\"")
- # Ask make check to try to build tests first before executing them
- add_dependencies(check ${TEST_TARGET} ${TEST_TARGET}_static)
+ # Ask make check to try to build tests first before executing them
+ add_dependencies(check ${TEST_TARGET} ${TEST_TARGET}_static)
# Group source files for IDE source explorers (e.g. Visual Studio)
source_group("Header Files" FILES ${TEST_HEADERS})
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index f268ec1..edeccd7 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -83,6 +83,7 @@ if(WIN32)
PROPERTIES
DEFINE_SYMBOL SOCI_DLL
OUTPUT_NAME "${SOCI_CORE_TARGET_OUTPUT_NAME}"
+ DEBUG_POSTFIX "_debug"
VERSION ${SOCI_VERSION}
CLEAN_DIRECT_OUTPUT 1)
else()
@@ -104,6 +105,7 @@ set_target_properties(${SOCI_CORE_TARGET}-static
PROPERTIES
OUTPUT_NAME ${SOCI_CORE_TARGET_OUTPUT_NAME}
PREFIX "lib"
+ DEBUG_POSTFIX "_debug"
CLEAN_DIRECT_OUTPUT 1)
#
diff --git a/src/core/backend-loader.cpp b/src/core/backend-loader.cpp
index 286bf8c..cc131d9 100644
--- a/src/core/backend-loader.cpp
+++ b/src/core/backend-loader.cpp
@@ -41,7 +41,11 @@ typedef HMODULE soci_handler_t;
#endif
#define DLCLOSE(x) FreeLibrary(x)
#define DLSYM(x, y) GetProcAddress(x, y)
+#ifdef _DEBUG
+#define LIBNAME(x) (SOCI_LIB_PREFIX + x + "_" SOCI_ABI_VERSION "_debug"
SOCI_LIB_SUFFIX)
+#else
#define LIBNAME(x) (SOCI_LIB_PREFIX + x + "_" SOCI_ABI_VERSION SOCI_LIB_SUFFIX)
+#endif
#else
--
1.7.3.1.msysgit.0
------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users