I have a project that uses C in some modules and C++ in others - everything being built with a Makefile
.
I created a CMakeLists.txt
file that just calls the Makefile
so the project can be imported in Clion. When I run my program, I get a segfault in one of the libraries I previously built (so, I have the sources, the headers and the static library) - so I'm trying to debug that library in the context of my project.
Now, my question is how do I add the headers, library and library sources to my project in Clion so I can set breakpoints and debug it?
This is a C++ project, but CLion navigated fine to <string> standard header file. If CLion was kind enough to offer Show Compiler Info option anywhere, I'd be happy to share it's output. As it is, however, CLion is not that cooperative.
If you are accustomed to Go to Related Symbol for switching between header and source files, you can remap its shortcut to Go to Header/Source. Once per installation, CLion will prompt you to do that when you invoke Go to Related Symbol via the shortcut in a C/C++ file (if the non-default shortcut is not yet set for Go to Header/Source ):
In the Project tree, right-click the folder you want to add a file into and select New from the context menu. Choose the desired file type: Specify the name, type, and additional options for the new file. For C++ Class, C/C++ Source, and C/C++ Header file templates, CLion will prompt you to add the new file to one or several existing CMake targets:
ALL THE FILES SHOULD BE ON THE CMakeList.txt folder! if not, remember to add the path in there. There is also a way to make CLion to add any cpp and h files (I don't know why don't they do it by default) and is to add this line: In this example: ClionProject is actually the name of the project.
You need to add your library to the sources with a separate CMake like:
set(HEADER_FILES ...)
set(SOURCE_FILES ...)
add_library(<lib_name> STATIC ${SOURCE_FILES} ${HEADER_FILES})
Then you link you program with a library in CMake like that:
target_link_libraries(<prog_name> <lib_name>)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With