windows 调用 static lib

1.生成静态 lib

头文件,mylib.h

//mylib.h

#pragma once
int add(int x, int y);

源文件,mylib.cpp

#include "myLib.h"


int add(int x, int y)
{
	return  x + y;
}

vs2019 工程配置:

 

 

2.在mfc中引用 lib

在工程目录里建立连个目录,lib:放lib文件;libhead:放lib头文件

代码里引用头文件和lib库就可以使用lib里的函数了。

#include "libhead/myLib.h"

#pragma comment(lib,"lib/lib1.lib")

常见问题:

  • error LNK2019: 无法解析的外部符号 "int __cdecl add(int,int)"        

        忘记引用lib库文件,或者引用的路径不对找不到lib库文件

下次写一下,windows调用DLL处理方式。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
PCM(Pulse-code modulation)是一种数字音频编码方式,常用于音频采集和存储。在Android系统中,有两种主要的PCM编解码库:pcm_native和pcm_lib。pcm_native是使用Android底层C++代码实现的PCM编解码库,而pcm_lib则是使用Java编写的PCM编解码库。 以下是一个使用pcm_native进行PCM编解码的示例代码: ```c++ #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <errno.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/ioctl.h> #include <linux/ioctl.h> #include <linux/soundcard.h> #define DEFAULT_RATE 44100 #define DEFAULT_CHANNELS 2 #define DEFAULT_FORMAT AFMT_S16_LE int main(int argc, char *argv[]) { int fd; int format = DEFAULT_FORMAT; int rate = DEFAULT_RATE; int channels = DEFAULT_CHANNELS; int bytes_per_sample; int frames_per_buffer; char *buffer; int size; int result; int i; // 打开PCM设备 fd = open("/dev/dsp", O_RDWR); if (fd < 0) { fprintf(stderr, "Failed to open /dev/dsp: %s\n", strerror(errno)); exit(EXIT_FAILURE); } // 设置PCM参数 result = ioctl(fd, SNDCTL_DSP_SETFMT, &format); if (result < 0) { fprintf(stderr, "Failed to set format: %s\n", strerror(errno)); exit(EXIT_FAILURE); } result = ioctl(fd, SNDCTL_DSP_SPEED, &rate); if (result < 0) { fprintf(stderr, "Failed to set rate: %s\n", strerror(errno)); exit(EXIT_FAILURE); } result = ioctl(fd, SNDCTL_DSP_CHANNELS, &channels); if (result < 0) { fprintf(stderr, "Failed to set channels: %s\n", strerror(errno)); exit(EXIT_FAILURE); } // 计算每个采样的字节数和每个缓冲区中的采样数 bytes_per_sample = (format & 0xff) / 8; frames_per_buffer = 1024 / bytes_per_sample; size = frames_per_buffer * channels * bytes_per_sample; buffer = (char *) malloc(size); // 从标准输入读取PCM数据并写入PCM设备 while ((result = read(STDIN_FILENO, buffer, size)) > 0) { result = write(fd, buffer, result); if (result < 0) { fprintf(stderr, "Failed to write PCM data: %s\n", strerror(errno)); exit(EXIT_FAILURE); } } // 关闭PCM设备 close(fd); return 0; } ``` 以上代码中,我们使用ioctl函数来设置PCM设备的参数,并使用read函数从标准输入读取PCM数据,使用write函数将PCM数据写入PCM设备。 以下是一个使用pcm_lib进行PCM编解码的示例代码: ```java import android.media.AudioFormat; import android.media.AudioRecord; import android.media.MediaRecorder; import android.media.AudioTrack; public class PCMExample { private static final int SAMPLE_RATE = 44100; private static final int CHANNEL_CONFIG = AudioFormat.CHANNEL_IN_STEREO; private static final int AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT; public static void main(String[] args) { int bufferSize = AudioRecord.getMinBufferSize(SAMPLE_RATE, CHANNEL_CONFIG, AUDIO_FORMAT); byte[] buffer = new byte[bufferSize]; AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, SAMPLE_RATE, CHANNEL_CONFIG, AUDIO_FORMAT, bufferSize); AudioTrack player = new AudioTrack(AudioManager.STREAM_MUSIC, SAMPLE_RATE, AudioFormat.CHANNEL_OUT_STEREO, AUDIO_FORMAT, bufferSize, AudioTrack.MODE_STREAM); recorder.startRecording(); player.play(); while (true) { int bytesRead = recorder.read(buffer, 0, bufferSize); player.write(buffer, 0, bytesRead); } } } ``` 以上代码中,我们使用AudioRecord类从麦克风读取PCM数据,并使用AudioTrack类播放PCM数据。需要注意的是,以上代码只是一个简单的示例,实际应用中应该在合适的地方添加必要的异常处理和资源释放代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿土有品

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值