It looks like math.his not enabled in CLion, so you need to enable it! Source here.

  1. add #include <math.h>
  2. add target_link_libraries( m) in CMakeLists.txt

The second command allows you to link with libm for the math functions.

Adding this to your makefile! (Check the source I gave you!!)

target_link_libraries(log m)
Answer from M.K on Stack Overflow
๐ŸŒ
JetBrains
intellij-support.jetbrains.com โ€บ hc โ€บ en-us โ€บ community โ€บ posts โ€บ 206607085-CLion-Enabling-math-h-for-C-projects
CLion - Enabling for C projects โ€“ IDEs Support (IntelliJ Platform) | JetBrains
August 24, 2015 - Hi Ivan. Please do the following steps: 1) add #include <math.h> 2) add target_link_libraries(<target_name> m) in CMakeLists.txt The second command allows you to link with libm for the math functions.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ [c++/clion] adding source files (.h/.lib ) to a cmake (clion) project. (coming from visual studio)
r/learnprogramming on Reddit: [C++/CLion] Adding source files (.h/.lib ) to a CMake (CLion) project. (Coming from Visual Studio)
January 29, 2019 -

First off all, i don't know if this is a fitting place to ask, but i don't know anywhere else. If anyone could point me in the right direction, i'd be very happy.

For part of my C++ class, i need a given set of files. As seen here:

FLTK_1.3.4-2 
โ”œโ”€โ”€ FL
|   โ””โ”€โ”€ Lots of .h files
โ”œโ”€โ”€lib32
|   โ””โ”€โ”€ lots of .lib files
โ””โ”€โ”€lib64
    โ””โ”€โ”€ lots of .lib files
Graph_lib
โ”œโ”€โ”€ Graph
|   โ””โ”€โ”€ Lots of .h files
โ”œโ”€โ”€lib32
|   โ””โ”€โ”€ lots of .lib files
โ””โ”€โ”€lib64
    โ””โ”€โ”€ lots of .lib files
includes
    โ””โ”€โ”€ std_lib_something.h

These are supposed to be placed in the program files folder. (Done and works with the given project template in MSVC)

I want to, in the same way, include these files in a CLion project i have. For all i know, i have to use CLion. Those above files rely on that given file structure. I've googled to the best of my abilities and think i came some way with how to add them to my project in CLion (still using the MSVC C++ compiler)

Thus my current CMakeLists.txt file looks like this: (ignore the lack of the last includes file, i just copied that .h file into the project .includes)

link_directories("C:/Program Files/TDT4102/FLTK_1.3.4-2/lib64" "C:/Program Files/TDT4102/Graph_lib/lib64")

target_link_libraries(untitled2 Graph_libd.lib fltkd.lib wsock32.lib comctl32.lib fltkjpegd.lib
        fltkimagesd.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
        shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib )
include_directories("C:/Program Files/TDT4102/Graph_lib/Graph"  "C:/Program Files/TDT4102/FLTK_1.3.4-2/FL")

The above is mostly stolen from a Visual studio converter to a CMake project file, this to include the libs, i hope.

The include directories is needed to point to the collection of header files for the projects.

When i try to run i get one funny error, i get an error because it tries to loop up a linux/mac path despite being on Windows. of course, i tried to comment out that section, but that only lead to another further issue. The FL folder has a file called math.h, which conflicts with some other math.h files, leading to mass errors because all the basic math stuff suddenly" isn't in the global namespace of cstdlib."

I'm hoping someone else would know how to proceed to get this working, i vastly prefer to use CLion.

๐ŸŒ
Reddit
reddit.com โ€บ r/c_programming โ€บ how do i use math.h?
r/C_Programming on Reddit: How do I use math.h?
April 14, 2023 -

Programming in C on Linux and using Clion, and I can't get math.h to actually work. I can't figure out why the the -lm gcc argument isn't working. Why is this language so difficult to get to work properly?

Compiling with command

gcc *.c -o Project.o -lm

Get errors

/usr/bin/ld: serial.c:(.text+0x2335): undefined reference to `min'
/usr/bin/ld: serial.c:(.text+0x2360): undefined reference to `max'
/usr/bin/ld: serial.c:(.text+0x2371): undefined reference to `min'
/usr/bin/ld: serial.c:(.text+0x238a): undefined reference to `max'
/usr/bin/ld: serial.c:(.text+0x239b): undefined reference to `min'
/usr/bin/ld: serial.c:(.text+0x23a9): undefined reference to `max'
/usr/bin/ld: serial.c:(.text+0x2756): undefined reference to `min'
/usr/bin/ld: serial.c:(.text+0x277b): undefined reference to `min'
/usr/bin/ld: serial.c:(.text+0x2791): undefined reference to `min'
/usr/bin/ld: serial.c:(.text+0x279f): undefined reference to `max'
Find elsewhere
๐ŸŒ
Arch Linux Forums
bbs.archlinux.org โ€บ viewtopic.php
standard sqrt() in C not working? / Programming & Scripting / Arch Linux Forums
March 29, 2022 - As the only math function used in the code can be evaluated to a constant at compile-time, the compiler does that for you and eliminates it from the code. So there is no call to a "sqrt" function in the compiled code, and thus no need to link to the math library to provide a sqrt function.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 68374653 โ€บ clion-does-not-find-math-h-anymore
c++ - CLION does not find math.h anymore - Stack Overflow
Today I upgraded CLION to version 2021.1.3 Suddenly my project turns red, because math.h ( It is a legacy project, don't ask!!!) is no longer found and even the good old printf is no longer known. ...
๐ŸŒ
JetBrains
jetbrains.com โ€บ help โ€บ clion โ€บ quick-cmake-tutorial.html
Quick CMake tutorial | CLion Documentation
April 3, 2025 - For example, if we place a header called header_math.h inside the includes/math folder, we can then include it from calc_lib.cpp using #include "header_math.h".
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 66347631 โ€บ clion-cant-include-math-h
c - CLion: Can't include Math.h - Stack Overflow
You don't do that with CMake, fms.c is missing #include <math.h>. m is specific to GCC, don't link it for MSVC. โ€“ Hans Passant Commented Feb 24, 2021 at 9:40 ยท Add a comment | Related questions ยท 21 ยท When compiling in clion I get the error "executable is not specified" 1 ยท
๐ŸŒ
JetBrains
intellij-support.jetbrains.com โ€บ hc โ€บ en-us โ€บ community โ€บ posts โ€บ 360006469520-Math-header-doesn-t-work
Math header doesn't work โ€“ IDEs Support (IntelliJ Platform) | JetBrains
October 23, 2019 - Hello, I have a problem with CLion. I did some research, tried some suggestions, but neither of them helped me. I am using CLion on Elementary OS to write programs in C. The problem is I can't build any project with math header. It's very strange, because the editor itself knows the syntax ...
๐ŸŒ
Programiz
programiz.com โ€บ c-programming โ€บ library-function โ€บ math.h โ€บ ceil
C ceil() - C Standard Library
#include <stdio.h> #include <math.h> int main() { double num = 8.33; int result; result = ceil(num); printf("Ceiling integer of %.2f = %d", num, result); return 0; }
๐ŸŒ
YouTube
youtube.com โ€บ watch
CLION C++ Header File .h in Multiple Files #cpplus ...
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
๐ŸŒ
KiCad
forum.kicad.info โ€บ software
CLion & MSYS2 - missing wxWidgets_LIBRARIES - Software - KiCad.info Forums
March 31, 2021 - Hi There, I have been successfully building KiCad from source under Linux and wanted to now build KiCad under windows using MSYS2 & CLion. I followed this guide here: https://dev-docs.kicad.org/en/build/windows-msys2/ Wโ€ฆ
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ C_mathematical_functions
C mathematical functions - Wikipedia
1 month ago - Beginning in C++17, C++ introduces special functions into the <cmath> header. Under POSIX systems like Linux and BSD, the mathematical functions (as declared in <math.h>) are bundled separately in the mathematical library libm. Therefore, if any of those functions are used, the linker must be given the directive -lm.
๐ŸŒ
JetBrains
intellij-support.jetbrains.com โ€บ hc โ€บ en-us โ€บ community โ€บ posts โ€บ 9973535938450-changing-built-in-math-function
changing built in math function โ€“ IDEs Support (IntelliJ Platform) | JetBrains
But CLion uses the libm one instead of mine ยท I have observed that target_link_libraries is not longer necessary to include libm in linking ยท Is there any way to exclude -lm for linking? Do I have to change my function name (it works fine If I do so)? ... Only stdio.h. No need to include math.h nor specify that the program must be linked with libm