16

How to only build a static library with clion without having an executable? How does the CMakeLists.txt look like? (without add_executable)

Update: If I don't add executable to Clion, I have an error, that an executable is required.

Here my CMakeLists.txt.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
ilw
  • 2,499
  • 5
  • 30
  • 54
  • Your problem is unrelated to CLion, it is only a CMake question. – usr1234567 Mar 31 '15 at 09:08
  • Ok, then your problem is completely unrelated to CMake. You configure to run an executable and you don't have an executable, just a library. CLion cannot execute a library, thus the error. – usr1234567 Mar 31 '15 at 11:46
  • I misunderstood your question. Does this help? http://stackoverflow.com/questions/27869503/clion-build-depend-targets – usr1234567 Mar 31 '15 at 12:02
  • CMakeLists.txt is not available anymore, I have checked https://web.archive.org. – Kresten Jun 15 '19 at 17:58

2 Answers2

21

This is an old question. But I'll add the answer to your question as a help for other people. You need to replace your add_executable with add_library

add_library(target_name source_files)
Praminda
  • 565
  • 4
  • 8
  • 3
    And if you want to build a dynamic library, you can use `add_library(target_name SHARED source_files)`. – shawkinaw Oct 13 '16 at 02:52
2

Short answer: compile the library target and run any custom command as a placeholder to avoid the warning.

Long answer:

CLion lets you either build the whole project and run executables/configurations.

When running executables, you can choose a target to compile and the executable to run after compiling the target. For executable targets, they are usually the same thing. You compile the executable target and then run it.

It seems like this is not really designed for libraries, but there is a workaround. You usually set the target to be the library and the executable to be any executable that depends on this library. However, this is usually not very useful because if you wanted to run this executable you could just set this executable to be the target and the library would be built anyway.

So people probably want to just build the library (to check if everything is OK, etc) without compiling or running any extra executable targets. In this case, the workaround is to choose a custom executable to run after building the library, and the error message is gone.

You have nothing useful you need to run after building the library, just choose any cheap command as a placeholder. Something like "pwd" or "ls".

Setting up a configuration

alandefreitas
  • 69
  • 1
  • 2