0

正如标题所说,我正在尝试在我想在 ROS 包中使用的 .cpp 文件中使用一些 C 代码。这是我现在写的代码:

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "../include/heart_rate_monitor/wfdb.h"
#include <stdio.h>
#include <sstream>


int main(int argc, char **argv)
{
    ros::init(argc, argv, "heart");
    ros::NodeHandle n;

    int i;
    WFDB_Sample v[2];
    WFDB_Siginfo s[2];

    if (isigopen("100s", s, 2) < 2)
        exit(1);

    for (i = 0; i < 10; i++) {
        if (getvec(v) < 0)
            break;
        printf("%d\t%d\n", v[0], v[1]);

    }
    exit(0);
    return 0;
}

当我尝试使用 catkin_make 时,我可以在终端中看到一些错误,例如

"heart.cpp:(.text+0xf4): reference not defined on "isigopen".

因为,很明显,系统看不到 wfdb.h C 库,尽管它位于包的 include 文件夹中。也许我必须使用一些代码,比如#ifdef __cplusplusextern C或什么?

如果是这样,我真的不知道如何使用它,因为我是编码方面的超级菜鸟!还有什么我没有考虑过的吗?

先感谢您!

马可

4

2 回答 2

2

您应该在这里查看有关代码混合的更多信息: https ://isocpp.org/wiki/faq/mixing-c-and-cpp

   // C++ code
extern "C" void f(int); // one way
extern "C" {    // another way
    int g(double);
    double h();
};
void code(int i, double d)
{
    f(i);
    int ii = g(d);
    double dd = h();
    // ...
}
于 2016-11-02T15:33:18.843 回答
-1

This sounds like a linker problem, not a compiler problem. Have you included the .lib on your linker line?

于 2016-11-02T15:22:34.523 回答