Tectu / malloy

A cross-platform C++20 library providing embeddable server & client components for HTTP and WebSocket.
BSD 3-Clause "New" or "Revised" License
68 stars 8 forks source link

Allow building as shared library #55

Closed 0x00002a closed 2 years ago

0x00002a commented 3 years ago

df54240639a3aa944a6b1c28e8fb4af2c63dd3bd has split the library up into components, which is nice. However, currently it only allows building static libs, since BUILD_SHARED_LIBS only affects add_library calls which don't explicitly specify shared or static. I was wondering if there was a specific reason for this? I would quite like to build shared libs to reduce my link time for all the examples (not to mention binary sizes, the debug build for all of them is ~4gb for me combined).

I suggest adding an option() to malloy like MALLOY_BUILD_SHARED which toggles BUILD_SHARED_LIBS internally. If there is a specific reason they need to be static I am curious as to why :p.

Tectu commented 3 years ago

Yeah, that will follow soon. Just couldn't it get done yesterday :p

Tectu commented 3 years ago

I deem this important enough to pull it into v0.1.

0x00002a commented 3 years ago

Shall I do this? Pretty sure its just a matter of removing STATIC from the add_library calls and adding an option, unless I'm missing something?

Tectu commented 3 years ago

You can give it a go.

Requirements from my side: Have a properly prefixed MALLOY_ option. Relying on CMake's BUILD_SHARED_LIBS can lead to nasty problems down the road if working on larger projects with complex nested FetchContent() dependencies.

The main reason I didn't already do this is because I wasn't sure whether we should go with a boolean option() like MALLOY_BUILD_SHARED or a proper set() setting that accepts static or shared as a value. As of today I think a simple option(MALLOY_BUILD_SHARED ...) should be sufficient.

Tectu commented 3 years ago

[...] unless I'm missing something?

One thing: If I remember last time I checked MSVC required the proper import/export declarations for building/linking shared libs. Is this (still) the case?

I have a CMake template ready which automatically generates the export header and installs it with the target. If we need that functionality, we might be faster if I handle this.

0x00002a commented 3 years ago

One thing: If I remember last time I checked MSVC required the proper import/export declarations for building/linking shared libs. Is this (still) the case?

I'm... not sure. To tell the truth I've mostly avoided (creating) dlls on windows, since the lack of rpath makes them really quite painful. I remember CMake has a switch to automatically export all symbols though doesn't it?

Tectu commented 3 years ago

I'd say make a PR just with the new MALLOY_BUILD_SHARED option then and we'll see if we need export declarations for MSVC. If so, I'll handle that.

Alternatively I can offer to add this new option within the next hour or so.

0x00002a commented 3 years ago

I'm working on it now. I'm going to have to put all the binaries in one directory and put the dlls in there too so they'll actually run on windows. I'll do it on a per-target basis (with malloy_target_common_setup) so it doesn't pollute consumers, is that ok?

Tectu commented 3 years ago

Is this regarding the destination path for the built binaries? There are two ways: Setting the output directory of the binary in the target's properties or manually copying it using something like this:

# Copy SQLite3 DLL to binary dir after build
add_custom_command(
    TARGET ${TARGET}
    POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy
    ${CMAKE_CURRENT_LIST_DIR}/../3rdparty/sqlapi/bin/sqlite3.dll
    ${CMAKE_CURRENT_BINARY_DIR}
    COMMENT "Copying 'sqlite3' library to binary directory."
)
Tectu commented 3 years ago

Interesting, I just pulled the latest main branch (after merging #67), made a clean build (completely removed the build directory) and tried to build malloy-example-server-basic with: -DCMAKE_BUILD_TYPE=Debug -DMALLOY_BUILD_SHARED=ON -DMALLOY_FEATURE_TLS=OFF on Windows 10 using MSYS2 with MinGW.

cmake output:

-- The CXX compiler identification is GNU 10.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: C:/bin/boost_1_76_0 (found suitable version "1.76.0", minimum required is "1.74.0")  
-- Build spdlog: 1.8.3
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Build type: Debug

---------------------
Malloy configuration:
  Build:
    Examples     : ON
    Tests        : ON
    Library Type : SHARED
  Features:
    Client       : ON
    Server       : ON
    HTML         : ON
    TLS          : OFF
---------------------

-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/joel/Documents/projects/malloy/cmake-build-debug-mingw-w64-gcc

[Finished]

make output:

Scanning dependencies of target spdlog
[  4%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/spdlog.cpp.obj
[ 13%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/color_sinks.cpp.obj
[ 13%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/stdout_sinks.cpp.obj
[ 18%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/cfg.cpp.obj
[ 22%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/async.cpp.obj
[ 27%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/fmt.cpp.obj
[ 31%] Building CXX object _deps/spdlog-build/CMakeFiles/spdlog.dir/src/file_sinks.cpp.obj
[ 36%] Linking CXX static library libspdlogd.a
[ 36%] Built target spdlog
Scanning dependencies of target malloy-core
[ 40%] Building CXX object lib/malloy/core/CMakeFiles/malloy-core.dir/html/form.cpp.obj
[ 45%] Building CXX object lib/malloy/core/CMakeFiles/malloy-core.dir/http/session/manager.cpp.obj
[ 50%] Building CXX object lib/malloy/core/CMakeFiles/malloy-core.dir/http/cookie.cpp.obj
[ 54%] Building CXX object lib/malloy/core/CMakeFiles/malloy-core.dir/http/generator.cpp.obj
[ 59%] Building CXX object lib/malloy/core/CMakeFiles/malloy-core.dir/controller.cpp.obj
[ 63%] Linking CXX shared library ..\..\..\bin\libmalloy-core.dll
[ 63%] Built target malloy-core
Scanning dependencies of target malloy-server
[ 68%] Building CXX object lib/malloy/server/CMakeFiles/malloy-server.dir/http/connection_detector.cpp.obj
[ 72%] Building CXX object lib/malloy/server/CMakeFiles/malloy-server.dir/http/preflight_config.cpp.obj
[ 77%] Building CXX object lib/malloy/server/CMakeFiles/malloy-server.dir/routing/router.cpp.obj
[ 81%] Building CXX object lib/malloy/server/CMakeFiles/malloy-server.dir/controller.cpp.obj
[ 86%] Building CXX object lib/malloy/server/CMakeFiles/malloy-server.dir/listener.cpp.obj
[ 90%] Linking CXX shared library ..\..\..\bin\libmalloy-server.dll
[ 90%] Built target malloy-server
Scanning dependencies of target malloy-example-server-basic
[ 95%] Building CXX object examples/server/basic/CMakeFiles/malloy-example-server-basic.dir/main.cpp.obj
[100%] Linking CXX executable ..\..\..\bin\malloy-example-server-basic.exe
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../../../_deps/spdlog-build/libspdlogd.a(spdlog.cpp.obj): in function `spdlog::default_logger_raw()':
C:/Users/joel/Documents/projects/malloy/cmake-build-debug-mingw-w64-gcc/_deps/spdlog-src/include/spdlog/spdlog-inl.h:116: multiple definition of `spdlog::default_logger_raw()'; ../../../lib/malloy/server/libmalloy-server.dll.a(d002316.o):(.text+0x0): first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../../../_deps/spdlog-build/libspdlogd.a(spdlog.cpp.obj): in function `spdlog::details::backtracer::enabled() const':
C:/Users/joel/Documents/projects/malloy/cmake-build-debug-mingw-w64-gcc/_deps/spdlog-src/include/spdlog/details/backtracer-inl.h:47: multiple definition of `spdlog::details::backtracer::enabled() const'; ../../../lib/malloy/server/libmalloy-server.dll.a(d003412.o):(.text+0x0): first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../../../_deps/spdlog-build/libspdlogd.a(spdlog.cpp.obj): in function `spdlog::details::log_msg::log_msg(spdlog::source_loc, fmt::v7::basic_string_view<char>, spdlog::level::level_enum, fmt::v7::basic_string_view<char>)':
C:/Users/joel/Documents/projects/malloy/cmake-build-debug-mingw-w64-gcc/_deps/spdlog-src/include/spdlog/details/log_msg-inl.h:27: multiple definition of `spdlog::details::log_msg::log_msg(spdlog::source_loc, fmt::v7::basic_string_view<char>, spdlog::level::level_enum, fmt::v7::basic_string_view<char>)'; ../../../lib/malloy/server/libmalloy-server.dll.a(d002976.o):(.text+0x0): first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../../../_deps/spdlog-build/libspdlogd.a(spdlog.cpp.obj): in function `spdlog::logger::set_level(spdlog::level::level_enum)':
C:/Users/joel/Documents/projects/malloy/cmake-build-debug-mingw-w64-gcc/_deps/spdlog-src/include/spdlog/logger-inl.h:68: multiple definition of `spdlog::logger::set_level(spdlog::level::level_enum)'; ../../../lib/malloy/server/libmalloy-server.dll.a(d002429.o):(.text+0x0): first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../../../_deps/spdlog-build/libspdlogd.a(spdlog.cpp.obj): in function `spdlog::logger::log_it_(spdlog::details::log_msg const&, bool, bool)':
C:/Users/joel/Documents/projects/malloy/cmake-build-debug-mingw-w64-gcc/_deps/spdlog-src/include/spdlog/logger-inl.h:167: multiple definition of `spdlog::logger::log_it_(spdlog::details::log_msg const&, bool, bool)'; ../../../lib/malloy/server/libmalloy-server.dll.a(d002426.o):(.text+0x0): first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../../../_deps/spdlog-build/libspdlogd.a(spdlog.cpp.obj): in function `spdlog::logger::err_handler_(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
C:/Users/joel/Documents/projects/malloy/cmake-build-debug-mingw-w64-gcc/_deps/spdlog-src/include/spdlog/logger-inl.h:228: multiple definition of `spdlog::logger::err_handler_(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'; ../../../lib/malloy/server/libmalloy-server.dll.a(d002400.o):(.text+0x0): first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../../../_deps/spdlog-build/libspdlogd.a(spdlog.cpp.obj): in function `spdlog::sinks::sink::set_level(spdlog::level::level_enum)':
C:/Users/joel/Documents/projects/malloy/cmake-build-debug-mingw-w64-gcc/_deps/spdlog-src/include/spdlog/sinks/sink-inl.h:18: multiple definition of `spdlog::sinks::sink::set_level(spdlog::level::level_enum)'; ../../../lib/malloy/server/libmalloy-server.dll.a(d002376.o):(.text+0x0): first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../../../_deps/spdlog-build/libspdlogd.a(fmt.cpp.obj): in function `void fmt::v7::detail::vformat_to<char>(fmt::v7::detail::buffer<char>&, fmt::v7::basic_string_view<char>, fmt::v7::basic_format_args<fmt::v7::basic_format_context<fmt::v7::detail::buffer_appender<fmt::v7::type_identity<char>::type>, fmt::v7::type_identity<char>::type> >, fmt::v7::detail::locale_ref)':
C:/Users/joel/Documents/projects/malloy/cmake-build-debug-mingw-w64-gcc/_deps/spdlog-src/include/spdlog/fmt/bundled/format.h:3761: multiple definition of `void fmt::v7::detail::vformat_to<char>(fmt::v7::detail::buffer<char>&, fmt::v7::basic_string_view<char>, fmt::v7::basic_format_args<fmt::v7::basic_format_context<fmt::v7::detail::buffer_appender<fmt::v7::type_identity<char>::type>, fmt::v7::type_identity<char>::type> >, fmt::v7::detail::locale_ref)'; ../../../lib/malloy/server/libmalloy-server.dll.a(d000552.o):(.text+0x0): first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::winsock_init_base::startup(boost::asio::detail::winsock_init_base::data&, unsigned char, unsigned char)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to `__imp_WSAStartup'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::winsock_init_base::cleanup(boost::asio::detail::winsock_init_base::data&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/winsock_init.ipp:56: undefined reference to `__imp_WSACleanup'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `int boost::asio::detail::socket_ops::call_setsockopt<int>(int boost::asio::detail::socket_ops::msghdr::*, unsigned long long, int, int, void const*, unsigned long long)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:1855: undefined reference to `__imp_setsockopt'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::shutdown(unsigned long long, int, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:460: undefined reference to `__imp_shutdown'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::set_user_non_blocking(unsigned long long, unsigned char&, bool, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:369: undefined reference to `__imp_ioctlsocket'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:369: undefined reference to `__imp_ioctlsocket'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::close(unsigned long long, unsigned char&, bool, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:315: undefined reference to `__imp_closesocket'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:333: undefined reference to `__imp_ioctlsocket'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::get_last_error(boost::system::error_code&, bool)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:87: undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::send(unsigned long long, _WSABUF const*, unsigned long long, int, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:1376: undefined reference to `__imp_WSASend'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::recv(unsigned long long, _WSABUF*, unsigned long long, int, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:756: undefined reference to `__imp_WSARecv'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::win_iocp_socket_service_base::start_send_op(boost::asio::detail::win_iocp_socket_service_base::base_implementation_type&, _WSABUF*, unsigned long long, int, bool, boost::asio::detail::win_iocp_operation*)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/win_iocp_socket_service_base.ipp:400: undefined reference to `__imp_WSASend'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/bin/boost_1_76_0/boost/asio/detail/impl/win_iocp_socket_service_base.ipp:402: undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::win_iocp_socket_service_base::start_receive_op(boost::asio::detail::win_iocp_socket_service_base::base_implementation_type&, _WSABUF*, unsigned long long, int, bool, boost::asio::detail::win_iocp_operation*)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/win_iocp_socket_service_base.ipp:455: undefined reference to `__imp_WSARecv'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/bin/boost_1_76_0/boost/asio/detail/impl/win_iocp_socket_service_base.ipp:458: undefined reference to `__imp_WSAGetLastError'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::send(unsigned long long, _WSABUF const*, unsigned long long, int, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:1376: undefined reference to `__imp_WSASend'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::socket(int, int, int, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:1810: undefined reference to `__imp_WSASocketW'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::host_to_network_long(unsigned long)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:3930: undefined reference to `__imp_htonl'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `int boost::asio::detail::socket_ops::call_bind<int>(int boost::asio::detail::socket_ops::msghdr::*, unsigned long long, sockaddr const*, unsigned long long)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:278: undefined reference to `__imp_bind'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `int boost::asio::detail::socket_ops::call_getsockname<int>(int boost::asio::detail::socket_ops::msghdr::*, unsigned long long, sockaddr*, unsigned long long*)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:2099: undefined reference to `__imp_getsockname'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::listen(unsigned long long, int, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:682: undefined reference to `__imp_listen'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `unsigned long long boost::asio::detail::socket_ops::call_accept<int>(int boost::asio::detail::socket_ops::msghdr::*, unsigned long long, sockaddr*, unsigned long long*)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:101: undefined reference to `__imp_accept'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::ioctl(unsigned long long, unsigned char&, int, unsigned long*, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:2128: undefined reference to `__imp_ioctlsocket'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:2128: undefined reference to `__imp_ioctlsocket'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `int boost::asio::detail::socket_ops::call_connect<int>(int boost::asio::detail::socket_ops::msghdr::*, unsigned long long, sockaddr const*, unsigned long long)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:469: undefined reference to `__imp_connect'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::select(int, fd_set*, fd_set*, fd_set*, timeval*, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:2197: undefined reference to `__imp_select'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::win_fd_set_adapter::is_set(unsigned long long) const':
C:/bin/boost_1_76_0/boost/asio/detail/win_fd_set_adapter.hpp:83: undefined reference to `__WSAFDIsSet'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::shutdown(unsigned long long, int, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:460: undefined reference to `__imp_shutdown'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::recv(unsigned long long, _WSABUF*, unsigned long long, int, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:756: undefined reference to `__imp_WSARecv'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::poll_read(unsigned long long, unsigned char, int, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:2234: undefined reference to `__imp_select'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::recv(unsigned long long, _WSABUF*, unsigned long long, int, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:756: undefined reference to `__imp_WSARecv'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\malloy-example-server-basic.dir/objects.a(main.cpp.obj): in function `boost::asio::detail::socket_ops::poll_read(unsigned long long, unsigned char, int, boost::system::error_code&)':
C:/bin/boost_1_76_0/boost/asio/detail/impl/socket_ops.ipp:2234: undefined reference to `__imp_select'
collect2.exe: error: ld returned 1 exit status
mingw32-make[3]: *** [examples\server\basic\CMakeFiles\malloy-example-server-basic.dir\build.make:108: bin/malloy-example-server-basic.exe] Error 1
mingw32-make[2]: *** [CMakeFiles\Makefile2:1026: examples/server/basic/CMakeFiles/malloy-example-server-basic.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:1033: examples/server/basic/CMakeFiles/malloy-example-server-basic.dir/rule] Error 2
mingw32-make: *** [Makefile:240: malloy-example-server-basic] Error 2

I didn't investigate yet. It might be a good idea to extend the CI matrix to also do shared builds.

0x00002a commented 3 years ago

It might be a good idea to extend the CI matrix to also do shared builds.

🤦 Right, thats why the CI won't have complained if there was an issue with msvc

0x00002a commented 3 years ago

Update on this, I'm currently migrating a project to use the latest malloy and came across the issue. It seems no .lib file is generated for the dll, so I guess we do need the dllexport stuff after all.

Tectu commented 3 years ago

I'll handle this (hopefully tomorrow).

Tectu commented 3 years ago

Commit 1235e5827d1d11115d6d9c12d22c29f99d87521e adds the auto-generated export headers. I'm a bit unclear as to whether each component should get its own export header (like it is now) - I guess time will tell :p

This commit only adds them, we still have to make use of them.

Tectu commented 3 years ago

Basically we need to include the export header and use the MALLOY_EXPORT where needed (this gets automatically expanded to something like __declspec(dllexport) or whatever is appropriate for the platform/compiler (thank you cmake!).

Tectu commented 3 years ago

@0x00002a Do you feel like taking it from here? 🙈

0x00002a commented 3 years ago

I'm going away this week/start of weekend (and don't have a windows laptop :p) but I'll have a look week after next. Does WINDOWS_EXPORT_ALL_SYMBOLS (docs) not do this automagically?

Tectu commented 3 years ago

After 2f684ba76832eee94c57d7ac63f7b7d92eee1367 (and 24523a50e39ca6f96e91ba07848348be7f2b7809) I am able to build successfully with -DMALLOY_BUILD_SHARED=ON on Windows with MinGW-w64/MSYS2.

Running the compiled example crashes immedately:

C:\Users\joel\Documents\projects\malloy\cmake-build-debug-mingw-w64-gcc\bin\malloy-example-server-routing-subrouters.exe

Process finished with exit code -1073741515 (0xC0000135)

If my memory is not failing 0xC0000135 indicates that a shared library couldn't be found. Can't investigate further right now.

Tectu commented 3 years ago

Thinking of it, most likely it fails because it can't find the location of the spdlog shared library.

UPDATE: Yep, that was it. Manually copying spdlogd.dll to the <build_dir>/bin directory allowed to launch the example. Not sure why this is the case. I though that cmake will take care of that when the library is linked using target_link_libraries().

0x00002a commented 3 years ago

I though that cmake will take care of that when the library is linked using target_link_libraries()

iirc on non-windows it does. The problem on windows is lack of rpath. One hacky way around this could be to set CMAKE_BINARY_DIR globally at the top of the root cmakelists and then reset it at the end (so as not to pollute users, although if they are on windows they'd need this too)

Tectu commented 2 years ago

@0x00002a since #81 was merged, do we actually still need to generate that malloy_export.hpp header using cmake's generate_export_header()? From what I can tell the answer is no - but I'd appreciate it if you could verify this on your end (Windows / MSVC).

Tectu commented 2 years ago

From what I can tell this is still working just fine (also under Windows 10 & MSVC).