从C ++调用带有外部“ C”的C函数时未定义的符号已经覆盖了C头文件

我在下面的C ++代码中使用了一个文件C库cute_c2.h

#include <iostream>

extern "C" {
    #include "cute_c2.h"
}

int main(int argc,const char * argv[]) {
    // insert code here...
    std::cout << "Hello,World!\n";

    c2v p1;   // c2v is a struct defined in cute_c2.h which only has two variable x and y
    p1.x = 0;
    p1.y = 0;

    c2v p2;
    p2.x = 10;
    p2.y = 10;

    c2AABB aabb;  // c2v is also a struct defined in cute_c2.h which only has two c2v max and min
    aabb.max = p2;
    aabb.min = p1;

    int result = c2AABBtoAABB(aabb,aabb);  // error from this line of code

    return 0;
}

我在Mac OS Catalina中并使用Xcode 11.2

错误是

Undefined symbols for architecture x86_64:
  "_c2AABBtoAABB",referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

当我删除extern "C"时,错误是

Undefined symbols for architecture x86_64:
  "c2AABBtoAABB(c2AABB,c2AABB)",referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

任何想法如何解决这个问题?我是C ++的新手,这个问题使我发疯。

GGsnake 回答:从C ++调用带有外部“ C”的C函数时未定义的符号已经覆盖了C头文件

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3132538.html

大家都在问