12

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.

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

but even weirder is:

cannot open source file "stdio.h"

here is the code:

#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();
}

Any help would be appreciated!

jww
  • 97,681
  • 90
  • 411
  • 885
user5840403
  • 121
  • 1
  • 1
  • 4
  • When you add the path of header files to INCLUDE_PATH, you must use #include instead of #include "filename". double qoutations must be used for header files that are in the project directory. – payman Jan 26 '16 at 07:24
  • @payman Alright I tried that and got the same errors – user5840403 Jan 26 '16 at 07:34
  • 1
    Possible duplicate of [How to add additional libraries to Visual Studio project?](https://stackoverflow.com/q/4445418/608639), [Compiling and linking third party libraries in VS 2015](https://stackoverflow.com/q/31030556/608639), etc. – jww Mar 02 '19 at 06:48

1 Answers1

29

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

1. You have to add the Include Directory.

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

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

2. You have to link against the *.lib file.

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

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. You have to provide the *.dll in your project directory

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.

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

EGOrecords
  • 1,959
  • 2
  • 19
  • 33
  • Thanks for this nice answer. Is there a way in VS2017 to add a runtime directory in the project options to find dlls ? Something like `./bin` or an entirely different directory such as `C:/SomeSDK/bin` ? Basically to avoid copying all dlls. Thanks. – PinkTurtle May 26 '18 at 08:49
  • VS2017 has no Project > Properties > Linker – user2445507 Jul 28 '19 at 18:22