--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -18,7 +18,13 @@ if(NOT MSVC)
     endif()
   include(FindZLIB)
   include_directories(${ZLIB_INCLUDE_DIRS})
+  if(MINGW)
+    if (MATH_FOUND)
+      SET(PKG_CONFIG_PRIVATELIBS "${MATH_LIBRARIES} ${PKG_CONFIG_PRIVATELIBS}")
+    endif()
+  else()
   set(PKG_CONFIG_PRIVATELIBS "-lm ${PKG_CONFIG_PRIVATELIBS}")
+  endif()
   set(PKG_CONFIG_PRIVATELIBS "-lz ${PKG_CONFIG_PRIVATELIBS}")
 else()
   set(MATH "")
@@ -63,6 +69,7 @@ set_target_properties(
   mysofa-static
   PROPERTIES OUTPUT_NAME mysofa CLEAN_DIRECT_OUTPUT 1 POSITION_INDEPENDENT_CODE
                                                       ON)
+target_compile_definitions(mysofa-static PUBLIC MYSOFA_STATIC_DEFINE)
 install(TARGETS mysofa-static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
 
   if(UNIX
@@ -151,7 +158,7 @@ if(BUILD_TESTS)
     COMMAND external)
 
   add_executable(internal tests/internal.c tests/tools.c hrtf/tools.c)
-  target_link_libraries(internal m ${CUNIT_LIBRARIES})
+  target_link_libraries(internal mysofa-static ${CUNIT_LIBRARIES})
   add_test(
     NAME internal
     WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
