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
Please sign in to leave a comment.
Hello
Please provide the following additional information:
Clibrun/debug configuration, and provide a screenshot of it.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
Gary Revell, thank you for the information you provided!
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.
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!