[C++]Building Error Notes - Windows
keywords: C++, std_Binderstd_Unforced, sockaddr, int __cdecl invoke_main(void)
unresolved external symbol main referenced in function “int __cdecl invoke_main(void)”
Error:
MSVCRTD.lib(exe_main.obj): Error LNK2019 : unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
Solution:
Add /subsystem:windows
:
#ifdef _WIN32
#pragma comment(linker, "/subsystem:windows")
#include <windows.h>
#endif
cannot convert from ‘std::_Binder’
Error:
Error C2440 : 'initializing': cannot convert from 'std::_Binder<std::_Unforced,int &,sockaddr *,size_t>' to 'int'
Solution:
Give a global function symbol.
int rs = ::bind(ServerSocket, (sockaddr*)&oAddr, sizeof(oAddr));
Failed to create virtual memory for PCH
Error:
c1xx: Error C3859 : Failed to create virtual memory for PCH
c1xx: note: the system returned code 1455: The paging file is too small for this operation to complete.
c1xx: note: please visit https://aka.ms/pch-help for more details
c1xx: Error C1076 : compiler limit: internal heap limit reached
Solution:
Enable virtualization option (Intel VT
or AMD SVM
) in the BIOS.
e.g. for AMD CPU, Overclocking -> Advanced CPU Configuration -> Enable SVM Mode
.
attempting to reference a deleted function
Error:
Reference C2280 : compiler has generated 'RecvBuf::operator =' here
Caused by:
class A
{
public:
// explicit
A(){}
A(A &&){}
// implicit
A(const A&) = delete;
A& operator=(const A&) = delete;
};
Solution:
A(const A&) = default;
A& operator=(const A&) = default;
C++ Compiler Error C2280 “attempting to reference a deleted function”
https://stackoverflow.com/a/31266254/1645289
CMake Issues
No CMAKE_C_COMPILER could be found
Building error:
CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
CMake error at CMakeLists.txt:30 (project): No CMAKE_CXX_COMPILER could be found
Solution:
Mac OS:
sudo xcode-select --reset
Windows:
call "C:\Program_Filesx86\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
Reference:
https://stackoverflow.com/a/46906065/1645289
Unknown CMake command “FetchContent_Declare”
Building error:
CMake Error at CMakeLists.txt:4 (FetchContent_Declare):
Unknown CMake command “FetchContent_Declare”
Solution:
add include(FetchContent)
in CMakeLists.txt
include(FetchContent)
Origin:
https://discourse.cmake.org/t/fetchcontent-declare-not-recognized/443
error C2220: the following warning is treated as an error
Error on building:
error C2220: the following warning is treated as an error
Solution:
set C_FLAGS_WARNINGS
in CMakeLists.txt:
set(C_FLAGS_WARNINGS "/W4 /WX-")
fatal error LNK1104: cannot open file ‘kernel32.lib’
Error on building in cmake:
fatal error LNK1104: cannot open file 'kernel32.lib'
Solution:
Execute Cross Tools Command Prompt of Visual Studio firstly:
call "C:\Program_Filesx86\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
error LNK2019: unresolved external symbol _vkCreateInstance@12
Error on building using Ninja
hello_triangle.cpp.obj : error LNK2019: unresolved external symbol _vkCreateInstance@12 referenced in function "private: void __thiscall HelloTriangleApplication::createInstance(void)" (?createInstance@HelloTriangleApplication@@AAEXXZ)
hello_triangle.cpp.obj : error LNK2019: unresolved external symbol _vkDestroyInstance@8 referenced in function "private: void __thiscall HelloTriangleApplication::cleanup(void)" (?cleanup@HelloTriangleApplication@@AAEXXZ)
hello_triangle.cpp.obj : error LNK2019: unresolved external symbol _vkEnumeratePhysicalDevices@12 referenced in function "private: void __thiscall HelloTriangleApplication::pickPhysicalDevice(void)" (?pickPhysicalDevice@HelloTriangleApplication@@AAEXXZ)
Solution:
-
Visual Studio version isn’t compatible with Ninja, update ninja version.
https://github.com/ninja-build/ninja/releases -
Execute cmake command using
x64 Native Tools Command Prompt
, notx64_x86 Cross Tools Command Prompt
.
“Trying to predict the future is like trying to drive down a country road at night with no lights while looking out the back window. ” ― Peter Drucker