paullouisageneau / libjuice

JUICE is a UDP Interactive Connectivity Establishment library
Mozilla Public License 2.0
403 stars 75 forks source link

Building juice-static on Windows results in a static library that looks to be compiled for a dynamically linked C runtime #229

Closed baldurg closed 8 months ago

baldurg commented 8 months ago

The steps I perform: cmake -B build -G "NMake Makefiles" cd build nmake juice-static

This produces juice-static.lib but if I link against it, it turns out it is full of imp_ wrappers. juice-static.lib(log.c.obj) : error LNK2019: unresolved external symbol __imp_strftime referenced in function juice_log_write 1>juice-static.lib(random.c.obj) : error LNK2019: unresolved external symbol imp_srand referenced in function juice_random 1>juice-static.lib(random.c.obj) : error LNK2019: unresolved external symbol imp_rand referenced in function juice_random 1>juice-static.lib(conn.c.obj) : error LNK2019: unresolved external symbol imp__wassert referenced in function conn_create 1>juice-static.lib(udp.c.obj) : error LNK2001: unresolved external symbol impwassert

This indicates the static library is compiled for a dynamically linked C runtime, which is unusual although not strictly forbidden. However my application has to use a statically linked C runtime or something else breaks. Now, I don't know my tail from my head when it comes to CMake, so I don't really know where to make adjustments to set which C runtime the linker assumes when building the library. (Command line parameter /MT for multi threaded non-debug on the Microsoft linker)

paullouisageneau commented 8 months ago

The runtime to link against on Windows is independent of the library type. The CMake flag to link against MSVC static runtime is -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded (You need to ensure policy CMP0091 is set because libjuice requires a minimal version of CMake where the flag was not present, see the doc here)

baldurg commented 8 months ago

Thank you very much. In the meantime I was able to get it working by adding /MT to C_FLAGS manually in the juice-static target.