在Visual Studio中编译和链接第三方库 [英] Compile and link 3rd party library in Visual Studio

查看:182
本文介绍了在Visual Studio中编译和链接第三方库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C编程非常陌生,并且以前没有使用过Visual Studio或第三方库.我正在尝试使用FMOD做一些简单的事情,需要链接fmodvclibfmod.h,当然还有fmod.dll.

I am fairly new to C programming and I haven't used Visual Studio or a third party library before. I'm trying to do something simple with FMOD and need to link fmodvclib, fmod.h, and of course fmod.dll.

我已经将fmodex_vc.lib放在了其他依赖项中,并在包含和库目录以及其他包含库中提供了低级库的路径,但是在我构建时,它给出了我的答案:

I've put fmodex_vc.lib in the additional dependencies and the path to the low level libraries in the include and library directories as well as additional include libraries but when I build it gives me:

"cannot open source file "fmod.h"
identifier "FSOUND_SAMPLE" is undefined
Cannot open include file: 'fmod.h': No such file or directory

但更奇怪的是:

cannot open source file "stdio.h"

下面是代码:

#include "fmod.h"
#include <stdio.h>

FSOUND_SAMPLE* handle;

int main(void)
{
    int input;

    FSOUND_Init(44100, 32, 0);

    handle = FSOUND_Sample_Load(0, "test.ogg", 0, 0, 0);
    FSOUND_PlaySound(0, handle);

    while (input != 0)
    {
        scanf_s("&d", &input);
    }

    FSOUND_Sample_Free(handle);
    FSOUND_Close();
}

任何帮助将不胜感激!

推荐答案

要链接到第三方库,通常需要做三件事:

To link against third party libraries you usually have to do 3 things:

1.您必须添加包含目录".

Project > Properties > C/C++->General > Additional Include Directories

单击编辑",然后输入文件"fmod.h"所在的目录的路径.

Click Edit, and enter the path to the directory where the file "fmod.h" is located.

2.您必须链接到* .lib文件.

Project > Properties > Linker > General > Additional Library Directories中,单击编辑",然后输入库文件的路径.

In Project > Properties > Linker > General > Additional Library Directories, click Edit and enter the path to your library files.

Project > Properties > Linker > Input > Additional Dependencies中,单击编辑",添加要链接的库的文件名(在这种情况下,很可能是"fmodvc.lib")

In Project > Properties > Linker > Input > Additional Dependencies, click Edit, add the filename of the library you want to link against (in this case this would be most likely "fmodvc.lib")

3.您必须在项目目录中提供* .dll

您的程序将成功运行,必须在运行时找到*.dll文件.您可以将其放置在PATH变量引用的文件夹中,也可以放置在进程的PWD中.这将在您的*.vcxproj文件旁边.

That your programm will run successfully it has to find the *.dll file at runtime. You can either place it in a folder referenced by the PATH variable, or in the PWD of your process. This would be right beside your *.vcxproj files.

如果您是静态链接,则可以跳过第3步;如果动态地加载dll文件,则可以跳过第2步.

If you are linking statically you can skip step 3, if you are loading the dll file dynamically you can skip step 2.

这篇关于在Visual Studio中编译和链接第三方库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆