0

I've got an example makefile given from ChartDirector that compiles what I want correctly, but I want to convert it to cmake to use the code in a larger project involving cmake.

Relevant Makefile code:

CC = g++
CFLAGS = -Idependencies/ChartDirector/include -Ldependencies/ChartDirector/lib -Wl,-Rdependencies/ChartDirector/lib
LIBS = -lchartdir
TARGET = main

Current CMakeLists.txt

cmake_minimum_required(VERSION 3.12)
project(main VERSION 1.0)
add_executable(main main.cpp)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dependencies/ChartDirector/include)
target_link_directories(main PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/ChartDirector/lib)

I think all i'm missing is the linker option -Wl,-Rdependencies/ChartDirector/lib. Cmake will run with this, but the makefile won't find everything it needs.

Neza
  • 117
  • 1
  • 7
  • 1
    [https://cmake.org/cmake/help/v3.23/command/target_link_options.html](https://cmake.org/cmake/help/v3.23/command/target_link_options.html) – drescherjm Feb 18 '22 at 16:56
  • 1
    Note, that `-L` and `-Wl` are pure **linker** options(flags), so placing them into `CFLAGS` is confusing: This variable denotes options(flags) for C **compiler**. Also you forgot to translate into `CMakeLists.txt` the `LIBS` variable (with `target_link_libraries` command). – Tsyvarev Feb 18 '22 at 17:10
  • Thanks @Tsyvarev that target_link_libraries was all I was missing – Neza Feb 18 '22 at 17:16

0 Answers0