0

After sucessfully building libuv on windows in a mingw64 environment, I'm having a problems linking the libuv.dll/libuv.lib that are built as part of the vsbuild.bat build script.

When I build libuv by myself from the sources to produce either a .dll or .lib I can link without any issues.

The errors I get back when including the static or shared lib from the vsbuild.bat are related to undefined references e.g.:

[  9%] Linking CXX shared library ..\buildcmake\bin\libuws.dll
CMakeFiles\uws.dir/objects.a(Group.cpp.obj): In function `uS::Async::start(void (*)(uS::Async*))':
D:/test/uWebSockets/git/src/Libuv.h:37: undefined reference to `uv_async_init'
CMakeFiles\uws.dir/objects.a(Group.cpp.obj): In function `uS::Async::close()':
D:/test/uWebSockets/git/src/Libuv.h:45: undefined reference to `uv_close'

...etc

The specific part of my cmake script that deals with the linking is:

find_library(LIBUV_STATIC_LIBRARY NAMES libuv.lib PATHS ${LIBUV_DEPS_DIR}/git/Debug ${LIBUV_DEPS_DIR}/git/Release  PATH_SUFFIXES ${CMAKE_BUILD_TYPE}/lib NO_DEFAULT_PATH)
find_library(LIBUV_SHARED_LIBRARY NAMES libuv.dll PATHS ${LIBUV_DEPS_DIR}/git PATH_SUFFIXES .libs ${CMAKE_BUILD_TYPE} NO_DEFAULT_PATH)
MESSAGE(STATUS ".${LIBUV_STATIC_LIBRARY}")
MESSAGE(STATUS ".${LIBUV_SHARED_LIBRARY}")
include_directories(${UWS_DIR} ${LIBUVDIR_SRC} ${ZLIB_DIR_INCLUDE} ${LIBUVDIR_INCLUDE} ${OPENSSL_INCLUDE_DIR} )
add_library(uws SHARED ${UWS_SOURCES})
target_link_libraries(uws PUBLIC ${LIBUV_SHARED_LIBRARY} ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
add_definitions(-D_WIN32_WINNT=0x0A00)

cmake output shows the libraries are found ok...

-- .D:/test/deps/libuv/git/Debug/lib/libuv.lib
-- .D:/test/deps/libuv/git/Debug/libuv.dll

Version of CMake is 3.9.something and I'm using nu-mingw with g++.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
Tom Shaw
  • 73
  • 9
  • This might be due to: https://stackoverflow.com/questions/2472924/linking-to-msvc-dll-from-mingw but Im not sure how to investigate if it is. – Tom Shaw Jan 19 '18 at 19:04
  • [You cannot link against a dll in Windows](https://learn.microsoft.com/en-us/cpp/build/linking-an-executable-to-a-dll). Are you sure that your `LIBUV_STATIC_LIBRARY` is indeed a static library and not the corresponding [import library](https://stackoverflow.com/questions/3573475/how-does-the-import-library-work-details) for that dll? – ComicSansMS Jan 22 '18 at 09:49
  • Im not trying to statically link a DLL I'm trying to statically link the lib. Assuming that the library is an import library how would this change my procedure? Using the VS build lib/dll no matter which method I try I cannot get it to link using the dll or lib. – Tom Shaw Jan 24 '18 at 18:49
  • If it's an import library, the exported symbols will have a different signature, because of the dllexport storage class specifier. You would need to account for that when pulling in the library header in your source code. This would explain the linker errors that you are getting, if you pull in the header with the static definitions, but try to link against an import library exporting the dynamic definitions. Check out [the MSDN docs](https://msdn.microsoft.com/en-us/library/aa271769(v=vs.60).aspx) if you need to know more. – ComicSansMS Jan 25 '18 at 07:42
  • A few other tips Ive picked up for anyone else having this issue.Typically an import lib is much smaller than the dll, a standard lib will be a similar size and you can create a DEF file for a given dll which lists the available exported functions. If you add the above as an answer Ill accept it because this problem isn't so easily cut and dried. – Tom Shaw Jan 27 '18 at 12:24

0 Answers0