I want to compile curl from source inside a Visual Studio project.
I get this error (and a lot more):
curl\src\tool_sdecls.h(67): error C2061: Syntax Error: Identifier'bool' (..\..\..\framework\libs\curl\src\tool_cb_dbg.c)
curl\src\tool_sdecls.h(68): error C2061: Syntax Error: Identifier'bool'is_cd_filename' (..\..\..\framework\libs\curl\src\tool_cb_dbg.c)
curl\src\tool_sdecls.h(68): error C2059: Syntax Error: ';' (..\..\..\framework\libs\curl\src\tool_cb_dbg.c)
The source of this file is:
65: struct OutStruct {
66: char *filename;
67: bool alloc_filename;
68: bool is_cd_filename;
69: bool s_isreg;
...
It looks like boolis not defined for some reason.
I tried defining HAVE_BOOL_T but nothing changed.
Any idea? Thanks
To solve the problem I added the folowing to curl_config.h
//for undefined bool error
#if _MSC_VER > 1700
#include <stdbool.h>
#else
#ifndef bool
typedef int bool;
#define false 0
#define true 1
#endif
#endif
//for warning C4005: 'POLLIN' : macro redefinition error
#define _WIN32_WINNT 0x0501
Related
A code compiles/runs fine on Linux and macOS. On Windows 10, I'm compiling the code with Visual Studio 2017 toolchain, but I'm receiving this error:
...\deps\tbb-2020.3-win\tbb\include\tbb\concurrent_vector.h:680: error: C2061: syntax error: identifier 'concurrent_vector<'template-type-parameter-1','template-type-parameter-2'>'
The error happens at this concurrent_vector template:
//! Copying constructor for vector with different allocator type
template<class M>
__TBB_DEPRECATED concurrent_vector( const concurrent_vector<T, M>& vector, const allocator_type& a = allocator_type() )
: internal::allocator_base<T, A>(a), internal::concurrent_vector_base()
{
vector_allocator_ptr = &internal_allocator;
__TBB_TRY {
internal_copy(vector.internal_vector_base(), sizeof(T), ©_array);
} __TBB_CATCH(...) {
segment_t *table = my_segment.load<relaxed>();
internal_free_segments( table, internal_clear(&destroy_array), my_first_block.load<relaxed>() );
__TBB_RETHROW();
}
}
The error happens inside the TBB headers:
C:\...\deps\tbb-2020.3-win\tbb\include\tbb\concurrent_vector.h
What could possibly be the cause?
Here is a more complete error log:
c:\users\m3\repos\3d-editor\editorlib\deps\tbb-2020.3-win\tbb\include\tbb\concurrent_vector.h(680): error C2061: syntax error: identifier 'concurrent_vector<`template-type-parameter-1',`template-type-parameter-2'>'
c:\users\m3\repos\3d-editor\editorlib\deps\tbb-2020.3-win\tbb\include\tbb\concurrent_vector.h(1167): note: see reference to class template instantiation 'tbb::concurrent_vector<T,A>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\memory_resource(860): note: see reference to class template instantiation 'std::pmr::_Intrusive_stack<std::pmr::monotonic_buffer_resource::_Header,void>' being compiled
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\memory_resource(465): note: see reference to class template instantiation 'std::pmr::_Intrusive_stack<std::pmr::unsynchronized_pool_resource::_Pool::_Chunk,void>' being compiled
c:\users\m3\repos\3d-editor\editorlib\deps\tbb-2020.3-win\tbb\include\tbb\concurrent_vector.h(681): error C2334: unexpected token(s) preceding ':'; skipping apparent function body
c:\users\m3\repos\3d-editor\editorlib\deps\tbb-2020.3-win\tbb\include\tbb\concurrent_vector.h(61): fatal error C1075: '{': no matching token found
jom: C:\Users\m3\repos\build-3dsceneeditor-Desktop_Qt_5_12_9_MSVC2017_64bit-Debug\editorlib\Makefile.Debug [debug\openvdbutils.obj] Error 2
This code can be used to recreate the issue in combination with the /Zc:__cplusplus compiler flag in visual studio 2017:
#include <tbb/concurrent_vector.h>
int main()
{
tbb::concurrent_vector<int> vector;
vector.push_back(1);
return 0;
}
This seems to be a visual studio bug. From the issue on the TBB github respository the /Zc:__cplusplus compiler flag is the cause.
Enabling that flag causes this code to use the c++14 [[deprecated]] attribute:
#if (__cplusplus >= 201402L)
#define __TBB_DEPRECATED [[deprecated]]
#define __TBB_DEPRECATED_MSG(msg) [[deprecated(msg)]]
#elif _MSC_VER
#define __TBB_DEPRECATED __declspec(deprecated)
#define __TBB_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
#elif (__GNUC__ && __TBB_GCC_VERSION >= 40805) || __clang__
#define __TBB_DEPRECATED __attribute__((deprecated))
#define __TBB_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
#endif
Swapping this code around to always use the visual studio specific code seems to fix the problem:
#if _MSC_VER
#define __TBB_DEPRECATED __declspec(deprecated)
#define __TBB_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
#elif (__cplusplus >= 201402L)
#define __TBB_DEPRECATED [[deprecated]]
#define __TBB_DEPRECATED_MSG(msg) [[deprecated(msg)]]
#elif (__GNUC__ && __TBB_GCC_VERSION >= 40805) || __clang__
#define __TBB_DEPRECATED __attribute__((deprecated))
#define __TBB_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
#endif
A smaller demonstration of the same problem is:
template <typename T>
class Foo
{
public:
Foo() {}
template <typename X>
[[deprecated]] Foo(const Foo<T>& a)
{
}
};
int main()
{
Foo<int> x;
return 0;
}
This only doesn't work in Visual Studio 2017, it works in 2019 so the simplest fix is to update visual studio.
A pull request has been created to fix this issue and reported to Microsoft, I wouldn't expect MS to fix it though as it is already fixed in 2019.
As discussed here a short fix would be to downgrade to TBB 2020 Update 1 on Windows. Thanks to #AlanBirtles
I'm having the same error as Crypto++ giving a compiler error in algparam.h when compiling a game using Crypto++. The error is:
Error C2061: syntax error : identifier 'buffer' (at line 397)
Here is the code. It starts on line 390 an ends at line 411.
#if defined(DEBUG_NEW) && (_MSC_VER >= 1300)
# pragma push_macro("new")
# undef new
#endif
void MoveInto(void *buffer) const
{
AlgorithmParametersTemplate<T>* p = new(buffer) AlgorithmParametersTemplate<T>(*this);
CRYPTOPP_UNUSED(p); // silence warning
}
#if defined(DEBUG_NEW) && (_MSC_VER >= 1300)
# pragma pop_macro("new")
#endif
protected:
T m_value;
};
CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<bool>;
CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<int>;
CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<ConstByteArrayParameter>;
What is the problem and how do I fix it?
Here are the libraries I use:
boost 1.67 (tried 1.63 too)
sqlapi++
camp
mysqlcppconns
Here is the error message:
1>c:\local\cryptopp\algparam.h(397): error C2061: syntax error: identifier 'buffer'
1>c:\local\cryptopp\algparam.h(396): note: while compiling class template member function 'void CryptoPP::AlgorithmParametersTemplate<CryptoPP::ConstByteArrayParameter>::MoveInto(void *) const'
1>c:\local\cryptopp\algparam.h(411): note: see reference to class template instantiation 'CryptoPP::AlgorithmParametersTemplate<CryptoPP::ConstByteArrayParameter>' being compiled
Here is the function you are having trouble with from algparam.h:
395 void MoveInto(void *buffer) const
396 {
397 AlgorithmParametersTemplate<T>* p = new(buffer) AlgorithmParametersTemplate<T>(*this);
398 CRYPTOPP_UNUSED(p); // silence warning
399 }
I suspect one of the other libraries you are using is messing with the definition on new.
I believe you need to compile the source file but instead of producing an object file, you need to use either /P (Preprocess to a File) or /E (Preprocess to stdout). Once the file is processed take a look at the definition of new. From there work back to the library that is changing it.
In the comments you said you also use:
boost 1.67 (tried 1.63 too)
sqlapi++
camp
mysqlcppconns
Boost does some unusual things at times, and I would suspect boost as the problem.
I've integrated all the needed files to use freetype-gl.hdirectly into my OpenGL project, but when I try to build the program, I receive 262 errors complaining aboutwglew.h. A sample of the errors:
error C2143: syntax error : missing ')' before '*' c:\bar\includes\glew110\include\gl\wglew.h 113 1 Foo
error C2143: syntax error : missing ';' before '*' c:\bar\glew110\include\gl\wglew.h 113 1 Foo
error C2059: syntax error : ')' c:\bar\includes\glew110\include\gl\wglew.h 113 1 Foo
error C2065: 'HDC' : undeclared identifier c:\bar\glew110\include\gl\wglew.h 113 1 Foo
error C2146: syntax error : missing ')' before identifier 'hDC' c:\bar\includes\glew110\include\gl\wglew.h 113 1 Foo
And in my class, just this header causes the problem with wglew.h:
#include "freetype-gl.h" // causes all the errors
This solution solved a wglew error for me, not sure if it's the same problem.
Try adding the wglew.h include line to the same file as your other include line for freetype-gl.h, and in this order:
#include <Windows.h> // maybe not needed
#define GLEW_STATIC // maybe not needed
#include "GL/glew.h"
#include "GL/wglew.h"
#include "freetype-gl.h"
// other includes below
I am trying to compile a code
#include <Header1.h>
#include "Header2..h"
#include <ctype.h>
Header1.h includes winsock.h and Header2.h includes windows.h
I am using winsock.h instead of winsock2.h because winsock2.h was showing redefinition errors, which is a standard error, but I was not able to fix that using the solutions provided to them.
I have also tried including ws2tcpip.h, but it is giving tons of redefinition errors in winsock.h.
I am getting 12 errors in this Module
error C3861: 'close': identifier not found
error C2664: 'setsockopt' : cannot convert parameter 4 from 'timeval *' to 'const char *'
error C2065: 'socklen_t' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'optionLength'
error C2065: 'optionLength' : undeclared identifier
error C2065: 'optionLength' : undeclared identifier
error C2664: 'setsockopt' : cannot convert parameter 4 from 'int32 *' to 'const char *'
error C2065: 'MSG_WAITALL' : undeclared identifier
error C2664: 'recvfrom' : cannot convert parameter 2 from 'uint8 *' to 'char *'
error C2065: 'ERROR_END_OF_STREAM' : undeclared identifier
error C3861: 'close': identifier not found
error C3861: 'close': identifier not found
Add #include <winsock2.h> or #include <ws2tcpip.h> on the top of includes.
#include <winsock2.h>
#include <Header1.h>
#include "Header2.h"
#include <ctype.h>
winsock.h should be included first. And I notice that your code seems to be unixish code. On windows, closesocket is used for closing socket.
Also, #define WIN32_LEAN_AND_MEAN before anything else. That often helps.
Also, in some cases helps this (issues with ws2tcpip identifier error):
#pragma once
#define _WIN32_WINNT 0x500
#include <winsock2.h>
#include <WS2tcpip.h>
#pragma comment(lib, "WS2_32.Lib")
I have a problem: My codes work well in CentOS g++, but when I compile them in visual studio 2008, the visual studio tells me errors like below:
1.c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h(19) : error C2144: syntax error : '__w64 unsigned int' should be preceded by '}'
2.error C2143: syntax error : missing '}' before 'namespace'.
My file coding is UTF-8. Should I change them in Unicode all, I change some error file in Unicode,it still has errors like above.
below are some sourecode:
#ifndef ENRC_CODE_DEFS_H
#define ENRC_CODE_DEFS_H
enum ENReturnCode
{
ENRC_SUCCESS = 0,
ENRC_FAILED,
ENRC_NODATA,
ENRC_CONFIG_NOT_AVAILABLE,
ENRC_INVALID_SUBSCRIBE_ID,
ENRC_INVALID_SUBSCRIBE_CONDITION,
ENRC_INVALID_SUBSCRIBER,
ENRC_INVALID_PARAMETER,
ENRC_THREAD_RUNNING,
ENRC_SUBSCRIBE_LIST_EMPTY,
ENRC_OUT_OF_MEMORY // 10
}
e:\my_code\cppcommon\include\errordefs.h(5) : error C2143: syntax error : missing ';' before 'enum [tag]'
next:
#ifndef EN_SMS_SRC_TAO2CPP_H_
#define EN_SMS_SRC_TAO2CPP_H_
#include "SystemMonitorMasterServiceC.h"
#include "SystemMonitorSlaveServiceC.h"
#include "CommonDefs.h"
#include "SystemMonitorServiceDataDefs.h"
namespace EN
{
namespace SMS
{
template < typename _Ty, typename _Cy>
inline
void Tao2Cpp_Enum(_Ty taoValue, _Cy &cppValue)
{
cppValue = (_Cy)taoValue;
}
error C2143: syntax error : missing '}' before 'namespace'
A lot of errors like above.
Thanks. I waste some time to make it easy to read.
You need a semi-colon in the enum declaration:
enum ENReturnCode
{
...
};