Visual Studio + Boost error - c++

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.

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".

Building Quickfix on Windows for 64bit

I've downloaded what I believe is the latest Quickfix from Github. It builds fine as an x86 project, but when I try to build it as an x64 project there's a load of warnings (see below).
I can't imagine I'm the first person to want to build a 64bit version of Quickfix. A lot of the warnings look like they're Windows specific (eg casting the SOCKET to int).
Is there a version of Quickfix out there that builds cleanly as a 64bit library on Windows, or will I need to go in and patch it myself?
FieldMap.cpp(205): warning C4267: '+=': conversion from 'size_t' to
'int', possible loss of data FileStore.cpp(135): warning C4477:
'fscanf_s' : format string '%lu' requires an argument of type
'unsigned long *', but variadic argument 3 has type 'size_t *'
FileStore.cpp(135): note: consider using '%zu' in the format string
FileStore.cpp(197): warning C4477: 'fprintf' : format string '%lu'
requires an argument of type 'unsigned long', but variadic argument 3
has type '::size_t' FileStore.cpp(197): note: consider using '%zu' in
the format string
c:\apps\VS2017Pro\VC\Tools\MSVC\14.10.25017\include\utility(239):
warning C4267: '=': conversion from 'size_t' to 'int', possible loss
of data FileStore.cpp(136): note: see reference to function template
instantiation 'std::pair &std::pair::operator
=(std::pair &&)' being compiled FileStore.cpp(136): note: see reference to function template
instantiation 'std::pair &std::pair::operator
=(std::pair &&)' being compiled SocketConnection.cpp(89): warning C4267: '+=': conversion
from 'size_t' to 'unsigned int', possible loss of data
SocketMonitor.cpp(141): warning C4244: '=': conversion from 'double'
to 'long', possible loss of data SocketMonitor.cpp(146): warning
C4244: '=': conversion from 'double' to 'long', possible loss of data
SocketMonitor.cpp(232): warning C4244: 'initializing': conversion from
'SOCKET' to 'int', possible loss of data SocketMonitor.cpp(271):
warning C4244: 'initializing': conversion from 'SOCKET' to 'int',
possible loss of data SocketMonitor.cpp(312): warning C4244:
'initializing': conversion from 'SOCKET' to 'int', possible loss of
data Utility.cpp(105): warning C4244: 'initializing': conversion from
'SOCKET' to 'int', possible loss of data Utility.cpp(128): warning
C4244: 'return': conversion from 'SOCKET' to 'int', possible loss of
data Utility.cpp(139): warning C4996: 'inet_addr': Use inet_pton() or
InetPton() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to
disable deprecated API warnings C:\Program Files (x86)\Windows
Kits\8.1\Include\um\Winsock2.h(1850): note: see declaration of
'inet_addr' Utility.cpp(150): warning C4244: 'return': conversion from
'SOCKET' to 'int', possible loss of data Utility.cpp(155): warning
C4267: 'argument': conversion from 'size_t' to 'int', possible loss of
data Utility.cpp(276): warning C4309: '=': truncation of constant
value Utility.cpp(299): warning C4996: 'inet_ntoa': Use inet_ntop() or
InetNtop() instead or define _WINSOCK_DEPRECATED_NO_WARNINGS to
disable deprecated API warnings C:\Program Files (x86)\Windows
Kits\8.1\Include\um\Winsock2.h(1868): note: see declaration of
'inet_ntoa' Utility.cpp(314): warning C4996: 'inet_addr': Use
inet_pton() or InetPton() instead or define
_WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings C:\Program Files (x86)\Windows Kits\8.1\Include\um\Winsock2.h(1850):
note: see declaration of 'inet_addr' Utility.cpp(322): warning C4996:
'gethostbyname': Use getaddrinfo() or GetAddrInfoW() instead or define
_WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings C:\Program Files (x86)\Windows Kits\8.1\Include\um\Winsock2.h(2238):
note: see declaration of 'gethostbyname' Utility.cpp(328): warning
C4996: 'inet_ntoa': Use inet_ntop() or InetNtop() instead or define
_WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings C:\Program Files (x86)\Windows Kits\8.1\Include\um\Winsock2.h(1868):
note: see declaration of 'inet_ntoa' Utility.cpp(337): warning C4996:
'inet_ntoa': Use inet_ntop() or InetNtop() instead or define
_WINSOCK_DEPRECATED_NO_WARNINGS to disable deprecated API warnings C:\Program Files (x86)\Windows Kits\8.1\Include\um\Winsock2.h(1868):
note: see declaration of 'inet_ntoa' Utility.cpp(399): warning C4244:
'=': conversion from 'uintptr_t' to 'FIX::thread_id', possible loss of
data Utility.cpp(418): warning C4312: 'type cast': conversion from
'FIX::thread_id' to 'void *' of greater size Utility.cpp(419): warning
C4312: 'type cast': conversion from 'FIX::thread_id' to 'HANDLE' of
greater size Utility.cpp(428): warning C4312: 'type cast': conversion
from 'FIX::thread_id' to 'HANDLE' of greater size Utility.cpp(438):
warning C4311: 'type cast': pointer truncation from 'HANDLE' to
'unsigned int' Utility.cpp(438): warning C4302: 'type cast':
truncation from 'HANDLE' to 'unsigned int'
df

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

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)