无法在cygwin中编译linux C程序

时间:2018-07-16 05:22:17

标签: c linux audio cygwin pulseaudio

我试图在Cygwin中为Linux编译一个名为minimodem的程序,因为我希望能够在Windows中运行它。这是一个简单的命令行程序,我安装了Cygwin,基本上使用了所有必需的库来进行编译。

其中一些库是:已安装所有音频,视频,数学,编译,开发,api以及系统和基础。

我遇到的第一个问题是./configure。从github中项目的源代码来看,没有配置文件或文件夹。我决定放弃它,而是直接使用make并引用该文件夹中的所有文件。

首先发生的事情是我遇到了这个错误:

  

minimodem.c:在“ main”函数中:minimodem.c:556:4:错误:#error   必须启用{USE_PULSEAUDIO,USE_ALSA,USE_SNDFILE}中的至少一个! #   错误必须至少为{USE_PULSEAUDIO,USE_ALSA,USE_SNDFILE}中的一个   启用!       ^ ~~~~

所以我进入代码并删除了检查音频驱动程序的部分(即使Cygwin有可用的所有音频库),我还是再次尝试了:

  

gcc -o minimodem.c

然后编译器走得更远 然后给出此错误:

/tmp/cc5sSG5R.o: In function `fsk_transmit_frame':
/home/8bit_coder/minimodem-master/src/minimodem.c:95: undefined reference to `simpleaudio_tone'
/home/8bit_coder/minimodem-master/src/minimodem.c:95:(.text+0xb9): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `simpleaudio_tone'
/home/8bit_coder/minimodem-master/src/minimodem.c:106: undefined reference to `simpleaudio_tone'
/home/8bit_coder/minimodem-master/src/minimodem.c:106:(.text+0xf2): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `simpleaudio_tone'
/tmp/cc5sSG5R.o: In function `tx_stop_transmit_sighandler':
/home/8bit_coder/minimodem-master/src/minimodem.c:65: undefined reference to `simpleaudio_tone'
/home/8bit_coder/minimodem-master/src/minimodem.c:65:(.text+0x27f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `simpleaudio_tone'
/home/8bit_coder/minimodem-master/src/minimodem.c:68: undefined reference to `simpleaudio_tone'
/home/8bit_coder/minimodem-master/src/minimodem.c:68:(.text+0x2ec): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `simpleaudio_tone'
/tmp/cc5sSG5R.o: In function `generate_test_tones':
/home/8bit_coder/minimodem-master/src/minimodem.c:295: undefined reference to `simpleaudio_get_rate'
/home/8bit_coder/minimodem-master/src/minimodem.c:295:(.text+0x59d): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `simpleaudio_get_rate'
/home/8bit_coder/minimodem-master/src/minimodem.c:299: undefined reference to `simpleaudio_tone'
/home/8bit_coder/minimodem-master/src/minimodem.c:299:(.text+0x5dd): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `simpleaudio_tone'
/home/8bit_coder/minimodem-master/src/minimodem.c:300: undefined reference to `simpleaudio_tone'
/home/8bit_coder/minimodem-master/src/minimodem.c:300:(.text+0x5eb): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `simpleaudio_tone'
/tmp/cc5sSG5R.o: In function `fsk_transmit_frame':
/home/8bit_coder/minimodem-master/src/minimodem.c:109: undefined reference to `simpleaudio_tone'
/home/8bit_coder/minimodem-master/src/minimodem.c:109:(.text+0x170): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `simpleaudio_tone'
/tmp/cc5sSG5R.o: In function `main':
/home/8bit_coder/minimodem-master/src/minimodem.c:751: undefined reference to `databits_decode_ascii8'
/home/8bit_coder/minimodem-master/src/minimodem.c:751:(.text.startup+0xa6): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `databits_decode_ascii8'
/home/8bit_coder/minimodem-master/src/minimodem.c:751: undefined reference to `databits_encode_ascii8'
/home/8bit_coder/minimodem-master/src/minimodem.c:751:(.text.startup+0xc6): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `databits_encode_ascii8'
/tmp/cc5sSG5R.o: In function `benchmarks':
/home/8bit_coder/minimodem-master/src/minimodem.c:324: undefined reference to `simpleaudio_tone_init'
/home/8bit_coder/minimodem-master/src/minimodem.c:324:(.text.startup+0x2b3): additional relocation overflows omitted from the output
/home/8bit_coder/minimodem-master/src/minimodem.c:326: undefined reference to `simpleaudio_open_stream'
/home/8bit_coder/minimodem-master/src/minimodem.c:332: undefined reference to `simpleaudio_close'
/home/8bit_coder/minimodem-master/src/minimodem.c:334: undefined reference to `simpleaudio_open_stream'
/home/8bit_coder/minimodem-master/src/minimodem.c:340: undefined reference to `simpleaudio_close'
/home/8bit_coder/minimodem-master/src/minimodem.c:344: undefined reference to `simpleaudio_tone_init'
/home/8bit_coder/minimodem-master/src/minimodem.c:346: undefined reference to `simpleaudio_open_stream'
/home/8bit_coder/minimodem-master/src/minimodem.c:352: undefined reference to `simpleaudio_close'
/home/8bit_coder/minimodem-master/src/minimodem.c:354: undefined reference to `simpleaudio_open_stream'
/home/8bit_coder/minimodem-master/src/minimodem.c:360: undefined reference to `simpleaudio_close'
/tmp/cc5sSG5R.o: In function `main':
/home/8bit_coder/minimodem-master/src/minimodem.c:665: undefined reference to `databits_decode_baudot'
/home/8bit_coder/minimodem-master/src/minimodem.c:666: undefined reference to `baudot_encode'
/home/8bit_coder/minimodem-master/src/minimodem.c:797: undefined reference to `databits_decode_baudot'
/home/8bit_coder/minimodem-master/src/minimodem.c:798: undefined reference to `baudot_encode'
/home/8bit_coder/minimodem-master/src/minimodem.c:864: undefined reference to `databits_decode_binary'
/home/8bit_coder/minimodem-master/src/minimodem.c:945: undefined reference to `simpleaudio_tone_init'
/home/8bit_coder/minimodem-master/src/minimodem.c:954: undefined reference to `simpleaudio_open_stream'
/tmp/cc5sSG5R.o: In function `fsk_transmit_stdin':
/home/8bit_coder/minimodem-master/src/minimodem.c:130: undefined reference to `simpleaudio_get_rate'
/tmp/cc5sSG5R.o: In function `main':
/home/8bit_coder/minimodem-master/src/minimodem.c:975: undefined reference to `simpleaudio_close'
/home/8bit_coder/minimodem-master/src/minimodem.c:805: undefined reference to `databits_decode_baudot'
/home/8bit_coder/minimodem-master/src/minimodem.c:806: undefined reference to `baudot_encode'
/home/8bit_coder/minimodem-master/src/minimodem.c:988: undefined reference to `simpleaudio_open_stream'
/home/8bit_coder/minimodem-master/src/minimodem.c:995: undefined reference to `simpleaudio_get_rate'
/home/8bit_coder/minimodem-master/src/minimodem.c:1011: undefined reference to `fsk_plan_new'
/home/8bit_coder/minimodem-master/src/minimodem.c:1232: undefined reference to `fsk_find_frame'
/home/8bit_coder/minimodem-master/src/minimodem.c:1443: undefined reference to `simpleaudio_close'
/home/8bit_coder/minimodem-master/src/minimodem.c:1445: undefined reference to `fsk_plan_destroy'
/home/8bit_coder/minimodem-master/src/minimodem.c:833: undefined reference to `databits_decode_callerid'
/home/8bit_coder/minimodem-master/src/minimodem.c:998: undefined reference to `simpleaudio_set_rxnoise'
/tmp/cc5sSG5R.o: In function `fsk_transmit_stdin':
/home/8bit_coder/minimodem-master/src/minimodem.c:211: undefined reference to `simpleaudio_tone'
/home/8bit_coder/minimodem-master/src/minimodem.c:233: undefined reference to `simpleaudio_tone'
/tmp/cc5sSG5R.o: In function `main':
/home/8bit_coder/minimodem-master/src/minimodem.c:1132: undefined reference to `simpleaudio_read'
/home/8bit_coder/minimodem-master/src/minimodem.c:1340: undefined reference to `fsk_find_frame'
/home/8bit_coder/minimodem-master/src/minimodem.c:1155: undefined reference to `fsk_detect_carrier'
/home/8bit_coder/minimodem-master/src/minimodem.c:1186: undefined reference to `fsk_set_tones_by_bandshift'
/home/8bit_coder/minimodem-master/src/minimodem.c:845: undefined reference to `databits_decode_uic_ground'
/home/8bit_coder/minimodem-master/src/minimodem.c:833: undefined reference to `databits_decode_callerid'
/home/8bit_coder/minimodem-master/src/minimodem.c:843: undefined reference to `databits_decode_uic_train'
/tmp/cc5sSG5R.o:minimodem.c:(.rdata$.refptr.databits_decode_binary[.refptr.databits_decode_binary]+0x0): undefined reference to `databits_decode_binary'
/tmp/cc5sSG5R.o:minimodem.c:(.rdata$.refptr.databits_decode_uic_train[.refptr.databits_decode_uic_train]+0x0): undefined reference to `databits_decode_uic_train'
/tmp/cc5sSG5R.o:minimodem.c:(.rdata$.refptr.databits_decode_uic_ground[.refptr.databits_decode_uic_ground]+0x0): undefined reference to `databits_decode_uic_ground'
/tmp/cc5sSG5R.o:minimodem.c:(.rdata$.refptr.databits_decode_callerid[.refptr.databits_decode_callerid]+0x0): undefined reference to `databits_decode_callerid'
/tmp/cc5sSG5R.o:minimodem.c:(.rdata$.refptr.databits_encode_ascii8[.refptr.databits_encode_ascii8]+0x0): undefined reference to `databits_encode_ascii8'
/tmp/cc5sSG5R.o:minimodem.c:(.rdata$.refptr.databits_decode_ascii8[.refptr.databits_decode_ascii8]+0x0): undefined reference to `databits_decode_ascii8'
/tmp/cc5sSG5R.o:minimodem.c:(.rdata$.refptr.baudot_encode[.refptr.baudot_encode]+0x0): undefined reference to `baudot_encode'
/tmp/cc5sSG5R.o:minimodem.c:(.rdata$.refptr.databits_decode_baudot[.refptr.databits_decode_baudot]+0x0): undefined reference to `databits_decode_baudot'
collect2: error: ld returned 1 exit status

然后我想也许我需要列出每个文件:

  

gcc -o baudot.c baudot.h databits.h databits_ascii.c databits_baudot.c   databits_binary.c databits_callerid.c databits_uic.c fsk.c fsk.h   minimodem.c simpleaudio.c simpleaudio.h simpleaudio_internal.h   simpleaudio-alsa.c simpleaudio-benchmark.c simpleaudio-pulse.c   simpleaudio-sndfile.c simple-tone-generator.c uic_codes.c uic_codes.h

但这带来了许多不同的错误:

/tmp/ccmwpyzy.o:databits_baudot.c:(.text+0x1f): undefined reference to `baudot_reset'
/tmp/ccmwpyzy.o:databits_baudot.c:(.text+0x1f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `baudot_reset'
/tmp/ccmwpyzy.o:databits_baudot.c:(.text+0x3d): undefined reference to `baudot_decode'
/tmp/ccmwpyzy.o:databits_baudot.c:(.text+0x3d): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `baudot_decode'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x1b8): undefined reference to `fftwf_malloc'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x1b8): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `fftwf_malloc'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x208): undefined reference to `fftwf_malloc'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x208): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `fftwf_malloc'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x281): undefined reference to `fftwf_plan_many_dft_r2c'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x281): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `fftwf_plan_many_dft_r2c'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x2cc): undefined reference to `fftwf_free'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x2cc): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `fftwf_free'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x2dc): undefined reference to `fftwf_free'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x2dc): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `fftwf_free'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x323): undefined reference to `fftwf_free'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x323): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `fftwf_free'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x333): undefined reference to `fftwf_free'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x333): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `fftwf_free'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x343): undefined reference to `fftwf_destroy_plan'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x343): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `fftwf_destroy_plan'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x454): undefined reference to `fftwf_execute'
/tmp/cc6Uh66Z.o:fsk.c:(.text+0x454): additional relocation overflows omitted from the output
/tmp/cc6Uh66Z.o:fsk.c:(.text+0xda7): undefined reference to `fftwf_execute'
/tmp/ccmR4Dzs.o:minimodem.c:(.rdata$.refptr.baudot_encode[.refptr.baudot_encode]+0x0): undefined reference to `baudot_encode'
/tmp/ccBHdt9j.o:simpleaudio.c:(.rdata$.refptr.simpleaudio_backend_alsa[.refptr.simpleaudio_backend_alsa]+0x0): undefined reference to `simpleaudio_backend_alsa'
/tmp/ccBHdt9j.o:simpleaudio.c:(.rdata$.refptr.simpleaudio_backend_pulseaudio[.refptr.simpleaudio_backend_pulseaudio]+0x0): undefined reference to `simpleaudio_backend_pulseaudio'
collect2: error: ld returned 1 exit status

在这一点上我不知道该怎么办,因为它可以很好地编译并可以在Linux上运行,但是使用Cygwin在Windows上进行编译可以做到这一点。如果有人对我做错了什么或如何修复命令或文件有任何想法,谢谢。

1 个答案:

答案 0 :(得分:2)

如@Sami Kuhmonen在对您的问题的评论中所述:

  

并非所有代码都可以在不同的系统上编译。如果代码   需要特定的音频系统,可能无法使用

在这种情况下,它尝试使用三个库,但在以下位置失败:

  • PulseAudio:适用于POSIX操作系统的声音系统(不是Windows,但已在Windows 2000和Windows XP上进行了测试),因此,我认为Windows支持的充其量将非常有限。
  • ALSA:以其名称Advanced Linux Sound Architecture(可能不是Windows正确吗?)表示,这是Linux专用代码,用于与Linux平台上的声卡驱动程序进行通信。
  • libsndfile:它在网站上说它已经预编译了适用于Win32和Win64 OS的二进制文件,但看起来并不像最初设计时考虑到的Windows

总而言之,像这样的音频代码可能正试图与仅针对基于Linux的系统(Linux vs Windows Audio in 2017)设计的特定驱动程序进行通信。尽管C可以在不同的操作系统之间移植,但是在您用来编译程序的库中编写的代码很可能不会。

我敢肯定,您必须编辑(移植)源代码才能使用更多相关的Windows音频编程。

注意:

由于@matzeri的评论,实际上Cygwin上有一个libsndfile软件包。参见link here