Error when converting .obj to openGL - c++

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):
  

Related

How do I prevent the compiler from compiling obvious typos like if (somevalue = 0)? [duplicate]

Is it possible in Visual Studio to get a compiler error for an assignment in an if statement? How?
#include <iostream>
int main()
{
int a = 2;
if (a = 3) // Want a warning here
std::cout << "Avoid this!\n";
}
I know I can switch to Yoda conditions (if (3=a)), but I really don't want to.
I tried: setting the warning level to /Wall but I still don't get a warning that I could then treat as an error.
I am doing this in Visual Studio 2019 (16.11.19).:
The build output is
Rebuild started...
1>------ Rebuild All started: Project: Yoda2019, Configuration: Debug Win32 ------
1>Yoda2019.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\limits.h(70,5): error C2220: the following warning is treated as an error
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\limits.h(70,5): warning C4668: '__STDC_WANT_SECURE_LIB__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xmemory(154,5): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xmemory(164,5): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(284,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(299,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(315,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(375,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>Done building project "Yoda2019.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
and Visual Studio 2022 (17.4.0)
The build output is
Rebuild started...
1>------ Rebuild All started: Project: YodaCheck, Configuration: Debug x64 ------
1>YodaCheck.cpp
1>YodaCheck.vcxproj -> B:\Projekte\C++\Dynamic Linking\YodaCheck\x64\Debug\YodaCheck.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
========== Elapsed 00:01,379 ==========
so I see no warning which I could convert into an error.
You can turn any specific warning into an error, using the #pragma warning(error:nnnn) directive. In your case, the warning is:
warning C4706: assignment within conditional expression
So, adding the relevant #pragma directive to the code will generate a compiler error:
#include <iostream>
#pragma warning(error:4706)
int main()
{
int a = 2;
if (a = 3) // Want a warning here
std::cout << "Avoid this!\n";
}
This now gives:
error C4706: assignment within conditional expression
For a solution wide setting, change it here in the property pages:
Use /W4 /WX
/WX Treats all compiler warnings as errors. For a new project, it may be best to use /WX in all compilations; resolving all warnings ensures the fewest possible hard-to-find code defects.
https://learn.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=msvc-170
Make sure you make that setting in the relevant configurations. In such a simple demo, it's probably easiest to choose "all configurations" and "all platforms".

How to get a compiler error for assignments in an if statement?

Is it possible in Visual Studio to get a compiler error for an assignment in an if statement? How?
#include <iostream>
int main()
{
int a = 2;
if (a = 3) // Want a warning here
std::cout << "Avoid this!\n";
}
I know I can switch to Yoda conditions (if (3=a)), but I really don't want to.
I tried: setting the warning level to /Wall but I still don't get a warning that I could then treat as an error.
I am doing this in Visual Studio 2019 (16.11.19).:
The build output is
Rebuild started...
1>------ Rebuild All started: Project: Yoda2019, Configuration: Debug Win32 ------
1>Yoda2019.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\limits.h(70,5): error C2220: the following warning is treated as an error
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\limits.h(70,5): warning C4668: '__STDC_WANT_SECURE_LIB__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xmemory(154,5): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xmemory(164,5): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(284,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(299,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(315,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\atomic(375,9): warning C4365: 'argument': conversion from 'long' to 'unsigned int', signed/unsigned mismatch
1>Done building project "Yoda2019.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
and Visual Studio 2022 (17.4.0)
The build output is
Rebuild started...
1>------ Rebuild All started: Project: YodaCheck, Configuration: Debug x64 ------
1>YodaCheck.cpp
1>YodaCheck.vcxproj -> B:\Projekte\C++\Dynamic Linking\YodaCheck\x64\Debug\YodaCheck.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
========== Elapsed 00:01,379 ==========
so I see no warning which I could convert into an error.
You can turn any specific warning into an error, using the #pragma warning(error:nnnn) directive. In your case, the warning is:
warning C4706: assignment within conditional expression
So, adding the relevant #pragma directive to the code will generate a compiler error:
#include <iostream>
#pragma warning(error:4706)
int main()
{
int a = 2;
if (a = 3) // Want a warning here
std::cout << "Avoid this!\n";
}
This now gives:
error C4706: assignment within conditional expression
For a solution wide setting, change it here in the property pages:
Use /W4 /WX
/WX Treats all compiler warnings as errors. For a new project, it may be best to use /WX in all compilations; resolving all warnings ensures the fewest possible hard-to-find code defects.
https://learn.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=msvc-170
Make sure you make that setting in the relevant configurations. In such a simple demo, it's probably easiest to choose "all configurations" and "all platforms".

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.

Visual Studio + Boost error

I'm trying to build a solution using Boost in Visual Studio C++ Express 2010 and get the following error:
1>------ Build started: Project: MEDsLDAc, Configuration: Release Win32 ------
1> MedLDA.cpp
1>D:\_download\boost_1_53_0\boost/math/constants/calculate_constants.hpp(152): error C2988: unrecognizable template declaration/definition
1>D:\_download\boost_1_53_0\boost/math/constants/calculate_constants.hpp(152): error C2059: syntax error : 'constant'
1>D:\_download\boost_1_53_0\boost/math/constants/calculate_constants.hpp(153): error C2143: syntax error : missing ')' before '>'
1>D:\_download\boost_1_53_0\boost/math/constants/calculate_constants.hpp(184): error C2244: 'boost::math::constants::detail::constant_euler<T>::compute' : unable to match function definition to an existing declaration
1> definition
1> 'T boost::math::constants::detail::constant_euler<T>::compute(void)'
1> existing declarations
1> 'T boost::math::constants::detail::constant_euler<T>::compute(void)'
1>MedLDA.cpp(385): warning C4244: 'initializing' : conversion from 'double' to 'long', possible loss of data
1>MedLDA.cpp(426): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_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\string.h(105) : see declaration of 'strcpy'
1>MedLDA.cpp(485): warning C4244: 'initializing' : conversion from 'double' to 'long', possible loss of data
1>MedLDA.cpp(608): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_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\string.h(105) : see declaration of 'strcpy'
1>MedLDA.cpp(609): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_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\string.h(105) : see declaration of 'strcpy'
1>MedLDA.cpp(636): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_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\string.h(105) : see declaration of 'strcpy'
1>MedLDA.cpp(730): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>MedLDA.cpp(963): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>MedLDA.cpp(1150): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
1>MedLDA.cpp(1241): warning C4244: 'initializing' : conversion from 'double' to 'long', possible loss of data
1>MedLDA.cpp(1296): warning C4244: 'initializing' : conversion from 'double' to 'long', possible loss of data
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
How to fix it?
UPDATE: the software is MedLDAc available here:
http://www.ml-thu.net/~jun/medlda.shtml
The author says building works for him.
Since you haven't shown any code, we can only guess. My guess is that you #define some macro that messes-up Boost.Math code. Maybe something like #define M ......
UPDATE: It turns out that my guess was correct. Take a look at MedLDAc/MEDsLDAc/cokus.h file:
#define M (397) // a period parameter
The immediate workaround is to move #include <boost/math/special_functions/gamma.hpp> line in MedLDA.cpp to be the first include, after StdAfx.h, so that the above macro wouldn't affect the templates declared in gamma.hpp.
P.S. Defining one-letter macros is a really, really bad idea.

Lua and Visual C++

I have a simple question. When I open VC++, create an "Empty Project," insert the Lua 5.2.0 source code, then compile, I get no errors. However, when I do this except select "Windows Forms Application" at the beginning, I get a whole bunch of errors. What may be causing this?
EDIT:
The errors are about safe versions of certain functions:
1>..\lua-5.2.0\src\lua.c(102): error C3861: 'signal': identifier not found
1>..\lua-5.2.0\src\lua.c(178): error C3861: 'signal': identifier not found
1>..\lua-5.2.0\src\lua.c(180): error C3861: 'signal': identifier not found
1> luac.c
1>..\lua-5.2.0\src\luac.c(43): warning C4996: 'strerror': This function or variable may be unsafe. Consider using strerror_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\string.h(157) : see declaration of 'strerror'
1>..\lua-5.2.0\src\luac.c(178): 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 (x86)\Microsoft Visual Studio 10.0\VC\include\stdio.h(234) : see declaration of 'fopen'
1> lundump.c
1> lvm.c
1>..\lua-5.2.0\src\lvm.c(53): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\stdio.h(371) : see declaration of 'sprintf'
1> lzio.c
1> Generating Code...
It may be because when you create a windows form application, it is actually using managed c++ (uses .net), which I don't think lua is compatible with. Take a look at http://luaplus.org/ that might be what you're looking for. It seems like it's lua for ANY .net language (which managed c++ is)