0

I want to add libpqxx library to my project, but find_package doesn't seem work with it. So I decided to manually add pkg-config's output on libpqxx to compiler and linker flags. For some reason this doesn't work (I tried building with CLion and from terminal, they both failed but with different errors). But if I simply insert pkg-config's output manually, then everything works fine.

execute_process (COMMAND bash -c "pkg-config --cflags libpqxx" OUTPUT_VARIABLE libs_cflags)
execute_process (COMMAND bash -c "pkg-config --libs libpqxx" OUTPUT_VARIABLE libs_linker_flags)

# Prints 'flags ='
execute_process (COMMAND bash -c "echo flags = ${CMAKE_CXX_FLAGS}")

# Works fine
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/opt/homebrew/Cellar/libpqxx/7.7.0/include")

# Doesn't work
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${libs_cflags}")

# Prints 'flags=-I/opt/homebrew/Cellar/libpqxx/7.7.0/include'
execute_process (COMMAND bash -c "echo flags = ${CMAKE_CXX_FLAGS}")

# Works fine
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/opt/homebrew/Cellar/libpqxx/7.7.0/lib -lpqxx")

# Doesn't work
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${libs_linker_flags}")

  • Most likely your output variables contains newline symbol at the end. You could spot that symbol by printing a variable in quotes: `message(STATUS "libs_linker_flags: '${libs_linker_flags}'")`. – Tsyvarev Mar 18 '22 at 21:28
  • You are right, thanks! – tralf_strues Mar 18 '22 at 21:52

1 Answers1

1

Turns out libs_cflags and libs_linker_flags had trailing whitespaces. Using OUTPUT_STRIP_TRAILING_WHITESPACE for execute_process() solves the problem.