Skip to content

Commit 227b49d

Browse files
Guang Yangfacebook-github-bot
authored andcommitted
Fix unsupported linker flag on Mac (#4473)
Summary: Run into the following linker error on Mac: ``` [ 83%] Linking CXX executable llama_main ld: warning: -s is obsolete ld: unknown options: --gc-sections clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [llama_main] Error 1 make[1]: *** [CMakeFiles/llama_main.dir/all] Error 2 make: *** [all] Error 2 ``` Env: `clang --version` ``` Apple clang version 15.0.0 (clang-1500.3.9.4) Target: arm64-apple-darwin23.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin ``` Fix: It turns out that Apple Clang linker doesn't support the `--gc-sections` options, where it instructs the linker to remove unused sections from the final executable or shared library. Use an equivalent flags `-dead_strip` instead on Mac. Pull Request resolved: #4473 Reviewed By: cccclai Differential Revision: D60474232 Pulled By: guangy10 fbshipit-source-id: d1f2745913a49588bdac4e8f5f792dfae4d7c9cd
1 parent 2852bda commit 227b49d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

examples/models/llama2/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ endif()
216216

217217
add_executable(llama_main ${_srcs})
218218
if(CMAKE_BUILD_TYPE STREQUAL "Release")
219-
target_link_options(llama_main PRIVATE "LINKER:--gc-sections,-s")
219+
if(APPLE)
220+
target_link_options(llama_main PRIVATE "LINKER:-dead_strip")
221+
else()
222+
target_link_options(llama_main PRIVATE "LINKER:--gc-sections,-s")
223+
endif()
220224
endif()
221225

222226
target_include_directories(llama_main PUBLIC ${_common_include_directories})

0 commit comments

Comments
 (0)