mac OS X 上的 c 代码编译错误
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 目录下有所有必要的头文件。我用谷歌搜索了很多,这似乎是一个简单的链接问题。我尝试使用 -L 参数进行编译,但我仍然遇到同样的问题。然后我尝试使用 -arch i386 ,但它也不起作用。我也尝试过 clang 作为类似 post 建议之一,但同样的问题。
挣扎了六个小时后,我post来到了这里。
谢谢。
如果你想包含 htslib/sam.h header 你必须查看 /usr/local/include 文件夹,所以添加 -I/usr/local/include 到你的编译器标志。
此外,您还必须将 c 文件的第 2 行更改为:
#include <htslib/sam.h>
Angular 大括号表示在系统目录中搜索 header 文件,而带引号的语法表示在本地路径中搜索。
假设您的 hts 库安装在 /usr/local/lib/ 中,您可以添加 -L/usr/local/lib 标志。
最后使用 libhts 库将 -lhts 标记添加到 link。
gcc -g -Wall -L/usr/local/lib -I/usr/local/lib -lhts test_bam.c -o test_bam
我正在尝试在我的 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 作为类似 post 建议之一,但同样的问题。
挣扎了六个小时后,我post来到了这里。
谢谢。
如果你想包含 htslib/sam.h header 你必须查看 /usr/local/include 文件夹,所以添加 -I/usr/local/include 到你的编译器标志。
此外,您还必须将 c 文件的第 2 行更改为:
#include <htslib/sam.h>
Angular 大括号表示在系统目录中搜索 header 文件,而带引号的语法表示在本地路径中搜索。
假设您的 hts 库安装在 /usr/local/lib/ 中,您可以添加 -L/usr/local/lib 标志。
最后使用 libhts 库将 -lhts 标记添加到 link。
gcc -g -Wall -L/usr/local/lib -I/usr/local/lib -lhts test_bam.c -o test_bam