首页 > 解决方案 > 即使使用“-lm”标志也出现“未定义的对‘floorf’的引用”错误

问题描述

在我的代码中使用 math.h 库中的 floorf 函数会导致“未定义对‘floorf’的引用”错误。我已经编辑了我的 tasks.json 以包含“-lm”标志文件,如下所示:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc-9 build active file",
            "command": "/usr/bin/gcc-9",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-lm"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Generated task by Debugger"
        }
    ],
    "version": "2.0.0"
}

但是,没有任何改变,我仍然收到错误消息。

我在 Vscode 中使用 WSL。

编辑:这是错误输出:

Build finished with error:

/usr/bin/ld: /tmp/ccg38t0m.o: in function `fill1d':
/home/viktor/upr/cosSim.c:51: undefined reference to `floorf'
collect2: error: ld returned 1 exit status

The terminal process failed to launch (exit code: -1).
enter code here

标签: cgccvisual-studio-codewindows-subsystem-for-linux

解决方案


推荐阅读