error lnk2001: closedir, readdir, opendir - c++

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.

Related

Can't play audio with STATIC linked SFML

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

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.

Sudden compilation errors within stdlib.h, math.h, stdio.h, string.h, stdarg.h, and many others

I've downloaded a source code originally from a Code::Blocks project, in which it works absolutely fine compiling with MinGW and GCC.
I tried to load it in Visual Studio 2010 and set the includes/libraries accordingly, but I'm getting tons and tons of errors from within the standard library headers and others as well.
Mainly, they are errors like:
...\stdlib.h(314): error C2146: syntax error : missing ')' before identifier '__nptr'
...\stdlib.h(314): error C2061: syntax error : identifier '__nptr'
...\stdlib.h(314): error C2059: syntax error : ';'
...\stdlib.h(314): error C2059: syntax error : ','
...\stdlib.h(314): error C2059: syntax error : ')'
...\stdlib.h(315): error C2373: '__restrict__' : redefinition; different type modifiers
From code:
(314) strtod (const char* __restrict__ __nptr, char** __restrict__ __endptr);
(315) float __cdecl __MINGW_NOTHROW strtof (const char * __restrict__, char ** __restrict__);
And so on.
Must have screwed up big time to have such a massive amount of errors. I really have no idea where it went wrong though.

Error when converting .obj to openGL

When I was converting .obj file to openGL i have some errors. I am not sure how to fix the error. I have change the sign to >, yet the error still persists.
1>------ Build started: Project: LoadObj Trial, Configuration: Release Win32 ------
1> LoadObj Trial.cpp
1>LoadObj Trial.cpp(78): warning C4018: '<' : signed/unsigned mismatch
1>LoadObj Trial.cpp(90): error C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> D:\VISUAL STUDIO\VC\include\stdio.h(311) : see declaration of 'sscanf'
1>LoadObj Trial.cpp(109): warning C4018: '<' : signed/unsigned mismatch
1>LoadObj Trial.cpp(134): warning C4018: '<' : signed/unsigned mismatch
1>LoadObj Trial.cpp(136): warning C4018: '<' : signed/unsigned mismatch
1>LoadObj Trial.cpp(138): warning C4018: '<' : signed/unsigned mismatch
1>LoadObj Trial.cpp(140): warning C4018: '<' : signed/unsigned mismatch
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
LoadObj Trial.cpp(90): error C4996: 'sscanf': This function or variable may be unsafe. Consider using sscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> D:\VISUAL STUDIO\VC\include\stdio.h(311) : see declaration of 'sscanf'
That is not really an error, and it has got nothing to do with OpenGL. That is the MSVC compiler treating a level 3 security/deprecation warning as a compiler error. Your project is probably configured to treat level 3/4 warnings as errors.
To solve the "error", you can use the variant it suggest (which will make your code rather non-portable), or simply add #define _CRT_SECURE_NO_WARNINGS or add that definition to your pre-processor definitions in the project settings.
The other warnings, however, are impossible to diagnose without seeing your code. And it is pretty safe to assume that simply switching the direction of the comparison is not going to do anything useful, that will probably break things and will do nothing to solve the problem of comparing signed and unsigned values.
Regarding making the pre-processor definition I mentioned a project-wide setting, see the following screenshot (Visual Studio 2013 Pro):
  

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