Home > OS >  what's the equivalence of Clang 's "-rdynamic" option in CMake?
what's the equivalence of Clang 's "-rdynamic" option in CMake?

Time:04-19

I'm trying to create a new programming language by reading LLVM documents. One of the documents is about "Kaleidoscope", a toy programming language. (tutorial's here: https://releases.llvm.org/9.0.0/docs/tutorial/LangImpl01.html).

All the codes in tutorial are written in a single file, and can be compiled by the command below:

clang   -g -O3 toy.cpp -I/usr/lib/llvm-10/include -std=c  14  \
-fno-exceptions -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS \
-L/usr/lib/llvm-10/lib \
-rdynamic \
-lLLVM-10 -o toy

However, I want to manage my project by CMake. I've translate most of the command above into a CMakeLists.txt file (attached afterwards), besides the option "-rdynamic". Does anyone know how to add this option to my CMakeLists.txt ? Thanks in advance!

SET(CMAKE_CXX_COMPILER "/usr/bin/clang  ")
INCLUDE_DIRECTORIES("/usr/lib/llvm-10/include")
LINK_DIRECTORIES("/usr/lib/llvm-10/lib")

SET(_GNU_SOURCE 1)
SET(__STDC_CONSTANT_MACROS 1)
SET(__STDC_FORMAT_MACROS 1)
SET(__STDC_LIMIT_MACROS 1)

# Project configuration
# omit something unrelated

FIND_PACKAGE(LLVM REQUIRED CONFIG)
TARGET_LINK_LIBRARIES(compiler LLVM-10)

CodePudding user response:

First of all, writing CMake commands in upper case was obsolete 10 years ago. Now it is simply unacceptable (in my opinion) so it should be set(), include_directories() etc.

As to your question: rdynamic is a linker flag, so you use target_link_options() command to add it to your target. If it was a compiler flag, you would use target_compile_options().

Example: target_link_options(compiler PRIVATE rdynamic)

CodePudding user response:

Quite akward to find out just adding this to CMakeLists.txt is OK.

set(CMAKE_CXX_FLAGS -rdynamic)
  • Related