Skip to content

build error missing math flag -lm #145

@bakeromso

Description

@bakeromso

I'm building on Debian 13, and following the instructions from https://pip-assets.raspberrypi.com/categories/610-raspberry-pi-pico/documents/RP-008276-DS-1-getting-started-with-pico.pdf?disposition=inline

$ git clone https://github.com/raspberrypi/openocd.git
$ cd openocd
$ ./bootstrap
$ ./configure --disable-werror
$ make -j4

I think it should recursively clone so it pulls in jimtcl as well. I couldn't get that package using APT and default repos in Debian Trixie anyways.
Building jimtcl goes without any problems, but then I get the following error (due to a missing -lm flag in libtool)

 $/bin/bash ./libtool  --tag=CC   --mode=link gcc -Wall -Wstrict-prototypes -Wformat-security -Wshadow -Wextra -Wno-unused-parameter -Wbad-function-cast -Wcast-align -Wredundant-decls -Wpointer-arith -Wundef -Werror  -g -O2   -o src/openocd src/main.o src/libopenocd.la   -L/usr/local/lib -ljim -lssl -lcrypto -lz
libtool: link: gcc -Wall -Wstrict-prototypes -Wformat-security -Wshadow -Wextra -Wno-unused-parameter -Wbad-function-cast -Wcast-align -Wredundant-decls -Wpointer-arith -Wundef -Werror -g -O2 -o src/openocd src/main.o  src/.libs/libopenocd.a -lm -L/usr/local/lib -ljim -lssl -lcrypto -lz
/usr/bin/ld: /usr/local/lib/libjim.a(jim.o): in function `JimExprOpDoubleUnary':
jim.c:(.text+0x1430f): undefined reference to `sin'
/usr/bin/ld: jim.c:(.text+0x14327): undefined reference to `cos'
/usr/bin/ld: jim.c:(.text+0x1433f): undefined reference to `tan'
/usr/bin/ld: jim.c:(.text+0x14357): undefined reference to `asin'
/usr/bin/ld: jim.c:(.text+0x1436f): undefined reference to `acos'
/usr/bin/ld: jim.c:(.text+0x14387): undefined reference to `atan'
/usr/bin/ld: jim.c:(.text+0x1439f): undefined reference to `sinh'
/usr/bin/ld: jim.c:(.text+0x143b7): undefined reference to `cosh'
/usr/bin/ld: jim.c:(.text+0x143cf): undefined reference to `tanh'
/usr/bin/ld: jim.c:(.text+0x144a7): undefined reference to `exp'
/usr/bin/ld: jim.c:(.text+0x144bf): undefined reference to `log'
/usr/bin/ld: jim.c:(.text+0x144d7): undefined reference to `log10'
/usr/bin/ld: jim.c:(.text+0x144f6): undefined reference to `sqrt'
/usr/bin/ld: /usr/local/lib/libjim.a(jim.o): in function `JimExprOpBin':
jim.c:(.text+0x15109): undefined reference to `pow'
/usr/bin/ld: jim.c:(.text+0x151f5): undefined reference to `atan2'
/usr/bin/ld: jim.c:(.text+0x153ac): undefined reference to `fmod'
/usr/bin/ld: jim.c:(.text+0x153c5): undefined reference to `hypot'
collect2: error: ld returned 1 exit status

Manually adding the -lm flag quick fixes the issue

$/bin/bash ./libtool  --tag=CC   --mode=link gcc -Wall -Wstrict-prototypes -Wformat-security -Wshadow -Wextra -Wno-unused-parameter -Wbad-function-cast -Wcast-align -Wredundant-decls -Wpointer-arith -Wundef -Werror  -g -O2   -o src/openocd src/main.o src/libopenocd.la   -L/usr/local/lib -ljim -lssl -lcrypto -lz -lm

now continuing with make is successful.

I don't have the proposed fix. I think it may all be related to jimctl not being installed on my system. Since it's linked as a submodule in this repo, I think this is something expected, so the Makefile I think should handle this case correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions