Vscodium issue #1972
Unanswered
DanielRein-1
asked this question in
Q&A
Vscodium issue
#1972
Replies: 2 comments 1 reply
-
|
Hi! The issue you’re encountering is common when compiling C/C++ code that uses How to fix it1. Using
|
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Thank you bro but i fixed it while ago
…On Sat, 1 Nov 2025, 05:36 Rodrick Heffley, ***@***.***> wrote:
Hi! The issue you’re encountering is common when compiling C/C++ code that
uses math.h. Functions like sin(), cos(), sqrt(), etc., are part of the *math
library*, which is separate and needs to be linked explicitly.
How to fix it 1. Using gcc or g++ from the terminal
Add -lm at the end of your compile command:
gcc myfile.c -o myprogram -lm
or for C++:
g++ myfile.cpp -o myprogram -lm
- -l tells the linker to link a library.
- m is the math library (libm).
2. If using tasks in VSCodium
If you are building via a task or using the built-in terminal, make sure
the compile command includes -lm.
Example tasks.json snippet:
{
"label": "build math program",
"type": "shell",
"command": "gcc",
"args": [
"${file}",
"-o",
"${fileBasenameNoExtension}",
"-lm"
],
"group": {
"kind": "build",
"isDefault": true
}
}
3. Common mistakes
- Placing -lm *before* the source file may fail on some systems.
Always place -lm *at the end*.
- Ensure you actually have the math library installed (on Linux it
usually comes with glibc, so it’s normally available).
*Summary:*
- Add -lm when compiling.
- Make sure it comes after your source files in the command.
- This will correctly link the math library and resolve math.h
function errors.
—
Reply to this email directly, view it on GitHub
<#1972 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BFUYYNAI7NYZ4HNHQKIGZTL32QMDBAVCNFSM6AAAAACK2RDUHWVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTIOBUGM3TANI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
am on linux using vscodium when i run files that have math.h i get an error how can i solve this to link my code with the math library
Beta Was this translation helpful? Give feedback.
All reactions