Creating a C++ library - how?

Answered

Hi,

I'm using Clion 2026.2.3.1 on Windows and wanted to try out creating a C++ library to hold some commonly used functions/classes.

However, I can't really find any documentation that helps me. So far I have a CMakeLists.txt file as follows:

cmake_minimum_required(VERSION 4.3)
project(Clib)

set(CMAKE_CXX_STANDARD 23)

add_library(Clib SHARED library.cpp)
 

and I do have libClib.dll/.dll.a in the cmake-build-debug directory, but according to Clion I have a pop-up “Configuration is still incorrect. Do you want to edit it again?” I click “Continue Anyway” and the .dll is created.

Can someone help/advise please?

TIA.

Gary

0
4 comments

Hello

Please provide the following additional information:

  1. A screenshot of the pop-up with “Configuration is still incorrect".
  2. Go to Run | Edit Configurations…, select your Clib run/debug configuration, and provide a screenshot of it.
  3. What button do you press on the toolbar before you see “Configuration is still incorrect": Build ("hammer"), Run ("triangle"), or Debug ('bug")?
0

Anna,

Hopefully I've provided enough info' here for your diagnosis:

I press the run button and this causes the pop-up to appear.

 

 

All I'm trying to do is simply test the process of creating a very simple library that I can then link in from another program, proof of concept etc.

Thanks!

Gary

 

0

Gary Revell, thank you for the information you provided!

I press the run button and this causes the pop-up to appear.

It's not possible to run a library. A C++ library is a collection of code meant to be used by a program, not a program you can run on its own. Unlike an executable, it typically has no main() entry point.

To build the library, use the Build button instead of the Run button.

To use the library, create an executable that links to the library and calls its functions, and run this executable.

0

Sure, I realise that a library is non-executable, I just thought the run button was the way to build it.

I used the hammer and it built fine; just my misunderstanding of the buttons. 

Thanks again!

0

Please sign in to leave a comment.