Bug #115758 mysql-concpp-config.cmake can't find lib correctly when use mingw
Submitted: 3 Aug 5:07 Modified: 5 Aug 10:15
Reporter: chuansheng lin Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:9.0.0 OS:Windows (Windows 11)
Assigned to: CPU Architecture:x86 (AMD)
Tags: mysql-connector-cpp

[3 Aug 5:07] chuansheng lin
Description:
I use the mysql-connector-cpp cloned down from the github repository. I build it by mingw(version 13.2.0).
When cmake goes to find_package (mysql-concpp REQUIRED),I got this
------------
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:37 (find_package)
[cmake] 
[cmake] 
[cmake] CMake Error at D:/Program File/cmake/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
[cmake]   Could NOT find MySQL Connector/C++ at F:/MyLib/mysql-connector-cpp/lib64.
[cmake]   (missing: MYSQL_CONCPP_FOUND) (found version "9.0.0")
------------

How to repeat:
clone from https://github.com/mysql/mysql-connector-cpp.git
build command cmake -S . -B ../build -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX="F:/MyLib/mysql-connector-cpp" -DCMAKE_BUILD_TYPE=Release -DOpenSSL_DIR="F:/MyLib/openssl/lib64/cmake/OpenSSL" -DWITH_PROTOBUF=ON -DWITH_ZLIB=ON -DWITH_LZ4=ON -DWITH_ZSTD=ON -DWITH_JDBC=ON

In CMakeLists.txt
add_library(my_openssl INTERFACE)
target_link_directories(my_openssl INTERFACE "${OpenSSL_ROOT_DIR}/lib64")
# target_link_libraries(my_openssl ssl crypto)
add_library(mysql::openssl ALIAS my_openssl)

find_package(mysql-concpp REQUIRED)

Suggested fix:
A simple way
In mysql-concpp-config.cmake, find function add_connector_target and then find this sentence
------------
find_library(lib_path
    NAMES ${base_name}
    PATHS ${MYSQL_CONCPP_RUNTIME_LIBRARY_DIR}/${vs_suffix}
    NO_DEFAULT_PATH
    NO_CACHE
  )
------------
modify "PATHS ${MYSQL_CONCPP_RUNTIME_LIBRARY_DIR}/${vs_suffix}" to "PATHS ${MYSQL_ CONCPP_RUNTIME_LIBRARY_DIR}"
[3 Aug 7:41] chuansheng lin
Another approach that should work is as follows: 
·First, modify the definition of vs_suffix
-------------------
unset(vs_suffix)
  if(WIN32)
	if(MSVC)
		set(vs_suffix vs14)
	else()
		set(vs_suffix "")
	endif()
  endif()
-------------------
·Next, around line 560, change the content
-------------------
  if(WIN32)
	if(MSVC)
    set(lib_path_debug
      "${MYSQL_CONCPP_RUNTIME_LIBRARY_DIR}/debug/${vs_suffix}/${base_name}.lib"
    )
	else()
	set(lib_path_debug
      "${MYSQL_CONCPP_RUNTIME_LIBRARY_DIR}/debug/lib${base_name}.dll.a"
    )
	endif()
  endif()
-------------------
[5 Aug 9:41] MySQL Verification Team
Hi Mr. lin,

Thank you for your bug report.

However, we do not support MingW development toolset.

We support only native Windows tools for our connectors.

Unsupported.
[5 Aug 10:15] chuansheng lin
Oh, All right, just ignore this report.