1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
最近在做语音识别相关,发现这个领域大部分代码都是C++和C都混编都工程,研究了下混编方式,写下记录过程
cust@virtualbox:~/alsa_test$ ls alsa libasound.so libasound.so.2 libasound.so.2.0.0 main.cpp Makefile test_one.c test_one.h main文件使用cpp结尾,test_one采用c结尾,如何混编呢?很简单,增加头文件,并在头文件里用一个宏!! test_one.h内容 #ifndef __TEST_ONE_H__ #define __TEST_ONE_H__ #ifdef __cplusplus extern "C" { #endif extern int test_one(); #ifdef __cplusplus } #endif #endif main.cpp内容 #include #include #include #include "alsa/asoundlib.h" #include "test_one.h" int main(int argc, char *argv[]) { test_one(); } Makefile内容 PROJECT_DIR := $(shell pwd) TARGET = test CC := /mcuzone/work/buildroot/output/rockchip_rk3308_release/host/usr/bin/aarch64-rockchip-linux-gnu-gcc CXX := /mcuzone/work/buildroot/output/rockchip_rk3308_release/host/usr/bin/aarch64-rockchip-linux-gnu-g++ LD := /mcuzone/work/buildroot/output/rockchip_rk3308_release/host/usr/bin/aarch64-rockchip-linux-gnu-ld LIBS := -ldl -lpthread -lasound DEFINES := -fpic INCLUDE := -I$(PROJECT_DIR) CFLAGS := -g -Wall -O3 $(DEFINES) $(INCLUDE) CXXFLAGS:= $(CFLAGS) LDFLAGS := -L$(PROJECT_DIR) # source file SOURCE := $(wildcard ./*.c) $(wildcard ./*.cpp) OBJS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE))) $(TARGET) : $(OBJS) $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS) .PHONY : clean all : $(TARGET) clean : rm -rf ./*.o rm $(TARGET) test_one.c内容 #include int test_one() { int val; printf("ALSA library version: %sn", SND_LIB_VERSION_STR); printf("nPCM stream types:n"); for (val = 0; val <= SND_PCM_STREAM_LAST; val++) printf(" %sn", snd_pcm_stream_name((snd_pcm_stream_t)val)); printf("nPCM access types:n"); for (val = 0; val <= SND_PCM_ACCESS_LAST; val++) printf(" %sn", snd_pcm_access_name((snd_pcm_access_t)val)); printf("nPCM formats:n"); for (val = 0; val <= SND_PCM_FORMAT_LAST; val++) if (snd_pcm_format_name((snd_pcm_format_t)val) != NULL) printf(" %s (%s)n", snd_pcm_format_name((snd_pcm_format_t)val), snd_pcm_format_description( (snd_pcm_format_t)val)); printf("nPCM subformats:n"); for (val = 0; val <= SND_PCM_SUBFORMAT_LAST; val++) printf(" %s (%s)n", snd_pcm_subformat_name(( snd_pcm_subformat_t)val), snd_pcm_subformat_description(( snd_pcm_subformat_t)val)); printf("nPCM states:n"); for (val = 0; val <= SND_PCM_STATE_LAST; val++) printf(" %sn", snd_pcm_state_name((snd_pcm_state_t)val)); return 0; } 编译结果 cust@virtualbox:~/alsa_test$ make /mcuzone/work/buildroot/output/rockchip_rk3308_release/host/usr/bin/aarch64-rockchip-linux-gnu-gcc -g -Wall -O3 -fpic -I/home/cust/alsa_test -c -o test_one.o test_one.c /mcuzone/work/buildroot/output/rockchip_rk3308_release/host/usr/bin/aarch64-rockchip-linux-gnu-g++ -g -Wall -O3 -fpic -I/home/cust/alsa_test -c -o main.o main.cpp /mcuzone/work/buildroot/output/rockchip_rk3308_release/host/usr/bin/aarch64-rockchip-linux-gnu-g++ -g -Wall -O3 -fpic -I/home/cust/alsa_test -o test ./test_one.o ./main.o -L/home/cust/alsa_test -ldl -lpthread -lasound 板子上运行结果 /oem # ./test ALSA library version: 1.1.5 PCM stream types: PLAYBACK CAPTURE PCM access types: MMAP_INTERLEAVED MMAP_NONINTERLEAVED MMAP_COMPLEX RW_INTERLEAVED RW_NONINTERLEAVED PCM formats: S8 (Signed 8 bit) U8 (Unsigned 8 bit) S16_LE (Signed 16 bit Little Endian) S16_BE (Signed 16 bit Big Endian) U16_LE (Unsigned 16 bit Little Endian) U16_BE (Unsigned 16 bit Big Endian) S24_LE (Signed 24 bit Little Endian) S24_BE (Signed 24 bit Big Endian) U24_LE (Unsigned 24 bit Little Endian) U24_BE (Unsigned 24 bit Big Endian) S32_LE (Signed 32 bit Little Endian) S32_BE (Signed 32 bit Big Endian) U32_LE (Unsigned 32 bit Little Endian) U32_BE (Unsigned 32 bit Big Endian) FLOAT_LE (Float 32 bit Little Endian) FLOAT_BE (Float 32 bit Big Endian) FLOAT64_LE (Float 64 bit Little Endian) FLOAT64_BE (Float 64 bit Big Endian) IEC958_SUBFRAME_LE (IEC-958 Little Endian) IEC958_SUBFRAME_BE (IEC-958 Big Endian) MU_LAW (Mu-Law) A_LAW (A-Law) IMA_ADPCM (Ima-ADPCM) MPEG (MPEG) GSM (GSM) SPECIAL (Special) S24_3LE (Signed 24 bit Little Endian in 3bytes) S24_3BE (Signed 24 bit Big Endian in 3bytes) U24_3LE (Unsigned 24 bit Little Endian in 3bytes) U24_3BE (Unsigned 24 bit Big Endian in 3bytes) S20_3LE (Signed 20 bit Little Endian in 3bytes) S20_3BE (Signed 20 bit Big Endian in 3bytes) U20_3LE (Unsigned 20 bit Little Endian in 3bytes) U20_3BE (Unsigned 20 bit Big Endian in 3bytes) S18_3LE (Signed 18 bit Little Endian in 3bytes) S18_3BE (Signed 18 bit Big Endian in 3bytes) U18_3LE (Unsigned 18 bit Little Endian in 3bytes) U18_3BE (Unsigned 18 bit Big Endian in 3bytes) G723_24 (G.723 (ADPCM) 24 kbit/s, 8 samples in 3 bytes) G723_24_1B (G.723 (ADPCM) 24 kbit/s, 1 sample in 1 byte) G723_40 (G.723 (ADPCM) 40 kbit/s, 8 samples in 3 bytes) G723_40_1B (G.723 (ADPCM) 40 kbit/s, 1 sample in 1 byte) DSD_U8 (Direct Stream Digital, 1-byte (x8), oldest bit in MSB) DSD_U16_LE (Direct Stream Digital, 2-byte (x16), little endian, oldest bits in MSB) DSD_U32_LE (Direct Stream Digital, 4-byte (x32), little endian, oldest bits in MSB) DSD_U16_BE (Direct Stream Digital, 2-byte (x16), big endian, oldest bits in MSB) DSD_U32_BE (Direct Stream Digital, 4-byte (x32), big endian, oldest bits in MSB) PCM subformats: STD (Standard) PCM states: OPEN SETUP PREPARED RUNNING XRUN DRAINING PAUSED SUSPENDED DISCONNECTED 以上,混编还是很方便的。 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
基于米尔瑞芯微RK3576核心板/开发板的人脸疲劳检测应用方案
606 浏览 0 评论
870 浏览 1 评论
768 浏览 1 评论
1984 浏览 1 评论
3230 浏览 1 评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 13:15 , Processed in 0.445073 second(s), Total 44, Slave 36 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号