Skip to content
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

MacOS compiler error on wcsnrtombs (UNICODE) #251

Open
pedro-vicente opened this issue Nov 12, 2020 · 2 comments
Open

MacOS compiler error on wcsnrtombs (UNICODE) #251

pedro-vicente opened this issue Nov 12, 2020 · 2 comments

Comments

@pedro-vicente
Copy link

Environment

  • nanodbc version: master branch
  • DBMS name/version: unixODBC
  • ODBC connection string:
  • OS and Compiler:
  • CMake settings:

Actual behavior

Expected behavior

Minimal Working Example

I get a compiler error building on MacOS

cmake .. -DNANODBC_ENABLE_UNICODE=ON

-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- nanodbc version: 2.13.0
-- nanodbc compile: C++14
-- Performing Test CXX_SUPPORTS_STDLIB
-- Performing Test CXX_SUPPORTS_STDLIB - Success
-- nanodbc build: Disable linking libc++ - OFF
-- nanodbc feature: ODBC Version Override - OFF
-- nanodbc feature: Disable async features - OFF
-- nanodbc feature: Enable Unicode - ON
-- nanodbc feature: Enable Boost - OFF
-- nanodbc feature: Enable SQL_NO_DATA bug workaround - OFF
-- nanodbc build: ODBC on Unix - unixODBC
-- ODBC compile flags: -I/usr/local/Cellar/unixodbc/2.3.9/include
-- ODBC link flags: -L/usr/local/Cellar/unixodbc/2.3.9/lib -lodbc
-- Use rpaths on Mac OS X - ON
-- nanodbc build: Enable nanodbc target - STATIC
-- nanodbc build: Disable install target - OFF
-- nanodbc build: Disable tests target - OFF
-- nanodbc build: Disable examples target - OFF
-- Configuring done
-- Generating done
-- Build files have been written to: /Volumes/Home/pvn/dev/nanodbc/build

errors

make
Scanning dependencies of target nanodbc
[  3%] Building CXX object CMakeFiles/nanodbc.dir/nanodbc/nanodbc.cpp.o
[  6%] Linking CXX static library libnanodbc.a
[  6%] Built target nanodbc
Scanning dependencies of target vertica_tests
[ 10%] Building CXX object test/CMakeFiles/vertica_tests.dir/main.cpp.o
In file included from /Volumes/Home/pvn/dev/nanodbc/test/main.cpp:9:
/Volumes/Home/pvn/dev/nanodbc/test/base_test_fixture.h:62:5: error: no matching function for call to 'wcsnrtombs'
    wcsnrtombs(&out[0], &source, characters.size(), out.length(), nullptr);
    ^~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/wchar.h:203:9: note: candidate function not viable:
      no known conversion from 'std::__1::basic_string<char16_t, std::__1::char_traits<char16_t>,
      std::__1::allocator<char16_t> >::value_type *' (aka 'char16_t *') to 'char *' for 1st argument
size_t  wcsnrtombs(char * __restrict, const wchar_t ** __restrict, size_t,
        ^
In file included from /Volumes/Home/pvn/dev/nanodbc/test/main.cpp:9:
/Volumes/Home/pvn/dev/nanodbc/test/base_test_fixture.h:85:19: error: no matching function for call to 'mbsnrtowcs'
    size_t size = mbsnrtowcs(nullptr, in.data(), in.length(), 0, nullptr);
                  ^~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/wchar.h:195:9: note: candidate function not viable:
      no known conversion from 'const std::__1::basic_string<char16_t, std::__1::char_traits<char16_t>,
      std::__1::allocator<char16_t> >::value_type *' (aka 'const char16_t *') to 'const char **' for 2nd argument
size_t  mbsnrtowcs(wchar_t * __restrict, const char ** __restrict, size_t,
        ^
In file included from /Volumes/Home/pvn/dev/nanodbc/test/main.cpp:9:
/Volumes/Home/pvn/dev/nanodbc/test/base_test_fixture.h:89:17: error: cannot initialize a variable of type 'const char *'
      with an rvalue of type 'const std::__1::basic_string<char16_t, std::__1::char_traits<char16_t>,
      std::__1::allocator<char16_t> >::value_type *' (aka 'const char16_t *')
    const char* source = in.data();
                ^        ~~~~~~~~~


@pedro-vicente
Copy link
Author

pedro-vicente commented Nov 12, 2020

this is simply a nasty cast or conversion from std::string to char *
instead of trying to fix that, it seems that the generic fall trough case of

out = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>().to_bytes(in);

can be used for the CLang compiler
so, a solution could be to let it fall to this case by changing from

#elif defined(__GNUC__) && __GNUC__ < 5 

to

#elif defined(__GNUC__) && __GNUC__ < 5 && !defined(__llvm__)

no errors in this case
except that the the odbc library was not found (unrelated to this)

ld: library not found for -lodbc

source

https://stackoverflow.com/questions/38499462/how-to-tell-clang-to-stop-pretending-to-be-other-compilers

@pedro-vicente
Copy link
Author

to detect unixODBC I use this on my Cmake

if(UNIX)
  find_path(ODBC_INCLUDE sql.h ${find_opt})
  if(NOT ODBC_INCLUDE)
    message(FATAL_ERROR "sql.h header file not found")
  else()
    message("-- Found sql.h header file at: " ${ODBC_INCLUDE})
  endif()
  include_directories(${ODBC_INCLUDE})
  find_library(ODBC_LIBRARY NAMES odbc PATHS "/usr/local/lib")
  if(NOT ODBC_LIBRARY)
    message(FATAL_ERROR "ODBC library not found$")
  else()
    message("-- Found ODBC library at: " ${ODBC_LIBRARY})
  endif()
  set(lib_dep ${lib_dep} ${ODBC_LIBRARY})
endif()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant