- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
使用 mingw 的 Msys 工具,我已经成功地从 source 1.1.tar.gz 构建了 opus-codec。 .该构建生成了一些文件,其中包括 libopus.a
和 libopus-0.dll
。现在我想试试 trivial-example.c在 QtCreator 中。我将库添加到我的 .pro
文件中,并将 opus.h
包含在我的主文件中。编译器提示它找不到包含在 opus.h
中的 header 这些不应该包含在 lib 中吗?我需要如何设置我的应用程序才能运行“简单示例”?
我的文件夹结构是:
我的.pro
-文件看起来像
QT += core
QT -= gui
TARGET = opus_lib_test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += $$PWD/include
LIBS += -L"C:/Qt/Qt5.2.1/Tools/QtCreator/bin/opus_lib_test/libs/" -llibopus
SOURCES += main.cpp
HEADERS += include/opus.h
我的 main.cpp
在这里:
//#include <QCoreApplication>
#include "opus.h"
int main(int argc, char *argv[])
{
// QCoreApplication a(argc, argv);
// return a.exec();
// ----------------------------- trivial_example.c
char *inFile;
FILE *fin;
char *outFile;
FILE *fout;
opus_int16 in[FRAME_SIZE*CHANNELS];
opus_int16 out[MAX_FRAME_SIZE*CHANNELS];
unsigned char cbits[MAX_PACKET_SIZE];
int nbBytes;
/*Holds the state of the encoder and decoder */
OpusEncoder *encoder;
OpusDecoder *decoder;
int err;
if (argc != 3)
{
fprintf(stderr, "usage: trivial_example input.pcm output.pcm\n");
fprintf(stderr, "input and output are 16-bit little-endian raw files\n");
return EXIT_FAILURE;
}
/*Create a new encoder state */
encoder = opus_encoder_create(SAMPLE_RATE, CHANNELS, APPLICATION, &err);
if (err<0)
{
fprintf(stderr, "failed to create an encoder: %s\n", opus_strerror(err));
return EXIT_FAILURE;
}
/* Set the desired bit-rate. You can also set other parameters if needed.
The Opus library is designed to have good defaults, so only set
parameters you know you need. Doing otherwise is likely to result
in worse quality, but better. */
err = opus_encoder_ctl(encoder, OPUS_SET_BITRATE(BITRATE));
if (err<0)
{
fprintf(stderr, "failed to set bitrate: %s\n", opus_strerror(err));
return EXIT_FAILURE;
}
inFile = argv[1];
fin = fopen(inFile, "r");
if (fin==NULL)
{
fprintf(stderr, "failed to open file: %s\n", strerror(errno));
return EXIT_FAILURE;
}
/* Create a new decoder state. */
decoder = opus_decoder_create(SAMPLE_RATE, CHANNELS, &err);
if (err<0)
{
fprintf(stderr, "failed to create decoder: %s\n", opus_strerror(err));
return EXIT_FAILURE;
}
outFile = argv[2];
fout = fopen(outFile, "w");
if (fout==NULL)
{
fprintf(stderr, "failed to open file: %s\n", strerror(errno));
return EXIT_FAILURE;
}
while (1)
{
int i;
unsigned char pcm_bytes[MAX_FRAME_SIZE*CHANNELS*2];
int frame_size;
/* Read a 16 bits/sample audio frame. */
fread(pcm_bytes, sizeof(short)*CHANNELS, FRAME_SIZE, fin);
if (feof(fin))
break;
/* Convert from little-endian ordering. */
for (i=0;i<CHANNELS*FRAME_SIZE;i++)
in[i]=pcm_bytes[2*i+1]<<8|pcm_bytes[2*i];
/* Encode the frame. */
nbBytes = opus_encode(encoder, in, FRAME_SIZE, cbits, MAX_PACKET_SIZE);
if (nbBytes<0)
{
fprintf(stderr, "encode failed: %s\n", opus_strerror(nbBytes));
return EXIT_FAILURE;
}
/* Decode the data. In this example, frame_size will be constant because
the encoder is using a constant frame size. However, that may not
be the case for all encoders, so the decoder must always check
the frame size returned. */
frame_size = opus_decode(decoder, cbits, nbBytes, out, MAX_FRAME_SIZE, 0);
if (frame_size<0)
{
fprintf(stderr, "decoder failed: %s\n", opus_strerror(err));
return EXIT_FAILURE;
}
/* Convert to little-endian ordering. */
for(i=0;i<CHANNELS*frame_size;i++)
{
pcm_bytes[2*i]=out[i]&0xFF;
pcm_bytes[2*i+1]=(out[i]>>8)&0xFF;
}
/* Write the decoded audio to file. */
fwrite(pcm_bytes, sizeof(short), frame_size*CHANNELS, fout);
}
/*Destroy the encoder state*/
opus_encoder_destroy(encoder);
opus_decoder_destroy(decoder);
fclose(fin);
fclose(fout);
return EXIT_SUCCESS;
}
最佳答案
opus.h
中引用的头文件:
#include "opus_types.h"
#include "opus_defines.h"
它们都来自源包含文件夹,与opus.h
相同。我认为如果您将所有 .h 文件(5 个,包括 opus.h
)从源包含文件夹复制到文件夹结构中的包含 [文件夹],您的问题就会得到解决。
lib中不包含头文件,只包含cpp文件。需要单独指定头文件。
关于c++ - 在 QtCreator 中链接/使用外部库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31342932/
我想给我的一个 friend 一个小项目的发布版本。从 qtcreator 内部启动时它工作得非常好,但在双击 .exe 文件时无法打开。它甚至没有给我错误消息。 现在,当我尝试在我的 exe 文件旁
I have just installed QtCreator 5.0.0. for Windows.我刚刚安装了QtCreator 5.0.0。适用于Windows。 Since I pre
我将在基于子目录模板的 QtCreator 项目中实现以下层次结构: 项目: subproject1 - 静态库 subproject2 - 静态库 subproject3 - 单元测试可执行 唯一的
有没有办法将命令行参数发送到 QtCreator 中正在调试的程序? 最佳答案 进入 QtCreator 左侧的“项目”部分,然后进入“运行设置”选项卡。有一个参数行编辑,您可以在其中放置启动应用程序
QtCreator 资源编辑器自 3.1 版本以来发生了重大变化。新版本在项目树中显示资源文件,我认为这是一个好主意,因为现在无需打开编辑器即可完成大多数操作。 但是这里好像少了点什么。以前的版本在资
我在 Ubuntu 11.10 上安装了 qtcreator sudo apt-get install qtcreator 安装的版本有:QT Creator 2.2.1、QT 4.7.3 当我启动
在 XCode 中要移动选定的 block ,您可以按“Cmd+]”向右和“Cmd+[”向左,QtCreator 中的哪个热键可以做到这一点?在帮助中我没有找到这个函数。 最佳答案 正确答案应该是ta
我想向 QtCreator 添加自定义选项页面。项目向导可以轻松创建通用 QtCreator 插件。但是,如何从那里着手并添加新功能和新小部件?它只是很薄,如果有记录的话。我发现的关于如何编写 QtC
我正在尝试在 Windows 上使用 Qt creator,当我尝试开始调试时,它显示“未设置调试器”。我该如何配置? 最佳答案 这记录在 Setting up the Debugger 上的 Qt
使用带有 CDB 调试器的 Win7 下的 QtCreator 2.8,我在 应用输出 标签我所有的 fprintf(stdout) 东西!? 我试过: fprintf(stderr, "...");
我有一个 Qmake subdirs 项目,在顶级 .pro 文件中,我指定了一个额外的目标,如下所示: gruntbuild.target = gruntbuild gruntbuild.comma
我正在学习在lubuntu 17.10上使用Qtcreator,并希望将一些输出输出到终端。我遇到了麻烦,因此将程序简化为基本的Hello World,以将单个字符串输出到终端。目前,我正在使用以下代
是否可以通过使用“测试” View (例如,点击“运行所有测试”)将googletest可执行文件部署到远程设备? 在我的情况下,应正确配置部署,因为在单击“运行”或“开始调试”后,可执行文件已部署并
我想在我的项目中使用 gcc6,并使用 qtcreator 作为 ide。我的项目使用 cmake。 在“build&run”->“compiler”中,我添加了 g++-6 作为编译器“gcc6”。
我正在尝试使用 gcc 4.7 构建 QtCreator,但出现以下错误: 关键是我卸载了 QtSDK,而是从源代码构建了 Qt(但不是我现在正在做的 QtCreator)。我已经检查了 PATH 变
我的QtCreator找不到我安装的新版本的cmake(我删除了旧的)。 我所能做的就是在 Preferences|Build&Run|CMake 中将 cmake 的路径设置为 /Applicati
我正在尝试添加 OpenXLSX到我的 QtCreator 项目但关注 this guide我似乎无法让 QtCreator 找到头文件。 QtCreator 手册提到了这个库不使用的 .lib 文件
我以前有 Qt 的安装包。/home/star/Downloads/sandeep/Untitled Folder/qt-creator-opensource-linux-x86_64-4.2.1(1
我是 Qt 的新手,对 C++ 也不是很熟悉。 我创建了简单的 Qt GUI 应用程序,但后来我不得不在 QLabel 类型的对象上添加 mousepressevent 函数,所以我创建了具有头文件的
我尝试将目标文件从创建目录复制到我的项目自己的子目录。看起来像 Project/my.pro Project/libs/mylib.so Project/libs/mylibtool.so Proje
我是一名优秀的程序员,十分优秀!