Starting yesterday I now get the following warning when I comple any code with an import:
nim c temp.nim
ld: warning: ignoring duplicate libraries: '-lm'
import strutils
if isMainModule:
assert "A" & "B" & "C" == "ABC"
assert ["A", "B", "C"].join == "ABC"
if I comment out the import the error goes away:
# import strutils
if isMainModule:
assert "A" & "B" & "C" == "ABC"
# assert ["A", "B", "C"].join == "ABC"
The warning message you encountered, "ld: warning: ignoring
duplicate libraries: '-lm'", is related to the ld command, which
is the linker used in the C and C++ programming languages. This
warning occurs when the linker encounters duplicate library
flags.
In this case, the warning specifically states that the linker is
ignoring the duplicate library flag -lm. The -lm flag is used to
link the math library in C programs. The linker is designed to
handle multiple occurrences of the same library flag, but it
typically ignores the duplicates to avoid unnecessary redundancy.
In most cases, this warning can be safely ignored because the
linker will still successfully link the program. However, if you
encounter multiple warnings for different libraries, it is worth
investigating why the duplicate library flags are present in the
first place. It could indicate an issue with the build system or
the way libraries are being linked.
To summarize, the warning message "ld: warning: ignoring
duplicate libraries: '-lm'" means that the linker has encountered
a duplicate library flag for the math library and is choosing to
ignore it.
macOS Ventura Version 13.5.2
Nim Compiler Version 2.0.0 [MacOSX: amd64]
Compiled at 2023-08-01
Copyright (c) 2006-2023 by Andreas Rumpf
gcc -v
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: x86_64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
cc -v
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: x86_64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
ld -v
@(#)PROGRAM:ld PROJECT:dyld-1015.7
BUILD 18:48:43 Aug 22 2023
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
will use ld-classic for: armv6 armv7 armv7s arm64_32 i386 armv6m armv7k armv7m armv7em
LTO support using: LLVM version 15.0.0 (static support for 29, runtime is 29)
TAPI support using: Apple TAPI version 15.0.0 (tapi-1500.0.12.3)
Library search paths:
Framework search paths:
Can any other Mac Nim users confirm this behavour?
Any recommendations on how to easily make this warning go away would be appreciated
I confirmed this behavior.
The "linkcmd": in your .cache location's .json file for the compilation shows the duplicate flag -lm -lm.
I assume this is the cause of the warning that is emitted.
You can also pass --listCmd to see the compilation commands.
Example: nim --listCmd c temp.nim
I know it is only a minor annoyance but do you know any easy way to make it go away?
Thanks for the reminder. A great tip for adding visibility for troubleshooting such issues.
Note: I just disocered that —listCmd is considered a hint and therefore doesn’t show up if you have a —hints:off in your config.nims file.
There was an Apple update to the Xcode command line support recently — a possible suspect?
Yes, that update included an upgrade from clang 14 to clang 15, and apparently there are some issues.
See, for example, this seemingly related discussion: https://github.com/orgs/Homebrew/discussions/4794
I looked through some old items in my`.cache` and in 1.6.8 there was still duplicate -lm. Clang must of just not been very sensitive to duplicates.
Looking at this more it may be that because the following files use below when defined criteria is met.
{.passl: "-lm".}
This could be the cause of additional -lm.
Clang upgrade could be more sensitive to duplicate arguments such as -lm -lm.
Clang behavior can and does change across versions, e.g. in one of my projects I recently needed to add:
--passC:"-Wno-error=incompatible-function-pointer-types"
That's because there's a behavior change in Clang 16, and I'm using MSYS2's CLANG64 environment on Windows where pacman -S mingw-w64-clang-x86_64-toolchain currently installs v16.
See: https://discourse.llvm.org/t/clang-16-notice-of-potentially-breaking-changes/65562
I just came across this today. It's happening because of the multiple use of the {.passl: "-lm".} pragma as @matthesoundman mentioned.
I was able to suppress the warning by adding this to my nim.cfg file:
# suppress warning about duplicate "-lm" flag
clang.options.linker = "-Wl,-no_warn_duplicate_libraries"