How to link to <math.h> library using CMake?

后端 未结 1 1767
灰色年华
灰色年华 2021-01-12 13:00

I included library in my source code. But I get compilation errors.

Error: 
**undefined reference to \'sqrt\'
**undefined referen         


        
1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-12 13:27

    I found answer. 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 or any standard library is similar.

    target_link_libraries(project_name PRIVATE m)
    

    That's all.

    0 讨论(0)
提交回复
热议问题