Registered Member
|
Hi, all!
I just stumbled across a (newbie?) question about including header files. (I'm just getting familiar with KDevelop (5.6.2) C with Debian, was using Visual-Studio VB.net and C# with Windows until now.) I started a new session "Rheinwerk OpenBook", added a new project from template "Standard - Terminal - CMake C". The "hello world" was displayed in the out window after "Build" and "Execute". The project was set up in /home/miriki/projects/kdevelop/rheinwerk_openbook/hallo_x/. Then I replaced the main.c content with another source from Rheinwerk OpenBook Linux Programmierung: 14.4.6 hallo_x.c (scroll a bit down, extended version of source) and added a new source my_delay.h into the project dir, too. The project still was built and linked without problems. But the header file is used throughout various projects in the book and so I decided to create a "KDevelop global" include directory for this and other projects in the future in /home/miriki/projects/kdevelop/include. Then I added that directory under "Project - Open Configuration - Language Support - Includes/Imports" as a new entry. Additionally I inserted a new line into the CMakeLists.txt:
But the "Build" now errors out with
So my questions actually would be: a) Is the "Language Support" section the correct place to add the .h file(s)? b) If yes, what went wrong? Otherwise, what else to do? c) Is there a global include dir for KDevelop or do I have to set that up for each and every project again? d) Same with libraries for the Linker: Every time into the CMakeLists.txt? Or is there a "global" place? Michael |
Registered Member
|
Hi!
If you write #include "my_delay.h" it expects the file in the current folder of the including file. Read it as "./my_delay.h". So either provide an absolute path "/home/miriki/projects/kdevelop/include/my_include.h" or use <> and "#include <my_delay.h>" like "<stdio.h>", etc. which should work if you added your include directory correctly. If you write your own Makefiles, you must include this path yourself with -I /home/miriki/projects/kdevelop/include. (big i, not L or 1) |
Registered Member
|
Thanks for your answer, but... forgive my dumbness , but: How? I compiled that source at the CLI according to the Rheinwerk Page:
(hallo_x.c changed to main.c) But that was easy, of course, because the my_delay.h resided in the same / actual directory. After moving the my_delay.h to the separate directory I used:
and that worked with both using "" and <> at the #include. But... changing into the Subdir "build" and call "make":
And I thought setting that path in die "Language Support" would result in producing the needed -I /hom... extension for the command line or a line in the managed Make files or whatever. Or am I supposed to edit the build/Makefile? That's auto-generated, isn't it? There are settings for CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR in lines 70 and 73 though... Michael |
Registered Member
|
The Makefile is generated from cmake (if you didn't change it). So you have to provide your include directory by changing CMakeLists.txt like
The first adds the -I line, the second tells cmake to parse this file as part of your project. I'm not that used to cmake as I still write Makefiles for C myself and only use it with Qt which needs other variables, but that should do it. |
Registered Member
|
Yay, fully hit! I now have a file with:
I just replaced the ${YOUR_DIRECTORY} parts with the real path of ~/projects/kdevelop/include/. Ah, and after first success I ommitted the 2nd source file in the set(SOURCES command. And now the "Build" produces (after a "Clear"):
Using the ${xxx} way would require to set a variable with that value methinks? How would that be done? And still the question: What is the point in setting the include path in the project configuration, in the ide settings that is? Michael |
Registered Member
|
I think the language support is a global setting for the tools providing code completion, syntax and logical checking, etc. Depending on what you have installed (cppcheck, clang, …) you can set include folders individually. KDevelop is a modular tool and depends on what you did install and which Plugins you did enable. There are a lot of different tools like git, bazaar for versioning, valgrind, gdb, clang for code checking and debugging, etc.
|
Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]