Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLion add dependency headers and sources

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?

like image 294
Mihai Bujanca Avatar asked Dec 24 '15 13:12

Mihai Bujanca


People also ask

Does CLion support C++ header files?

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.

How to remap go to header/source in CLion?

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 ):

How do I add a new file in CLion?

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:

How to add CPP and h files to a CLion project?

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.


1 Answers

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>)
like image 193
nastasiak2512 Avatar answered Oct 03 '22 23:10

nastasiak2512