Skip to content

clang linker on MacOS doesn't support -warn_commons for target linux. (IDFGH-12129) #13185

Closed
@morgana2313

Description

The clang linker on MacOs (target=linux) doesn't support the -warn_commons option:

hello_world $ idf.py --preview set-target linux
hello_world $ idf.py build
ld: unknown options: -warn_commons

If I remove this option it builds without a hitch:

list(APPEND link_options "-Wl,-warn_commons")

-    list(APPEND link_options "-Wl,-warn_commons")
+    list(APPEND link_options "-Wl")
Details
Executing action: all (aliases: build)
Running ninja in directory /Users/jasper/esp/esp-idf/examples/get-started/hello_world/build
Executing "ninja all"...
[3/3] Linking C executable hello_world.elfFAILED: hello_world.elf
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -mmacosx-version-min=14.1 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -fno-rtti -fno-lto -Wl,-dead_strip -Wl,-warn_commons CMakeFiles/hello_world.elf.dir/project_elf_src_linux.c.o -o hello_world.elf  esp-idf/linux/liblinux.a  esp-idf/esp_system/libesp_system.a  esp-idf/esp_common/libesp_common.a  esp-idf/esp_rom/libesp_rom.a  esp-idf/log/liblog.a  esp-idf/heap/libheap.a  esp-idf/esp_hw_support/libesp_hw_support.a  esp-idf/freertos/libfreertos.a  esp-idf/main/libmain.a  esp-idf/linux/liblinux.a  esp-idf/esp_system/libesp_system.a  esp-idf/esp_common/libesp_common.a  esp-idf/esp_rom/libesp_rom.a  esp-idf/log/liblog.a  esp-idf/heap/libheap.a  esp-idf/esp_hw_support/libesp_hw_support.a  esp-idf/freertos/libfreertos.a  esp-idf/linux/liblinux.a  esp-idf/esp_system/libesp_system.a  esp-idf/esp_common/libesp_common.a  esp-idf/esp_rom/libesp_rom.a  esp-idf/log/liblog.a  esp-idf/heap/libheap.a  esp-idf/esp_hw_support/libesp_hw_support.a  esp-idf/freertos/libfreertos.a  esp-idf/linux/liblinux.a  esp-idf/esp_system/libesp_system.a  esp-idf/esp_common/libesp_common.a  esp-idf/esp_rom/libesp_rom.a  esp-idf/log/liblog.a  esp-idf/heap/libheap.a  esp-idf/esp_hw_support/libesp_hw_support.a  esp-idf/freertos/libfreertos.a  esp-idf/linux/liblinux.a  esp-idf/esp_system/libesp_system.a  esp-idf/esp_common/libesp_common.a  esp-idf/esp_rom/libesp_rom.a  esp-idf/log/liblog.a  esp-idf/heap/libheap.a  esp-idf/esp_hw_support/libesp_hw_support.a  esp-idf/freertos/libfreertos.a  -lpthread && :
ld: unknown options: -warn_commons
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
ninja failed with exit code 1, output of the command is in the /Users/jasper/esp/esp-idf/examples/get-started/hello_world/build/log/idf_py_stderr_output_94370 and /Users/jasper/esp/esp-idf/examples/get-started/hello_world/build/log/idf_py_stdout_output_94370

I've minimalised main/hello_world_main.c to:

#include <stdio.h>
void app_main(void)
{
    printf("Hello world!\n");
}

With the above patch it builds and executes ok:

hello_world $ idf.py build
Executing action: all (aliases: build)
Running ninja in directory /Users/jasper/esp/esp-idf/examples/get-started/hello_world/build
Executing "ninja all"...
[0/1] Re-running CMake...-- Component directory /Users/jasper/mp-v5-flexy/components/sn_faust does not contain a CMakeLists.txt file. No component will be added
-- Building ESP-IDF components for target linux
-- Project sdkconfig file /Users/jasper/esp/esp-idf/examples/get-started/hello_world/sdkconfig
Loading defaults file /Users/jasper/esp/esp-idf/examples/get-started/hello_world/sdkconfig.defaults...
Loading defaults file /Users/jasper/mp-v5-flexy/sn-idf/sn-sdkconfig.defaults...
Loading defaults file /Users/jasper/.sdkconfig.defaults...
-- Components: esp_common esp_hw_support esp_rom esp_system freertos hal heap linux log main soc
-- Component paths: /Users/jasper/esp/esp-idf/components/esp_common /Users/jasper/esp/esp-idf/components/esp_hw_support /Users/jasper/esp/esp-idf/components/esp_rom /Users/jasper/esp/esp-idf/components/esp_system /Users/jasper/esp/esp-idf/components/freertos /Users/jasper/esp/esp-idf/components/hal /Users/jasper/esp/esp-idf/components/heap /Users/jasper/esp/esp-idf/components/linux /Users/jasper/esp/esp-idf/components/log /Users/jasper/esp/esp-idf/examples/get-started/hello_world/main /Users/jasper/esp/esp-idf/components/soc
-- Configuring done (1.4s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/jasper/esp/esp-idf/examples/get-started/hello_world/build
[1/1] Linking C executable hello_world.elfld: warning: ignoring duplicate libraries: 'esp-idf/esp_common/libesp_common.a', 'esp-idf/esp_hw_support/libesp_hw_support.a', 'esp-idf/esp_rom/libesp_rom.a', 'esp-idf/esp_system/libesp_system.a', 'esp-idf/freertos/libfreertos.a', 'esp-idf/heap/libheap.a', 'esp-idf/linux/liblinux.a', 'esp-idf/log/liblog.a'
Done

hello_world $ idf.py monitor
Executing action: monitor
Running idf_monitor in directory /Users/jasper/esp/esp-idf/examples/get-started/hello_world
Executing "/Users/jasper/.espressif/python_env/idf5.1_py3.11_env/bin/python /Users/jasper/esp/esp-idf/tools/idf_monitor.py --toolchain-prefix  --target linux /Users/jasper/esp/esp-idf/examples/get-started/hello_world/build/hello_world.elf -m '/Users/jasper/.espressif/python_env/idf5.1_py3.11_env/bin/python' '/Users/jasper/esp/esp-idf/tools/idf.py'"...
--- esp-idf-monitor 1.3.4 on linux ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
I (2780252600) port: Starting scheduler.
Hello world!

Done

Metadata

Labels

Resolution: NAIssue resolution is unavailableStatus: DoneIssue is done internally

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions