Trying to use SDL 2 with Visual Studio c++ - c++

I am trying to do one that requires I use SDL2 and I was excited to finally start attempting to write a program. I downloaded SDL2 and didn't have any problems.
Next I opened a new empty project followed the instructions to add the include folder, lib(x86) folder, and I added the sdl2.lib and sdl2main.lib to the linker.
When I tried to build the project I received the following error.
1>MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib'
conflicts with use of other libs; use /NODEFAULTLIB:library
1>sdl2main.lib(SDL_windows_main.obj) : error LNK2019: unresolved external
symbol _SDL_main referenced in function _main
1>c:\users\nas\documents\visual studio 2013\Projects\Basic SDL\Debug\Basic
SDL.exe : fatal error LNK1120: 1 unresolved externals

You need to link to the library files.
Right click the project and then properties
Click VC++ Directories.
Click include directories, then the down arrow, then <edit>.
Then add the directory of the include files (where all the .h files are, for example E:\Visual Studio .NET\SDL2-2.0.3\Include).
Then do the same for the library files by clicking library directories',down arrow,edit. However, you will want to make sure you are targeting x86 (for 32 bit program for exampleE:\Visual Studio .NET\SDL2-2.0.3\lib\x86`) or x64 (64bit program, not so common)
Then expand linker and click input on the left hand side.
Click additional dependencies, and then edit and add SDL2.lib and SDL2main.lib.
Click system under the linker heading.
Change SubSystem to /SUBSYSTEM:CONSOLE.
Finally make sure the SDL.dll file is in the folder of your project debug folder.

Related

Include all source file for build

I have C++ project in my Visual Studio. Additionally I placed directory with source files in it in order to use them like library in my main project.
Everything works fine while code browsing. I can define includes of library headers and navigate to functions.
I got problem during project build. I got a lot of linking errors which tells that system can't link to functions from library.
Error LNK2019 unresolved external symbol lv_task_create referenced in function monitor_init testLVGL C:\cpp_test\testLVGL\monitor.obj 1
Error LNK2019 unresolved external symbol lv_tick_inc referenced in function "int __cdecl tick_thread(void *)" (?tick_thread##YAHPEAX#Z) testLVGL C:\cpp_test\testLVGL\testLVGL.obj 1
Error LNK2019 unresolved external symbol lv_task_handler referenced in function SDL_main testLVGL C:\cpp_test\testLVGL\testLVGL.obj 1
Looks like Visual C++ is even not trying to build library.
How to tell Visual C++ to include all library files located in subdirectory in order to build and link to project?
Visual Studio does not include all the files in a directory on its own. You need to explicitly include them (you dont have to do this if you add a file within the Solution Explorer or within Visual Studio). Else it wont be listed to the compiler.
To include them, go to the solution explorer and select "Show all files". This will show you all the files in the directory. Then you can see the unlisted files marked with a red icon. Right click it and hit "Include in project" and the red icon will disappear. After this, the file will be listed as one of the project's file.

How do I resolve linker error LNK2019 while including "zlib" in my Visual Studio 2013?

I got the precompiled "lib" and "dll" from here: http://zlib.net/zlib128-dll.zip
I am compiling my project in x64.
I added directory into "Additional Include Directories"
I added the "zdll.lib" to Linker -> Additional Dependencies.
I added the library directory to Linker -> Additional Library Directories.
I also added the Post-Build Event "xcopy ..\oem\zlib\*.dll "$(TargetDir)"
But I still get the Linker error:
: error LNK2019: unresolved external symbol inflateInit_ referenced in function
Thanks.
IS that a 32-bit dll? If so, you'll have to obtain, or build your own, 64-bit version.
The linker error happens with the lib file, if you have the right headers it'll compile, if you have the right lib, it'll link, if you have the right dll, it'll run.

GLFW not working in Visual Studio Community

I am using Visual Studio for C++. I have tried to link GLFW in Visual Studio. The steps I went through are as follows:
Specify include directories under VC++ properties.
Specify the library directories under VC++ properties.
Add the .lib file in additional dependencies under Linker -> Input
Visual Studio recognises the header #include <GLFW/glfw3.h> and recognised glfwInit() but when glfwInit() is called it causes the build to fail. I get this build error:
LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
I then also get some unresolved externals:
LNK2019 unresolved external symbol __imp__vsnprintf referenced in function __glfwInputError
LNK2001 unresolved external symbol __imp__vsnprintf
LNK2019 unresolved external symbol __imp__sscanf referenced in function _parseVersionString
LNK2001 unresolved external symbol __imp___vsnprintf
LNK1120 3 unresolved externals
Sneaky... when I downloaded GLFW it had multiple lib folders (for the different releases) and only one include folder. I assumed that the include folder would work for all of the lib folders because there was only one. However that was not the case, the include folder only worked for the latest lib folder and I tried to use the 2013 GLFW instead of the latest 2015 GLFW lib folder with the include folder to no avail. I was using 2013 GLFW because that was the version the tutorial series I was watching used if you were wondering.

Linking a DLLs in visual studio 2013

I've already looked for solution, without a success.
I need to use a DLL supplied by third parties on Visual Studio 2013(running on (x64) Windows 10).
On machine there are both OpenCV 3.0.0 and OpenCV2.410 installed and working.
The DLL's author has provided a .lib file and He says that in order to use this DLLs in your project, you need to put some others OpenCV's dlls in the project folder( I've tried to put these DLLs in every project folder[yes I know, it has no sense, but after a lot of tries i've lost my patience])
What he supplies is an .dll and an example project( that doesn't work for me because it needs OpenCV2.1 and there are instructions needs to be translate in newest version [and I prefered don't translate nothing]).
The errors in this example project are of this kind:
error LNK2001: unresolved external symbol
fatal error LNK1120: unresolved externals
The most of them are caused by the miss of OpenCV2.1, that I don't want to install, because I'll have to use it on a program using with OpenCV 3.0.0.
In the example project folder there are:
The upper mentioned .dll
A .lib file
The header file .h
These DLLs: cv210.dll, cxcore210.dll, highgui210.dll, ...(eg. cv210d.dll)
What I've done is this:
A folder called "lib" where I insert all .dll, .lib, .h files.
Put the "lib" folder in Project properties>linker> General> Additional Library Directories
Writing the .lib file in properties>linker> Input> Additional Dependencies
Put the 'lib' pathproperties>C/C++>Additional Include Directories[I know, this has no sense too]
I get these kind of errors:
error LNK2001: unresolved external symbol
I've tried #pragma comment(lib, 'file.lib') way too.
Someone can help me?

Compiling C++ program using MS Visual Studio 2010 as to not depend on any external code or redistributables

I want my exe to be runnable without depending on any redistributable packages but when I set
"Use of MFC" to "Use MFC in a Static Library" in the Project > Properties menu, I get errors such as this one:
- Error 2 error LNK2019: unresolved external symbol _imp_GetWindowTextW#12 referenced in function _wmain
So basically I get unresolved external symbol for the functions.
Thank you.
In Project->Properties->Linker->Command Line type user32.lib
Under the linker settings for your project, make sure you've included the default libraries under "Additional Dependencies".
This is usually:
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
Also, make sure have not set "Ignore All Default Libraries".