Discussion:
adding source files for compilation
Robert Puskas
2016-11-24 18:56:32 UTC
Permalink
Hi.

I'm rather new to KDevelop, so the question is probably very noobish, but I have to ask anyway:

Right now, I'm using the default shipped template for a small project: Standard --> Terminal --> CMake C++. I also created a header file (my.h) and an additional my.cpp file by right clicking onto the project folder in the projects side pane, and used the create file option. After filling up main.cpp, my.h and my.cpp, with some code, the compiler gives an "undefined reference to" error message to those functions that are declared in my.h and defined in my.cpp.

After browsing around the project folder created by KDevelop, I noticed that none of the cmake files contain any entry about my newly added my.h and my.cpp files, so I suspect my.cpp is never compiled and/or linked. Could somebody tell me how to add these files to the compile list? Is there an automatic way (if I use the create file option from the menu, it would automatically mark the file to be compiled) for this? Maybe I'm just doing something wrong?

Or maybe I'm just too noob and asking too silly questions. If it is so, please correct me, I'd appreciate any useful input.

Thanks in advance!

--
----Robert Puskas----
-=***@vipmail.hu=-
Sven Brauch
2016-11-25 16:53:01 UTC
Permalink
Hi,
Post by Robert Puskas
After browsing around the project folder created by KDevelop, I
noticed that none of the cmake files contain any entry about my newly
added my.h and my.cpp files, so I suspect my.cpp is never compiled
and/or linked.
That's correct.
Post by Robert Puskas
Could somebody tell me how to add these files to the
compile list?
Just add them to the add_executable() call in CMakeLists.txt, e.g.
something like add_executable(test main.cpp foo.cpp something.cpp)
Post by Robert Puskas
Is there an automatic way (if I use the create file
option from the menu, it would automatically mark the file to be
compiled) for this? Maybe I'm just doing something wrong?
We had this in the past, but had to remove the component which did it
because it was too complicated. Right now, you have to add your source
files by hand to the CMakeLists.txt file. Re-introducing the assistant
doing that automatically would certainly be a nice feature.

Greetings,
Sven

Loading...