How to add compiler -l "(ell) flag in CMake

Work on Ubuntu 16

I used the command g++ main.cpp -lpqto compile my small project. Now I am using Clion and want to do the same thing that I am with g++. But I can not add compiler flags to the cmake file and get a compilation error.

cmake_minimum_required(VERSION 3.5.1)
project(day_g)

set(CMAKE_CXX_FLAGS "-lpq")

add_definitions(-lpq)

message("CMAKE_CXX_FLAGS is ${CMAKE_CXX_FLAGS}")

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(day_g ${SOURCE_FILES})

Also I only run the cmake file and get CMAKE_CXX_FLAGSwith the -lpq flag.

CMAKE_CXX_FLAGS is -lpq
-- Configuring done
-- Generating done

How to correctly add compiler flags to cmake file?

+5
source share
2 answers

-l , . . CMake target_link_libraries :

target_link_libraries(day_g pq)
+7

-lq - (CFLAGS), .

CMake, :

target_link_libraries(target_name libraries...)

, "q" , libq.a , windows q.dll.

... CMakeLists.txt :

target_link_libraries(day_g pq)

, CFLAG "" , , :

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")

, cmake , :

make VERBOSE=1
+1

Source: https://habr.com/ru/post/1673691/


All Articles