Question

After adding a new class to a KDevelop C++ project, linker has a problem to find exact sources (calculation.cpp in this case):

-- Build files have been written to: /var/www/C++/fibonacci/build
Scanning dependencies of target fibonacci
Linking CXX executable fibonacci
CMakeFiles/fibonacci.dir/main.cpp.o: In function `main':
/var/www/C++/fibonacci/main.cpp:12: undefined reference to `Calculation::fibonacci(unsigned int)'
/var/www/C++/fibonacci/main.cpp:13: undefined reference to `Calculation::fibonacci_req(unsigned int, unsigned int, unsigned int)'
collect2: ld returned 1 exit status
make[2]: *** [fibonacci] Error 1
make[1]: *** [CMakeFiles/fibonacci.dir/all] Error 2
make: *** [all] Error 2
*** Failed ***

There is no option in kdevelop interface to set files that should be linked or not. How to solve the linking problem?

Was it helpful?

Solution

Need to add the source files to your project in the CMakeLists.txt file. Replace:

add_executable(example main.cpp)

with:

set(MySources main.cpp calculation.h calculation.cpp)

add_executable(example ${MySources})

and this should be it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top