简体   繁体   English

将 libsndfile 源代码与 gcc 链接

[英]Link libsndfile source code with gcc

I just cloned libsndfile and created program.c file with the following contents:我刚刚克隆了libsndfile并创建了具有以下内容的 program.c 文件:

#include <stdio.h>
#include <sndfile.h>
main() {
    printf("hello world");
}

My goal is to get this file to compile using gcc (if indeed sndfile.h is the right header to include), however, I am not competent with c code nor the gcc compiler.我的目标是让这个文件使用 gcc 进行编译(如果 sndfile.h 确实是要包含的正确头文件),但是,我不擅长 c 代码,也不擅长 gcc 编译器。

So far I've been referencing the gcc docs and the libsndfile FAQ and haven't been able to come up with a solution.到目前为止,我一直在参考gcc 文档libsndfile 常见问题解答,但一直无法提出解决方案。 I'm not sure if I even have a 'library' yet to feed the gcc -l option .我不确定我是否还有一个“库”来提供 gcc -l 选项 Do I need to go through some sort of build process with the libsndfile source code first or can I 'link' to .c files?我是否需要先使用 libsndfile 源代码进行某种构建过程,还是可以“链接”到 .c 文件?

So far, with program.c and the libsndfile clone directory in the same directory, I've tried the following:到目前为止,在同一目录中的 program.c 和 libsndfile 克隆目录中,我尝试了以下操作:

gcc 'pkg-config --cflags libsndfile' program.c -o hello
gcc 'pkg-config --cflags ./libsndfile/sndfile.pc.in' program.c -o hello

I'm coding on my raspberry pi model B and did not install libsndfile, so, nothing is on my path... maybe I should rename sndfile.pc.in to sndfile.pc and somehow put it on my path?我正在我的树莓派模型 B 上编码并且没有安装 libsndfile,所以,我的路径上没有任何东西......也许我应该将 sndfile.pc.in 重命名为 sndfile.pc 并以某种方式把它放在我的路径上? (not a linux guru either!) (也不是 Linux 大师!)

If there are some resources you think I should study please comment!如果有你认为我应该研究的资源,请评论! I'm perfectly willing to accept answers that simply push me enough to figure things out.我完全愿意接受那些只是促使我弄清楚事情的答案。 Any help would be much appreciated.任何帮助将非常感激。

First make sure you have gcc installed:首先确保你已经安装了gcc

sudo apt-get install gcc

Then, install libsndfile1-dev :然后,安装libsndfile1-dev

sudo apt-get install libsndfile1-dev

I slightly fixed you code to avoid some warnings:我稍微修正了你的代码以避免一些警告:

#include <stdio.h>
#include <sndfile.h>

int main(void) {
  printf("hello world\n");
  return 0;
}

Now you can compile:现在你可以编译:

gcc -o hello program.c

Execution:执行:

bebs@rasp:~$ ./hello                                     
hello world                                                                              
bebs@rasp:~$      

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM