0

I want to create a shared *.dll library using a *.a Static library

Below is my CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(Projects)

set(CMAKE_CXX_STANDARD 11)

include_directories(../msys64/mingw64/include)
include_directories("../Program Files/Java/jdk1.8.0_151/include" "../Program Files/Java/jdk1.8.0_151/include/win32")
add_library(Projects1 SHARED main.cpp HelloWorld.cpp )

add_library(libgdal STATIC IMPORTED)
set_target_properties(libgdal PROPERTIES IMPORTED_LOCATION ../msys64/mingw64/lib/libgdal.a)
target_link_libraries(Projects1 A libgdal C )

it gives me below error:

*** No rule to make target '../msys64/mingw64/lib/libgdal.a', needed by 'libProjects1.dll'.  Stop.

although when I try to create a Static Lib changing as below it works fine.

 add_library(Projects1 STATIC main.cpp HelloWorld.cpp )

I am not sure how to create a Shared Library using a Static Library

Thanks for all the help in advance

Niraj Sanghani
  • 1,493
  • 15
  • 23
  • `when I try to create a Static Lib changing as below it works fine.` - Linker isn't called for *static* libraries, so "works fine" here means nothing. You need to specify correct IMPORTED_LOCATION of the IMPORTED library. It is better to specify **absolute path**. If you want to refer to current directory (where `CMakeLists.txt` located), use `${CMAKE_CURRENT_SOURCE_DIR}`. – Tsyvarev May 14 '18 at 13:43
  • Hello thanks for your response. I am new to cmake and c++, could you give me a reference for my problem or explain me more.. where I am going wrong. My sole purpose is to either link a .dll or .a file and create my own .dll – Niraj Sanghani May 14 '18 at 14:37
  • 1
    You current code in `CMakeLists.txt` uses *relative path* `../msys64/mingw64/lib/libgdal.a` as *IMPORTED_LOCATION* property. You need to use **absolute path** instead. If your current path is meant to be relative to current directory (one with `CMakeLists.txt` file), then use `${CMAKE_CURRENT_SOURCE_DIR}/../msys64/mingw64/lib/libgdal.a` – Tsyvarev May 14 '18 at 14:47
  • Hello I changed it to relative path it is still giving me error no rule to make target libgdal.a needed by libprojects.dll – Niraj Sanghani May 14 '18 at 14:56
  • So, the error remains, am I correctly understand you? The error means that the file your refer **doesn't exist**. You need to specify existed file. – Tsyvarev May 14 '18 at 15:01
  • I think my .a file is not getting included correctly! Still Even I am not sure – Niraj Sanghani May 14 '18 at 15:03
  • Hello thank-you for your help, You were right , There was a space in between in the folder Name so i had to put up "Folder SAS" and it worked. Really thankyou for ur support. – Niraj Sanghani May 15 '18 at 06:55

0 Answers0