我正在尝试将C和C ++代码结合起来,但是当我尝试链接时,我遇到了意外错误:
ld:警告:忽略文件edmonds.o,文件是为不支持的文件格式(0x43 0x50 0x43 0x48 0x01 0x0C 0x00 0x00 0x64 0x08 0x00 0x00 0x00B 0x02 0x60 0x42)构建的,这不是被链接的体系结构(x86_64)
这是我的设置:
dummy.c
void edmonds(int n, double* weights, int* heads);
int main()
{
int a = 1;
edmonds(1234,0,&a);
return 0;
}
edmonds.hpp:
extern "C" void edmonds(int n, double* weights, int* heads);
void edmonds(int n, double* weights, int* heads)
{
heads[0]=n*4;
return;
}
我使用以下命令序列手动编译:
clang -c dummy.c -o dummy.o
clang++ -c edmonds.hpp -o edmonds.o
clang++ edmonds.o dummy.o -o main.o
带有上述结果
ld: warning: ignoring file edmonds.o, file was built for unsupported file format ( 0x43 0x50 0x43 0x48 0x01 0x0C 0x00 0x00 0x64 0x08 0x00 0x00 0x0B 0x02 0x68 0x42 ) which is not the architecture being linked (x86_64): edmonds.o
Undefined symbols for architecture x86_64:
"_edmonds", referenced from:
_main in dummy.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我的系统是osx yosemite。我不明白为什么edmonds.hpp被编译成一些非x86_64的奇怪文件格式。