0

将新类添加到 KDevelop C++ 项目后,链接器无法找到确切的源(在本例中为 calculation.cpp):

-- 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 ***

kdevelop 界面中没有选项来设置应该链接或不链接的文件。如何解决链接问题?

4

1 回答 1

0

需要在 CMakeLists.txt 文件中将源文件添加到您的项目中。代替:

add_executable(example main.cpp)

和:

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

add_executable(example ${MySources})

这应该是它。

于 2012-12-11T20:32:31.043 回答