【发布时间】:2015-03-23 01:42:23
【问题描述】:
我正在尝试在我的 macbook pro(yosmite 10.10.2、Xcode 6.2)上编译一个简单的 c 代码。
#include <stdio.h>
#include "htslib/sam.h"
int main(int argc, char *argv[]){
htsFile *fp_in = NULL;
fp_in = hts_open(argv[1],"r");
if(NULL == fp_in){
printf("can't open file\n");
}
return 0;
}
但是我有编译错误。
gcc -g -Wall -v test_bam.c -o test_bam
Undefined symbols for architecture x86_64:
"_hts_open", referenced from:
_main in test_bam-7d7369.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我在 /usr/local/include 目录下拥有所有必要的头文件。我用谷歌搜索了很多,这似乎是一个简单的链接问题。我尝试使用 -L 参数进行编译,但我仍然遇到同样的问题。然后我尝试了 -arch i386 ,但它也不起作用。我也尝试过 clang 作为建议的类似帖子之一,但同样的问题。
挣扎了六个小时后,我在这里发帖。
谢谢。
【问题讨论】:
-
你应该使用
-l而不是-L。 -
嗨,我也试过
-l,但它说'sam.h' not found!。gcc -g -Wall -L /usr/local/include/htslib/ -lsam test_bam.c -o test_bamtest_bam.c:12:10: fatal error: 'sam.h' file not found #include "sam.h" -
使用
-I包含搜索路径,-L用于库搜索路径,-l用于链接库。
标签: c macos compiler-errors osx-yosemite