Visual studio 2015 c++ and assembly not building - c++

I recently wanted to start learning assembly, but I have been having some problem setting up my project to build.
What I want to have is a C++ and assembly project, but it is currently not working. My assembly code shown below builds just fine:
ExitProcess PROTO
.data
.code
main proc
mov rax, 8
mov rcx, 0
call ExitProcess
main endp
end
but the moment I add a cpp file to my project I get a load of linker errors:
void ToDo()
{
int i = 0;
}
Errors:
1>------ Build started: Project: AssemblyTest, Configuration: Debug x64 ------
1> test.cpp
1>MSVCRTD.lib(_init_.obj) : error LNK2019: unresolved external symbol _CrtDbgReport referenced in function _CRT_RTC_INIT
1>MSVCRTD.lib(_init_.obj) : error LNK2019: unresolved external symbol _CrtDbgReportW referenced in function _CRT_RTC_INITW
1>MSVCRTD.lib(_error_.obj) : error LNK2019: unresolved external symbol __stdio_common_vsprintf_s referenced in function _vsprintf_s_l
1>MSVCRTD.lib(_error_.obj) : error LNK2001: unresolved external symbol __C_specific_handler
1>MSVCRTD.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol _wmakepath_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned __int64)" (?GetPdbDllPathFromFilePath##YAHPEB_WPEA_W_K#Z)
1>MSVCRTD.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol _wsplitpath_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned __int64)" (?GetPdbDllPathFromFilePath##YAHPEB_WPEA_W_K#Z)
1>MSVCRTD.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol wcscpy_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned __int64)" (?GetPdbDllPathFromFilePath##YAHPEB_WPEA_W_K#Z)
1>MSVCRTD.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol __vcrt_GetModuleFileNameW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll##YAPEAUHINSTANCE__##XZ)
1>MSVCRTD.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol __vcrt_GetModuleHandleW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll##YAPEAUHINSTANCE__##XZ)
1>MSVCRTD.lib(_pdblkup_.obj) : error LNK2019: unresolved external symbol __vcrt_LoadLibraryExW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll##YAPEAUHINSTANCE__##XZ)
1>C:\Users\***\Desktop\AssemblyTest\x64\Debug\AssemblyTest.exe : fatal error LNK1120: 10 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Does anybody know what is wrong with my setup and how to fix it?

You're linking your project with only part of the C runtime (CRT) libary, msvcrtd.lib. You also need to link with the libraries vcruntimed.lib and ucrtd.lib. The former is part of Visual Studio 2015 itself while the later is part of the Windows 10 SDK that was installed along Visual Studio. Normally C++ projects automatically link with these libraries, but apparently your project is setup not to.
You may be following instructions meant for an older version of Visual Studio which only required linking with one CRT library file. This changed due to a refactoring of the CRT with Visual Studio 2015.

Related

Using Boost in a DLL project (ActiveX)

I'm trying to use Boost.Asio on a ActiveX DLL project using Visual Studio 2013.
Not sure what is wrong but when building these error shows up:
Error 34 error LNK2019: unresolved external symbol "class
boost::system::error_category const & __cdecl
boost::system::system_category(void)"
(?system_category#system#boost##YAABVerror_category#12#XZ) referenced
in function "public: __thiscall
boost::system::error_code::error_code(void)"
(??0error_code#system#boost##QAE#XZ) C:\eCompany\activex-dll\maindoor\RESTClient.obj maindoor
Error 35 error LNK2019: unresolved external symbol "class
boost::system::error_category const & __cdecl
boost::system::generic_category(void)"
(?generic_category#system#boost##YAABVerror_category#12#XZ) referenced
in function "void __cdecl boost::system::`dynamic initializer for
'errno_ecat''(void)"
(??__Eerrno_ecat#system#boost##YAXXZ) C:\Projects\eCompany\activex-dll\maindoor\RESTClient.obj maindoor
Error 36 error LNK1120: 2 unresolved
externals C:\Projects\eCompany\activex-dll\maindoor\Debug\maindoorEWI.dll 1 1 maindoor
I already added BOOST_ALL_NO_LIB in the Preprocessor. What could be missing in the project?
The short answer is to do something like this:
C:\local\boost_1_58_0>bjam.exe runtime-link=static
and remove BOOST_ALL_NO_LIB is its set, then build the DLL again. That should fix that.

Setting up OpenGL - it won't work

I just bought a new laptop with windows 8 64bit and I am using Visual Studio 2012.
I did the usual procedure with installing a 3d party lib just as I installed them on my previous PCs:
Download freeglut, glew, glfw, glut, sdl
Copy headers into "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include"
Copy libs into "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib"
Copy dll's into "C:\Windows\SysWOW64"
Then I downloaded the project I was developing on my other PC (was developed under windows 8 32bit if that's of any importance) and it would'n compile. The compiler threw me the following linking error:
Error 1 error LNK2001: unresolved external symbol __imp__glDrawArrays#12 - about 50 of these
Error 63 error LNK2019: unresolved external symbol __imp__glClear#4 - again about 50 of these
The project is working perfectly on my old PC.
I did try to make a simple new project: http://pastebin.com/GfEieL6f
Linked the following libraries (Properties->Linker->Input->Additional Dependencies)
opengl32.lib
glut32.lib
glu32.lib
And again it wouldn't compile, again the same linking errors:
Error 1 error LNK2019: unresolved external symbol __imp__glBegin#4 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 2 error LNK2019: unresolved external symbol __imp__glClear#4 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 3 error LNK2019: unresolved external symbol __imp__glClearColor#16 referenced in function _main P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 4 error LNK2019: unresolved external symbol __imp__glColor3f#12 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 5 error LNK2019: unresolved external symbol __imp__glEnd#0 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 6 error LNK2019: unresolved external symbol __imp__glFlush#0 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 7 error LNK2019: unresolved external symbol __imp__glLoadIdentity#0 referenced in function _main P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 8 error LNK2019: unresolved external symbol __imp__glMatrixMode#4 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 9 error LNK2019: unresolved external symbol __imp__glOrtho#48 referenced in function _main P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 10 error LNK2019: unresolved external symbol __imp__glRotatef#16 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
Error 11 error LNK2019: unresolved external symbol __imp__glVertex3iv#4 referenced in function "void __cdecl drawcube(void)" (?drawcube##YAXXZ) P:\OpenGL_Setup\OpenGL_Setup\opengl_setup.obj
I don't know if I am missing something, can you give me some ideas ?
PP: I managed to fix the simple program and run it, but I cannot run my old project. Maybe it's a problem because of the platform change ? How can I fix it?
Don't add files to the compiler lib directory. Instead add another library search path to your project.
You probably downloaded library files that aren't compatible with VC++ 2012 and your project build settings. In native code, you can't mix x86, x64, etc. Static libraries need to match your project bitness, not your OS. And Microsoft also changes/extends the library file format, as well as runtime library components used by the library, so you really should get a library file designed for your version of VC++.

Selecting a Capture Device Using the System Device Enumerator

I was tring to use this link: http://msdn.microsoft.com/en-us/library/dd377566%28v=VS.85%29.aspx, to select a capturing device.
Works perfectly on Visual Studio, but throws the following error QT:
test.obj : error LNK2005: _main already defined in main.obj
test.obj : error LNK2019: unresolved external symbol __imp__CoCreateInstance#20 referenced in function "long __cdecl EnumerateDevices(struct _GUID const &,struct IEnumMoniker * *)" (?EnumerateDevices##YAJABU_GUID##PAPAUIEnumMoniker###Z)
test.obj : error LNK2019: unresolved external symbol __imp__VariantClear#4 referenced in function "void __cdecl DisplayDeviceInformation(struct IEnumMoniker *)" (?DisplayDeviceInformation##YAXPAUIEnumMoniker###Z)
test.obj : error LNK2019: unresolved external symbol __imp__VariantInit#4 referenced in function "void __cdecl DisplayDeviceInformation(struct IEnumMoniker *)" (?DisplayDeviceInformation##YAXPAUIEnumMoniker###Z)
test.obj : error LNK2019: unresolved external symbol __imp__CoUninitialize#0 referenced in function _main
test.obj : error LNK2019: unresolved external symbol __imp__CoInitializeEx#8 referenced in function _main
I'm using windows 7 & QT 5.0.2.
Any help will be appreciated thanks.
Searching for "cocreateinstance unresolved external" on google and using the first link returned:
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/5fc032e1-86d8-43c7-870b-f10599000605/
I spotted the third comment that indicates to link against "ole32.lib".
Your reply to my comment above indicates that "oleAut32.lib" is also required.
Also make sure to link against "strmiids.lib".
To sum up, required libraries are:
ole32.lib
oleaut32.lib
strmiids.lib

How to use lacewing project

I am a newbie to C++. I want to use, lacewing-project.org in my C++ project. I read the documentation on how to build it and successfully did it using both DLL - Release and Static Library - Release configurations.
Now I don't know how to use this in my project and how to setup and configure my project? I was following this tutorial, but was stuck in the middle because of missing options in the latest Visual Studio. I use Visual C++ Expression Ed., 2012 on Windows 8
I googled and did the following:
Added the lib file and the lacewing.h file in my project.
Under Visual C++ Project Properties, in the Linker folder -> Input I added the lib file as Additional Dependencies.
I placed the dll in Windows\System32 folder. Will I need to do anything with the dll other than placing it in win32 folder?
My code is from the hello world example given in the documentation.
When I try to compile I get:
1>------ Build started: Project: test, Configuration: Debug Win32 ------
1> Source.cpp
1>Source.obj : error LNK2019: unresolved external symbol __imp__lw_version referenced in function "void __cdecl on_get(struct lacewing::_webserver *,struct lacewing::_webserver_request *)" (?on_get##YAXPAU_webserver#lacewing##PAU_webserver_request#2##Z)
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl lacewing::pump_delete(struct lacewing::_pump *)" (__imp_?pump_delete#lacewing##YAXPAU_pump#1##Z) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: struct lacewing::_error * __thiscall lacewing::_eventpump::start_eventloop(void)" (__imp_?start_eventloop#_eventpump#lacewing##QAEPAU_error#2#XZ) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) struct lacewing::_eventpump * __cdecl lacewing::eventpump_new(void)" (__imp_?eventpump_new#lacewing##YAPAU_eventpump#1#XZ) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl lacewing::_stream::writef(char const *,...)" (__imp_?writef#_stream#lacewing##QAAXPBDZZ) referenced in function "void __cdecl on_get(struct lacewing::_webserver *,struct lacewing::_webserver_request *)" (?on_get##YAXPAU_webserver#lacewing##PAU_webserver_request#2##Z)
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall lacewing::_webserver::host(long)" (__imp_?host#_webserver#lacewing##QAEXJ#Z) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall lacewing::_webserver::on_get(void (__cdecl*)(struct lacewing::_webserver *,struct lacewing::_webserver_request *))" (__imp_?on_get#_webserver#lacewing##QAEXP6AXPAU12#PAU_webserver_request#2##Z#Z) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) struct lacewing::_webserver * __cdecl lacewing::webserver_new(struct lacewing::_pump *)" (__imp_?webserver_new#lacewing##YAPAU_webserver#1#PAU_pump#1##Z) referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl lacewing::webserver_delete(struct lacewing::_webserver *)" (__imp_?webserver_delete#lacewing##YAXPAU_webserver#1##Z) referenced in function _main
1>C:\Users\Jayarathina\Desktop\New folder (3)\test\Debug\test.exe : fatal error LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please help...
To link statically with the library, one must define lw_import. If you don't do this, it will default to __declspec(dllimport):
#ifndef lw_import
#define lw_import __declspec (dllimport)
#endif
which causes the linker to try and pull the functions in from a DLL (which is wrong when statically linking). To do this, you can either add lw_import= to your preprocessor definitions in the project properties, or #define it before including lacewing.h, as so:
#define lw_import
#include <lacewing.h>
As you're statically linking the library, you will also need to link any library dependencies into your own project. You can find the list in the project properties of liblacewing.vcproj itself, but as of 0.5.1 these are ws2_32.lib, mswsock.lib, mpr.lib, secur32.lib and crypt32.lib.

unresolved external symbol in eclipse cdt

I try to build cpp file using eclipse cdt. Linker throws "unresolved external symbol", however path to lib file that contains implementation for function is listed in LIB environment variable on Project properties->C/C++ Build->Environment
What am I doing wrong?
UPD I try to build file. There is lib RpcRT4.Lib on the path C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\
And linker fails:
**** Build of configuration Debug for project test cpp ****
**** Internal Builder is used for build ****
link /debug /nologo /OUT:test cpp.exe main.obj
main.obj : error LNK2019: unresolved external symbol __imp__RpcStringFreeA#4 referenced in function "bool __cdecl Initialize_CreateWindowClass(void)"(?Initialize_CreateWindowClass##YA_NXZ)
main.obj : error LNK2019: unresolved external symbol __imp__RegisterClassA#4 referenced in function "bool __cdecl Initialize_CreateWindowClass(void)" (?Initialize_CreateWindowClass##YA_NXZ)
main.obj : error LNK2019: unresolved external symbol __imp__UuidToStringA#8 referenced in function "bool __cdecl Initialize_CreateWindowClass(void)" (?Initialize_CreateWindowClass##YA_NXZ)
main.obj : error LNK2019: unresolved external symbol __imp__UuidCreate#4 referenced in function "bool __cdecl Initialize_CreateWindowClass(void)" (?Initialize_CreateWindowClass##YA_NXZ)
main.obj : error LNK2019: unresolved external symbol __imp__DefWindowProcA#16 referenced in function "long __stdcall SkypeAPITest_Windows_WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?SkypeAPITest_Windows_WindowProc##YGJPAUHWND__##IIJ#Z)
main.obj : error LNK2019: unresolved external symbol __imp__PostQuitMessage#4 referenced in function "long __stdcall SkypeAPITest_Windows_WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?SkypeAPITest_Windows_WindowProc##YGJPAUHWND__##IIJ#Z)
main.obj : error LNK2019: unresolved external symbol __imp__UnregisterClassA#8 referenced in function "void __cdecl DeInitialize_DestroyWindowClass(void)" (?DeInitialize_DestroyWindowClass##YAXXZ)
main.obj : error LNK2019: unresolved external symbol __imp__CreateWindowExA#48 referenced in function "bool __cdecl Initialize_CreateMainWindow(void)" (?Initialize_CreateMainWindow##YA_NXZ)
main.obj : error LNK2019: unresolved external symbol __imp__DestroyWindow#4 referenced in function "void __cdecl DeInitialize_DestroyMainWindow(void)" (?DeInitialize_DestroyMainWindow##YAXXZ)
main.obj : error LNK2019: unresolved external symbol __imp__DispatchMessageA#4 referenced in function "void __cdecl Global_MessageLoop(void)" (?Global_MessageLoop##YAXXZ)
main.obj : error LNK2019: unresolved external symbol __imp__TranslateMessage#4 referenced in function "void __cdecl Global_MessageLoop(void)" (?Global_MessageLoop##YAXXZ)
main.obj : error LNK2019: unresolved external symbol __imp__GetMessageA#16 referenced in function "void __cdecl Global_MessageLoop(void)" (?Global_MessageLoop##YAXXZ)
main.obj : error LNK2019: unresolved external symbol __imp__PostMessageA#16 referenced in function "void __cdecl Global_InputProcessingThread(void *)" (?Global_InputProcessingThread##YAXPAX#Z)
main.obj : error LNK2019: unresolved external symbol __imp__SendMessageA#16 referenced in function "void __cdecl Global_InputProcessingThread(void *)" (?Global_InputProcessingThread##YAXPAX#Z)
main.obj : error LNK2019: unresolved external symbol __imp__RegisterWindowMessageA#4 referenced in function _main
test cpp.exe : fatal error LNK1120: 15 unresolved externals
Build error occurred, build is stopped
Time consumed: 2438 ms.
And environment settings for project
I'm not entirely clear on whether you've already done this based on the question, but just adding the directory to your linker's search path isn't enough for any compiler/linker I've ever used. There could be hundreds of different libraries in there, even different versions of the same library, and the linker has no idea which ones you do and don't want. You need to tell it, explicitly, to link against the library using the appropriate parameter.
It looks like you're using the Microsoft linker, which I've never used, so I can't help you with the specific flag but it should be easy enough to find what it is in the documentation if that's the issue. I presume Eclipse has a method of specifying this in the GUI as well which should be generic across the various compilers it supports.