It looks like math.his not enabled in CLion, so you need to enable it! Source here.
- add
#include <math.h> - 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 OverflowVideos
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.hThese 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.
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'
Cmakelists.txt file is like it:
cmake_minimum_required(VERSION 3.6)
project(project_name)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ")
set(SOURCE_FILES main.c)
add_executable(project_name ${SOURCE_FILES})
And you must add this command, for <math.h>
target_link_libraries(project_name PRIVATE m)
That's all.
Add below command in CMakeList.txt
target_link_libraries(${PROJECT_NAME} m)