【问题标题】:Undefined reference in KdevelopKdevelop 中未定义的引用
【发布时间】:2014-10-07 04:38:02
【问题描述】:

我有 main.cpp,从 io.c 链接测试函数

#include <iostream>
#include "io.h"

int main(int argc, char **argv) {
    test();
    return 0;
}

io.c:

#include <stdio.h>
#include "io.h"

void test() {
printf("hee");
}

我将 CMakeLists.txt 配置如下:

project(test)
set(MyProjectSources io.c io.h main.cpp )
add_executable(test ${MyProjectSources})

但是,当我构建项目时,出现未定义引用的错误。 请帮我。

PS:如果 main.cpp 引用了 l1.h 和 l2.h 等 2 个库。如何将这些链接到 main.cpp?

【问题讨论】:

  • 如果不发布实际错误,我们无能为力。另外:您可能不想将 io.h(头文件!)添加到源列表中。

标签: reference ubuntu-12.04 undefined-reference kdevelop printf-debugging


【解决方案1】:

您应该提供错误。不过,您似乎缺少链接到某些库。

还要注意这是一个 CMake 问题,而不是 KDevelop 的问题。如果你研究 cmake,你可能会发现更多的文献。

【讨论】:

    猜你喜欢
    • 2011-06-20
    • 1970-01-01
    • 2012-06-29
    • 2011-07-14
    • 2018-09-01
    • 2012-09-01
    • 2015-10-14
    • 2015-12-05
    相关资源
    最近更新 更多