0

I faced a problem when i migrated a project from Linux to windows for the visual studio seem can not use dll lib directly. I look through a number of materials and known i seem should use IMPORTED in add_library(...), but i can not find a practical example about how to use it and i used it like this:

add_library(hello_lib SHARED hello.c)
add_library(hello_lib SHARED IMPORTED)

And a ERROR happened

CMake Error at sub_haha/CMakeLists.txt:6 (add_library):
add_library cannot create imported target "haha_lib" because another target
with the same name already exists.

Could you please give me one or some? BTW the dll lib seem could be used in Mingw makefile on windows.

Chao Zhang
  • 190
  • 2
  • 15
  • As error message tells, you cannot create two targets with same name. Choose another name for imported library. – Tsyvarev Apr 25 '16 at 06:52
  • @Tsyvarev, I know this error, i just do not know how to use it to link dll in windows. – Chao Zhang Apr 25 '16 at 06:54
  • For link with library `target_link_libraries` command should used, as usual. Do not understand your problem. – Tsyvarev Apr 25 '16 at 06:57
  • For some details on creating/using shared libraries in CMake see e.g. [here](http://stackoverflow.com/questions/33062728/cmake-link-shared-library-on-windows) or [here](http://stackoverflow.com/questions/1941443/cmake-linking-against-shared-library-on-windows-error-about-not-finding-lib-fi). – Florian Apr 25 '16 at 17:04

0 Answers0