Can't play audio with STATIC linked SFML - c++

I am making a simple Pong game and after finishing the game I tried to add a sound effect for the ball collision but the compiler would not compile the code and send some errors I made sure that openal32 is linked and the .dll is in the directory of the project. So I would write the whole game without a problem and as soon as I include
buf.loadFromFile("data\pong.wav");
Sound sound;
sound.setBuffer(buf);
The compiler won't even start the game and would give me those errors,I am using SFML 2.5.1 after compiling it for visual studio 2019 that I am using.
1>------ Build started: Project: Project1, Configuration: Debug x64 ------
1>Source.cpp
1>C:\Users\Ahmad.T\source\repos\Project1\Project1\Source.cpp(69,19): warning C4129: 'p': unrecognized character escape sequence
1>C:\Users\Ahmad.T\source\repos\Project1\Project1\Source.cpp(133,19): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
1>C:\Users\Ahmad.T\source\repos\Project1\Project1\Source.cpp(137,20): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
1>C:\Users\Ahmad.T\source\repos\Project1\Project1\Source.cpp(141,20): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
1>C:\Users\Ahmad.T\source\repos\Project1\Project1\Source.cpp(151,19): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
1>C:\Users\Ahmad.T\source\repos\Project1\Project1\Source.cpp(155,20): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
1>C:\Users\Ahmad.T\source\repos\Project1\Project1\Source.cpp(159,20): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
1>C:\Users\Ahmad.T\source\repos\Project1\Project1\Source.cpp(164,21): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
1>C:\Users\Ahmad.T\source\repos\Project1\Project1\Source.cpp(164,13): warning C4244: 'argument': conversion from 'int' to 'float', possible loss of data
1>flac.lib(stream_decoder.obj) : error LNK2019: unresolved external symbol __iob_func referenced in function FLAC__stream_decoder_reset
1>flac.lib(stream_encoder.obj) : error LNK2001: unresolved external symbol __iob_func
1>flac.lib(win_utf8_io.obj) : error LNK2001: unresolved external symbol __iob_func
1>flac.lib(bitreader.obj) : error LNK2019: unresolved external symbol fprintf referenced in function FLAC__bitreader_dump
1>flac.lib(bitwriter.obj) : error LNK2001: unresolved external symbol fprintf
1>flac.lib(win_utf8_io.obj) : error LNK2019: unresolved external symbol vsnprintf_s referenced in function local_vsnprintf
1>MSVCRTD.lib(vsnprintf_s.obj) : error LNK2001: unresolved external symbol vsnprintf_s
1>MSVCRTD.lib(vsnprintf_s.obj) : error LNK2001: unresolved external symbol _vsnprintf_s
1>C:\Users\Ahmad.T\source\repos\Project1\x64\Debug\Project1.exe : fatal error LNK1120: 4 unresolved externals
1>Done building project "Project1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Here are the libraries that are linked to the project:
flac.lib
opengl32.lib
openal32.lib
freetype.lib
winmm.lib
gdi32.lib
vorbisenc.lib
vorbisfile.lib
vorbis.lib
ogg.lib
ws2_32.lib
sfml-graphics-s-d.lib
sfml-window-s-d.lib
sfml-system-s-d.lib
sfml-audio-s-d.lib
sfml-network-s-d.lib
If you need a further look on the code I will include it in a comment if needed.

I think you used the wrong compiler. As SFML depends on a big number of underlying libraries (flac.lib is only one example..). These libraries are part of the download. However these libraries need to be used with the same compiler they were build.
That is why SFML is offering Downloads for different visual studio versions.
Between the versions Microsoft changed header definitions so now functions are defined different than in the delivered libraries(basically the header files changed between the different Visual Studio versions).
You may have success by
using the legacy_stdio_definitions.lib to resolve the issues
recompile all dependencies in your current compiler (or search for them to download)
switch back to supported Visual Studio 2015
See this answer for a similar problem

Related

How to solve 'error LNK2001: unresolved external symbol' for writing a User-defined Model (FLAC) in Visual Studio 2010 C++?

I am trying to write a User-defined Model in C++ for FLAC in Visual Studio Express 2010 C++. Initially, I am trying to run (debug and build) the built-in Strain-softening Model based on the Mohr-Coulomb criterion (Available in FLAC 8.0) by changing its name only. Once I succeed to do it, I will try to modify it as per my requirement. I am running the code in VS2010. I have already installed SDK7.1, VS2010 SP1, etc. However, I am getting the following error msg:
1>------ Build started: Project: i_ssoft, Configuration: Debug x64 ------
1> modeli_ssoft.cpp
1> Creating library C:\Program Files\Itasca\FLAC800\PluginFiles\Models\modeli_ssoft\i_ssoft\i_ssoft.lib and object C:\Program Files\Itasca\FLAC800\PluginFiles\Models\modeli_ssoft\i_ssoft\i_ssoft.exp
1>modeli_ssoft.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __cdecl models::ConstitutiveModel::getPluginName(void)const " (?getPluginName#ConstitutiveModel#models##UEBA?AV?$basic_string#_WU?$char_traits#_W#std##V?$allocator#_W#2##std##XZ)
1>C:\Program Files\Itasca\FLAC800\PluginFiles\Models\modeli_ssoft\i_ssoft\\i_ssoft.dll : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
From the error code, it is clear that I need to add some libraries or I need to place the supporting libraries in the same project directory... which I have tried but still, I am getting the error.

LINK Error while using C++ library (ITERATOR_DEBUG_LEVEL)

I am coding some games in C++ and have to use a graphical engine called PlayLib, made in the university near me, but unfortunately when I run this Main.cpp file with all the "includes" and "additional libraries", it gives me the same error! (on Visual Studio 2015, while on VC++2010 it works normally - but I prefer the first one). The error output message is the following:
1>LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification
1>Main.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification
1>PlayLib.lib(Graphics.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1900' in Main.obj
1>PlayLib.lib(Graphics.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in Main.obj
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>PlayLib.lib(Graphics.obj) : error LNK2001: unresolved external symbol __imp__vsprintf
1>PlayLib.lib(Graphics.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::exception::exception(char const * const &)" (__imp_??0exception#std##QAE#ABQBD#Z)
1>c:\users\casa\documents\visual studio 2015\Projects\BatalhaNaval\Debug\BatalhaNaval.exe : fatal error LNK1120: 2 unresolved externals
The main.cpp and header.h are all correct, so I think the problem may lie on the project settings or on the library itself. Please help me so I can work on my Battleship game - I am desperate to put my hands on it haha
Thanks - Guilherme
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs
I had same warning using some libraries. What helped me was going through #include directives in whole project and changing old style includes to a new style ones:
for example:
math.h i had to change to cmath
stdio.h, to cstdio ad so on.
If that doesn't help then probably you have an issue with runtime libraries. If you use visual studio you can play with them in project properties->C/C++->Code generation->Runtime Libraries.

error lnk2001: closedir, readdir, opendir

I am trying to import a c++ project from linux to windows (vs2010). My problem arise with the use of dirent.h. I ve downloaded the windows version of dirent from here: dirent. However when I compile my project I am getting the following errors:
1>DBreading.obj : error LNK2001: unresolved external symbol _closedir
1>DBreading.obj : error LNK2001: unresolved external symbol _readdir
1>DBreading.obj : error LNK2001: unresolved external symbol _opendir
A little research and I found that I am using some unix functions. My code is:
#include <DBreading.h>
#include <Detection.h>
#define _POSIX_SOURCE
#include <sys/stat.h>
#include <unistd.h>
#undef _POSIX_SOURCE
DBreading::DBreading(){}
vector <string> DBreading::listFile(string path){
vector<string> directories;
DIR *pDIR;
const char * c = path.c_str();
struct dirent *entry;
if( pDIR=opendir(c) ){
while(entry = readdir(pDIR)){
if( strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0 )
//cout << entry->d_name << "\n";
directories.push_back( entry->d_name);
}
closedir(pDIR);
}
// directories stores all subfolders or sub-files of a given path directory
return directories;
}
Any idea which are the correspondant function for closedir readdir and opendir in windows?
1>------ Rebuild All started: Project: myProject, Configuration: Release Win32 ------
1> DBreading.cpp
1>DBreading.cpp(46): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(52): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(53): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(90): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(97): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(116): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(122): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(123): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(159): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.cpp(166): warning C4018: '<' : signed/unsigned mismatch
1> Detection.cpp
1>c:\opencv-2.4.6.1\install\include\opencv2\flann\logger.h(66): warning C4996: 'fopen':
This function or variable may be unsafe. Consider using fopen_s instead. To disable
deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\stdio.h(234) :
see
declaration of 'fopen'
1> main.cpp
1>main.cpp(120): warning C4018: '<' : signed/unsigned mismatch
1>main.cpp(166): warning C4018: '<' : signed/unsigned mismatch
1>main.cpp(182): warning C4018: '<' : signed/unsigned mismatch
1>main.cpp(206): warning C4018: '<' : signed/unsigned mismatch
1>main.cpp(268): warning C4018: '<' : signed/unsigned mismatch
1>DBreading.obj : error LNK2001: unresolved external symbol _closedir
1>DBreading.obj : error LNK2001: unresolved external symbol _readdir
1>DBreading.obj : error LNK2001: unresolved external symbol _opendir
1>C:\Documents and Settings\chrathan.ITI-THERMI\My Documents\Visual Studio
2010\Projects\myProject\Release\myProject.exe : fatal error LNK1120: 3 unresolved
You can use FindFirstFile, FindNextFile, and FindClose (I believe these are in windows.h).
See this MSDN article for an example.
You explicitly link to an implementation of dirent.h that wraps the Windows functions in the Unix API. (Calling that "the Windows version" is a bit missing the point.)
What should be happening is that you include that header, and when you are calling readdir() etc., that call is turned (by the code in your dirent.h) into Windows API calls like FindNextFileW() etc. -- no Unix functions actually being involved.
The point is, I don't see your source example actually including dirent.h... unless you do the include somewhere we cannot see it, that means you installed that wrapping header, but you are not using it. Instead you #include some POSIX headers, which in turn reference the appropriate POSIX functions (which your linker does not find).
Mix & mingle of Windows and POSIX API. A sure recipee for disaster.
You need to adjust your #include's accordingly. As your example isn't SSCCE, it's hard to be more specific.

Strange link error while rebuilding in visual Studio 2012

I have a very strange problem. I have a project in VS2012 that links statically with another lib.
If I build project everything is fine.
However, if I REBUILD the project it will fail with link problems.
The lib is compiled, I do not compile it during the build.
It is no difference if I clean everything or building/rebuilding on top of previous build.
Build works, Rebuild - not!
Can anyone give me at least a clue - what different in those 2 commands? I do not even know how to start investigate the problem.
Supplemental:
To all the people that answered - You are trying to explain me the difference between the build and rebuild. Thank you, but I know it. You ignore the fact that I explained before:
I can completely clean previous results, delete OutDir, delete IntDir, delete everything produced by the compilation. still - Build work, Rebuild not.
In the explained above case - what is the difference between build and rebuild if you build the first time??
The reason I did not posted errors is that those are simply link errors telling me .lib is missing. While it is clearly not.
Here is the example:
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\sal.h(2872): warning RC4005: '_useHeader' : redefinition
1>
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\sal.h(2882): warning RC4005: '_on_failure' : redefinition
1>
1> Creating library D:\p4client\ProAudio\dev_main\ProAudio\XPlatform..\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\Products\WaveShell-DAE.lib and object D:\p4client\ProAudio\dev_main\ProAudio\XPlatform..\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\Products\WaveShell-DAE.exp
1>DefaultSwap.obj : error LNK2019: unresolved external symbol _ASI_UnregisterCustomByteSwapper#4 referenced in function _RemoveByteSwapper
1>DefaultSwap.obj : error LNK2019: unresolved external symbol _ASI_RegisterCustomByteSwapper#8 referenced in function _RegisterByteSwapper
1>PlugInLib.lib(PlugInUtils.obj) : error LNK2001: unresolved external symbol _imp_FicGestalt#8
1>PlugInLib.lib(CDSPProcess.obj) : error LNK2001: unresolved external symbol _imp_FicGestalt#8
1>PlugInLib.lib(CAdaptorPlugIn.obj) : error LNK2001: unresolved external symbol _imp_FicGestalt#8
1>CShellProcessGroup.obj : error LNK2019: unresolved external symbol _imp_FicGestalt#8 referenced in function "public: __thiscall CShellProcessGroup::CShellProcessGroup(void)" (??0CShellProcessGroup##QAE#XZ)
1>CEffectTypeRTAS.obj : error LNK2001: unresolved external symbol _imp_FicGestalt#8
1>PlugInLib.lib(CProcessGroupInterface.obj) : error LNK2001: unresolved external symbol _imp_FicGestalt#8
1>PlugInLib.lib(CProcessGroup.obj) : error LNK2001: unresolved external symbol _imp_FicGestalt#8
Maybe it will help to know that while running Build (Not rebuild) I will get the following warnings:
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\sal.h(2872): warning RC4005: '_useHeader' : redefinition
1>
1>C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\sal.h(2882): warning RC4005: '_on_failure' : redefinition
1>
1> Creating library D:\p4client\ProAudio\dev_main\ProAudio\XPlatform..\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\Products\WaveShell-DAE.lib and object D:\p4client\ProAudio\dev_main\ProAudio\XPlatform..\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\Products\WaveShell-DAE.exp
1>PlugInLib.lib(C321ChipDSP.obj) : warning LNK4099: PDB 'vc110_ib_2.pdb' was not found with 'PlugInLib.lib(C321ChipDSP.obj)' or at 'D:\p4client\ProAudio\dev_main\ProAudio\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\vc110_ib_2.pdb'; linking object as if no debug info
1>PlugInLib.lib(CDSP.obj) : warning LNK4099: PDB 'vc110_ib_3.pdb' was not found with 'PlugInLib.lib(CDSP.obj)' or at 'D:\p4client\ProAudio\dev_main\ProAudio\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\vc110_ib_3.pdb'; linking object as if no debug info
1>PlugInLib.lib(CDSPUtils.obj) : warning LNK4099: PDB 'vc110_ib_4.pdb' was not found with 'PlugInLib.lib(CDSPUtils.obj)' or at 'D:\p4client\ProAudio\dev_main\ProAudio\VisualStudioBuildProducts\WaveShell-DAE\Win32\Debug\vc110_ib_4.pdb'; linking object as if no debug info
Thanks!
Build means compile and link only the source files that have changed since the last build, while Rebuild means compile and link all source files regardless of whether they changed or not.
Build is the normal thing to do and is faster. Sometimes the versions of project target components can get out of sync and rebuild is necessary to make the build successful. In practice, you never need to Clean.
'Build' will do an incremental build, basically going through each project in your solution, see if there has been a change since the last build, and if there is, build it again.
'Rebuild' will perform a clean on everything and build everything from scratch.
Edit: A more detailed answer link
If your static lib is another project in the same solution as the project that links to the lib, then you need to set a dependency between the two projects so that the build process will build the lib first and the other project second.
To do this, right-click on the Solution abd choose "Project dependencies" from the pop-up menu.
I am not sure if it is related. But you may want to check this thread (the symptom is reversed from yours though...):
VS2010 Unresolved External Symbol errors on build (but not rebuild)

error when compiling a project in VS 2010 C ++

I'm trying to compile a project that I created, a software management program, in VS 2010. In VS6 and VS2005, it compiles perfectly.
1 - visual studio 6 2 - Visual Studio 2005 3 - Visual Studio 2010
The original version has some bugs that I would like fix later, but first of all I need it to compile.
With VS 6 and VS 2005 it compiles perfectly.
I added the library #pragma comment(lib, "bufferoverflowU.lib") corresponding to each file that needs it (.cpp)
However, it did not solve anything with bufferoverflowU.lib
errors are:
1>------ Operación Volver a generar todo iniciada: proyecto: Gestion_v1, configuración: Release Win32 ------
1> StdAfx.cpp
1> WDoS.cpp
1> Helpers.cpp
1> Gestion.cpp
1> WWW.cpp
1>WWW.cpp(141): warning C4018: '<' : no coinciden signed/unsigned
1>WWW.cpp(136): warning C4101: 'dwTmp' : variable local sin referencia
1>WWW.cpp(481): warning C4244: '=' : conversion from 'DWORD' to 'char'; possible loss of data
1>WWW.cpp(482): warning C4244: '=' : conversion from 'DWORD' to 'char'; possible loss of data
1> Generando código...
1>LINK : warning LNK4108: /ALIGN specified without /DRIVER; image may not run
1>WDoS.obj : error LNK2019: unresolved external symbol ___security_cookie referenced in function "unsigned long __stdcall WDoS_HTTP(void *)" (?WDoS_HTTP##YGKPAX#Z)
1>Gstion.obj : error LNK2001: unresolved external symbol ___security_cookie
1>WWW.obj : error LNK2001: unresolved external symbol ___security_cookie
1>WDoS.obj : error LNK2019: unresolved external symbol #__security_check_cookie#4 referenced in function "unsigned long __stdcall WDoS_HTTP(void *)" (?WDoS_HTTP##YGKPAX#Z)
1>Gestion.obj : error LNK2001: unresolved external symbol #__security_check_cookie#4
1>WWW.obj : error LNK2001: unresolved external symbol #__security_check_cookie#4
1>.\Release/Gestion_v1.exe : fatal error LNK1120: 2 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Any ideas?
Thanks
Your unresolved externals are a consequence of compiling with the /GS (Buffer Security Check) compiler flag, but not linking against the CRT (/NODEFAULTLIB). If /GS is not specified it defaults to being enabled. You can try to disable Buffer Security Checks by specifying /GS-.
Alternatively you can attempt to add the pieces of code you need. __security_cookie is declared in <process.h> and defined in <gs_cookie.c> as part of the CRT source that ships with Visual Studio. Since you also explicitly specified WinMain as the entry point and don't rely on the CRT to perform the required initialization you will have to call __security_init_cookie yourself. There may be more to get this to compile, but this should serve as a starting point.
Make sure your project is not set to unicode. Your library may be that is different.
Try : Project properties -> Configuration properties -> General -> Character set = not set
Ok, try this question :
error LNK2001: unresolved external symbol