# Linking shared library fails on MacOS

**URL:** https://discourse.cmake.org/t/linking-shared-library-fails-on-macos/13706
**Category:** Code
**Tags:** os:macos
**Created:** [March 9, 2025, 9:09pm UTC](https://discourse.cmake.org/t/linking-shared-library-fails-on-macos/13706 "2025-03-09T21:09:45Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![shmuel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/f17d59/32.png) [@shmuel](https://discourse.cmake.org/u/shmuel)
#### Post date: [March 9, 2025, 9:09pm UTC](https://discourse.cmake.org/t/linking-shared-library-fails-on-macos/13706/1 "2025-03-09T21:09:45Z")

</div>

There are 2 targets (the code is simplified):

1. far2m - an executable that also exports symbols, e.g.

```auto
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    add_executable(far2m MACOSX_BUNDLE ${SOURCES} "DE/Far.icns")
else()
    add_executable(far2m ${SOURCES})
endif()
set_target_properties(far2m PROPERTIES ENABLE_EXPORTS TRUE)

```

1. luafar - a dynamic library  
`add_library (luafar SHARED ${SOURCES})`  
`target_link_libraries(luafar far2m)`

This code works fine on Linux but not on MacOS. The following errors are issued:

```auto
[51%] Linking CXX shared library ../install/far2m.app/Contents/MacOS/Plugins/luafar/luafar.so
Undefined symbols for architecture arm64:
  "_WINPORT_CloseHandle", referenced from:
      _su_FileClose in sysutils.c.o
      _ExtractFileTime in win.c.o
      ...
  "_WINPORT_CompareString", referenced from:
      _win_CompareString in win.c.o
  "_WINPORT_CreateDirectory", referenced from:
      _win_CreateDir in win.c.o
      ...

```

These undefined symbols are contained in far2m.  
I have zero experience with MacOS and never had a Mac.  
Could you please advise what is incorrect in my code and how it could be fixed?
