1

I'am using clion with lots of sub project(exe or lib), it's structure like below:

enter image description here

As to exe(core CMakeList as below), I can click the button run, then it runs as below:

add_executable(cv_knn_demo knn_kdtree_demo.cpp)

enter image description here

But as to library(core CMakeList as below), I can't create library by click the run button(I have to create it like normal cmake project: to mkdir build, and then cmake ..), I know library can't run(just show create exe it convenient by clion, but create library is not)

add_library(demo5 SHARED ${SRC_LIST})

enter image description here

How to create library by clion convenient(no need to do mkdir build; cmake.., just by a click)? my question is not like this: CLion and CMake: only building a library without an executable?

Jayhello
  • 5,931
  • 3
  • 49
  • 56
  • You can't *run* a library, it just doesn't make any sense. Only "programs" can *run*. So if you want to test the functions in a library, you need to make a program (`add_executable`) that uses the library. – Some programmer dude Jul 13 '18 at 07:39
  • I know, but my question means use clion to create library convenient like click a run button. – Jayhello Jul 13 '18 at 07:47
  • If you just want to create a brand new library project, go to the `File` menu and select `New project...`. Then you will get a dialog where you can select C++ or C library projects. Then you program your library and *build* it. That's it. No messing around with the `Run` dialog since you're not supposed to *run* anything. – Some programmer dude Jul 13 '18 at 08:09
  • Dose you mean if a clion project with many project(both exe and library), it can't create library convenient (but exe can)? If I want to create library convenient like a click,it should be a single library project? – Jayhello Jul 13 '18 at 08:14
  • If you have an existing project, you don't create executable sub-project using the `Run` dialog either! You need to manually edit your `CMakeLists.txt` files. The `Run` settings dialog is only to actually *run* programs, it has nothing to do with creating projects, sub-projects or building. – Some programmer dude Jul 13 '18 at 08:17
  • I have solved it – Jayhello Jul 24 '18 at 02:59

1 Answers1

1

I have know how to create it, for example the project demo5 is used to create library.

First, choose demo5(the right rectangle in the below image)

Second, Run->build

enter image description here

Output as below:

enter image description here

Jayhello
  • 5,931
  • 3
  • 49
  • 56