1

I am able to compile and run my code from the terminal with:

g++ main.cpp MapParser.cpp -o test -lgdal -std=c++11

Now I want to run it using CLion, but I am unable to link the gdal shared library in CMakeLists.txt. So far, this is what I have come up with:

cmake_minimum_required(VERSION 3.9)
project(MyMapsParser)

set(CMAKE_CXX_STANDARD 11)

add_library (gdal SHARED ./MapParser.h)
SET_TARGET_PROPERTIES(gdal PROPERTIES LINKER_LANGUAGE C)

set(
        SOURCE_FILES
        main.cpp
        ./MapParser.h
        ./MapParser.cpp
)
add_executable(MyMapsParser ${SOURCE_FILES})
  • Possible duplicate of [How to add "-l" (ell) compiler flag in CMake](https://stackoverflow.com/questions/43136418/how-to-add-l-ell-compiler-flag-in-cmake) – Tsyvarev May 03 '18 at 12:30
  • The 'add_library' command means you are building a new library named 'gdal' from the single source-file 'MapParser.h'. This is certainly not what you want to do. – Sean Burton May 03 '18 at 14:48

1 Answers1

1

I used these configs for CMakeLists.txt and it worked for me.

cmake_minimum_required(VERSION 3.5)
project(MyMapsParser)    

add_compile_options(-std=c++11)

set(
        SOURCE_FILES
        main.cpp
        MapParser.cpp
)
add_executable(MyMapsParser ${SOURCE_FILES})
target_link_libraries(MyMapsParser gdal)