[英]c code compilation error on mac OS X
我正在尝试在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目录下有所有必需的头文件。 我已经用Google搜索了很多,这似乎是一个简单的链接问题。 我尝试使用-L参数进行编译,但我仍然遇到相同的问题。 然后,我尝试使用-arch i386,但是它也不起作用。 我也尝试过clang作为类似的帖子之一,但同样的问题。
经过六个小时的奋斗,我在这里张贴。
谢谢。
如果要包含htslib / sam.h标头,则必须查看/ usr / local / include文件夹,因此将-I / usr / local / include添加到编译器标志中。
另外,您还必须将c文件的第2行更改为:
#include <htslib/sam.h>
大括号表示在系统目录中搜索头文件,而带引号的语法表示在本地路径中搜索。
假设您的hts库安装在/ usr / local / lib /中,则可以添加-L / usr / local / lib标志。
最后添加-lhts标志以链接libhts库。
gcc -g -Wall -L/usr/local/lib -I/usr/local/lib -lhts test_bam.c -o test_bam
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.