CMake - How to avoid CMAKE_CXX_FLAGS in linker command-line
Asked Answered
O

1

8

I'm having a problem with cmake / gcc / Linux.

No matter what I try, I cannot get rid of CMAKE_CXX_FLAGS on my linker line. CMake keeps passing them when invoking g++ in link mode.

I have -fopenmp in my CMAKE_CXX_FLAGS and it must not be present on the link line so g++ doesn't link to gomp (I'm using Intel's iomp5 instead).

Edit: I tried the following the beginning of CMakeLists.txt, didn't help:

set(CMAKE_CXX_LINK_EXECUTABLE
    "<CMAKE_CXX_COMPILER>  <FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>")

Thanks

Ozonize answered 30/11, 2017 at 19:56 Comment(1)
Redefining CMAKE_CXX_LINK_EXECUTABLE should help. Show what have you tried (in form of minimal reproducible example). Also, as suggested [in that answer] for similar question, you may use COMPILE_FLAGS property for compiler-only options.Snyder
O
7

Turns out

add_compile_options("-fopenmp")

avoids adding these options to the linker. It doesn't solve the general issue of CMAKE_CXX_FLAGS showing up in the linker line, but it solves the immediate problem I have.

Ozonize answered 30/11, 2017 at 21:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.