kdevelop连接麻烦

时间:2012-12-11 20:32:31

标签: linker cmake kdevelop

在向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界面中没有选项来设置应链接的文件。如何解决链接问题?

1 个答案:

答案 0 :(得分:0)

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

add_executable(example main.cpp)

使用:

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

add_executable(example ${MySources})

这应该是它。