Search code examples
visual-studiolinkeropen-sourceprojects-and-solutions

How to integrate projects in Visual Studio


After a few weeks struggle with integrate various projects, I still have no idea how to do it properly.

Note: the hyperlink, which I link for the example below, is the clone address for GIT/SVN

For example, I have Irrlict's demo project, and I wanna play sound in the project, so I choose USE_SDL_MIXER (I define that in Demo project), I clone SDL and SDL Mixer, then I realize that to build SDL Mixer, I have to intergrate SDL to SDL Mixer project - I don't know how. To use USE_SDL_MIXER define in Irrlict's demo, I have to integrate SDL and SDL Mixer to Irrlicht project - I'm so stuck here.

I found the doc of SDL Mixer said in 2.2 Compiling

To link with SDL_mixer you should use sdl-config to get the required SDL compilation options.

And I completely have no ideal what's that is.

In sum, I just want to know how to properly integrate project in Visual Studio - Please tell me in a step-by-step tutorial cause I'm not very smart. And if I create my new project, put in C:\MyProject\MyProject.sln, but the SDK (like Irrlict, SDL, SDL Mixer) put in D:\GitAndSvn\SDK. Do I need to copied these SDK to C:\MyProject so that I can link them?


Solution

  • Project integrate

    Example integrate: SDL, SDL Mixer, Irrlicht’s Demo project (Date clone these projects: 29/07/2017)

    1. Take care of SDL: build SDL

    1.1. Use CMake to generate project, and build project, I assume you know how to do this.

    2. Take care of SDL Mixer: Integrate SDL to SDL Mixer

    2.1. Open file SDL_mixer.sln with Visual Studio (mine is Visual Studio 2015)

    2.2. Set Additional Include Directories for SDL include folder

    Additional Include Directories

    2.2.1. Right click project SDL_mixer and choose Properties (Alt+Enter)

    2.2.2. Choose C/C++ (Note: set Platform to All Platforms)

    2.2.3. Choose Additional Include Directories

    2.2.4. Add SDL include folder for Additional Include Directories (the include folder of SDL project)

    2.2.5. Click Ok… – and now you successfully set Additional Include Directories. By now, the error like: [Cannot open include file: 'SDL_loadso.h': No such file or directory SDL2_mixer] should be gone. Build project SDL2_mixer and you should get the new error: [LNK1104 cannot open file 'SDL2.lib' SDL2_mixer], we gonna fix that in the next step.

    2.3. Set Additional Library Directories for SDL output folder

    Additional Library Directories

    2.3.1. In SDL2_mixer Properties dialog, choose Linker (Note: set Platform to All Platforms)

    2.3.2. Choose Additional Library Directories

    2.3.3. Add SDL output folder for Additional Library Directories (The folder contains the file SDL2.lib after you build the project SDL2)

    2.3.4. Click Ok…

    2.4. Now build other project in SDL_mixer solution (native_midi, timidity), with the experience from step 2.2, 2.3, you can build these projects just fine.

    2.5. Build the project SDL_mixer again, you should build it successfully by now.

    3. Take care of Irrlicht’s Demo project: Integrate SDL and SDL mixer into this Demo project

    3.1. Open BuildAllExamples_vcXX.sln which contains Demo project (I use Visual Studio 2015 so I open the file ..\trunk\examples\BuildAllExamples_vc14.sln)

    3.2. First thing first, build Irrlicht project.

    3.3. Now your purpose is to play some sound in this Demo project, so uncomment the code: #define USE_SDL_MIXER in the file ..\trunk\examples\Demo\CDemo.h

    3.4. Set Additional Include Directories for SDL include folder (refer step 2.2)

    Additional Include Directories for SDL include folder

    3.5. Build Demo project again, you may have the error like [cannot open source file "SDL/SDL.h" Demo], to fix this, in file CDemo.h change [# include and # include ] to [# include "SDL.h" and # include "SDL_mixer.h"]

    3.6. Build Demo project again, you may have the error like [Error C2664 'SDL_RWops *SDL_RWFromFile(const char *,const char *)': cannot convert argument 1 from 'irr::core::string>' to 'const char *' Demo], to fix this, in file CDemo.cpp, change [ballSound = Mix_LoadWAV(mediaPath + "ball.wav"); and impactSound = Mix_LoadWAV(mediaPath + "impact.wav");] to [ballSound = Mix_LoadWAV((mediaPath + "ball.wav").c_str()); and impactSound = Mix_LoadWAV((mediaPath + "impact.wav").c_str());]

    3.7. Build Demo project and you should have the error [Error LNK2019 unresolved external symbol _SDL_RWFromFile referenced in function "private: void __thiscall CDemo::startSound(void)" (?startSound@CDemo@@AAEXXZ) Demo] we fix these error in the next step

    3.8. Set SDL2.lib and SDL2_mixer.lib for Additional Dependencies

    Additional Dependencies

    3.8.1. Choose Linker > Input

    3.8.2. Choose Additional Dependencies

    3.8.3. Add SDL2.lib and SDL2_mixer.lib.

    3.9. Create a folder called SDL_lib, and put the following files into this folder

    • SDL2.lib

    • SDL2_mixer.lib

    3.10. Set Additional Library Directories for the SDL_lib folder you just created above.

    Additional Library Directories for the SDL_lib folder

    3.11. Build the Demo project again, now you should build it successfully.

    3.12. Hit F5 to run the Demo project, you should get the error like: The program can’t start because SDL2.dll is missing …ect… . Just copy the file SDL2.dll and SDL2_mixer.dll into the output directory of Demo project (where the file which is build named Demo.exe located, in my case: ..\trunk\bin\Win32-VisualStudio)

    3.13. Hit F5 again, and enjoy.

    Conclusion:

    In this whole step by step tutorial, you only have to understand the steps: 2.2, 2.3, 3.8. These are the core of this whole thing. So the key words are: Additional Include Directories, Additional Library Directories, Additional Dependencies

    Also, you can check this video if these text above bored you: https://youtu.be/0TlVpiQbFiE (video title SDL 2 Made Easy Tutorial 19 - Mixer [Sound & Music]), the video is not this tutorial, but you can see how to set Additional Library Directories, ect,…

    PS: sorry, I did try to format the answer to make it easier to look at, but this is the best I can format the answer.