hey guys i am working on an application and i removed the CRT to save alot of space in the executable and making it as small as possible :) the thing is that when i removed the CRT i also received tons of errors on unresolved external and i was able to remove most of them just by adding a few operators like these:
void * __cdecl operator new(unsigned int bytes) {
return HeapAlloc(GetProcessHeap(), 0, bytes);
}
void __cdecl operator delete(void *ptr) {
if(ptr) HeapFree(GetProcessHeap(), 0, ptr);
}
extern "C" int __cdecl __purecall(void) {
return 0;
}
extern "C" const DWORD_PTR __security_cookie = 0xE64EBB40;
extern "C" void __fastcall __security_check_cookie(DWORD_PTR cookie) {
if (cookie != __security_cookie)
__asm int 3;
}
but now i am stuck with the last three errors and i have no clue on how to solve them, and one that i am really curious of is the _memmove error ? i am not using the memmove operator anywhere in my code so i have not clue why i am receiving it :P
atleast here are the errors, i would be very greatefull for your answers.
Error 2 error LNK2001: unresolved external symbol "void __cdecl std::_Xbad_alloc(void)" (?_Xbad_alloc#std##YAXXZ) C:\Users\Fluttershy!\documents\visual studio 2012\Projects\PincelStub\PincelStub\PincelStub.obj
Error 3 error LNK2001: unresolved external symbol "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error#std##YAXPBD#Z) C:\Users\Fluttershy!\documents\visual studio 2012\Projects\PincelStub\PincelStub\PincelStub.obj
Error 4 error LNK2001: unresolved external symbol _memmove C:\Users\Fluttershy!\documents\visual studio 2012\Projects\PincelStub\PincelStub\PincelStub.obj
VC++ probably uses those internally (the first two to signal for error conditions and _memmove, well, to move memory blocks around in plain old struct assignments, for instance). The first two, I would just define as {}, but as for the last, I would try fiddling with optimization options (something about "intrinsic functions" etc.) or reimplement it fully (not just stub it).
I'm not sure why you want to shoot yourself in the leg, but whatever. The source of the CRT sits there, so you can just search it for the missing stuff and copy. the memmove function should be obvious. The other two looks like connected to standard exceptions.
Related
I normally work in c# and am out of my wits for this one . I used Walkthrough: Creating and Using a Dynamic Link Library (C++) to create a Dynamic Link Library.
I have defined two methods as shown below
DeveloperConsoleManager.h
#pragma once
#include "atlstr.h"
#ifdef DEVCONSOLEMANAGER_EXPORTS
#define DEVCONSOLEMANAGER_API __declspec(dllexport)
#else
#define DEVCONSOLEMANAGER_API __declspec(dllimport)
#endif
namespace DeveloperConsoleManager
{
class DeveloperConsoleLogic
{
public:
// Returns a + b
static DEVCONSOLEMANAGER_API double Add(double a, double b);
static DEVCONSOLEMANAGER_API bool CheckforValidFile(CString fileName);
};
}
DeveloperConsoleManager.cpp
// DeveloperConsoleManager.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "DeveloperConsoleManager.h"
namespace DeveloperConsoleManager
{
double DeveloperConsoleLogic::Add(double a, double b)
{
return a + b;
}
bool DeveloperConsoleLogic :: CheckforValidFile(CString fileName)
{
return false;
}
}
I use these methods in a .cpp file in a different project (type: Application (.exe)). When I Build the solution, there are following linker errors
Warning 1 warning C4273: 'DeveloperConsoleManager::DeveloperConsoleLogic::Add' : inconsistent dll linkage e:\md_69\developerconsolemanager\developerconsolemanager.cpp 10
Warning 2 warning C4273: 'DeveloperConsoleManager::DeveloperConsoleLogic::CheckforValidFile' : inconsistent dll linkage e:\md_69\developerconsolemanager\developerconsolemanager.cpp 16
Error 3 error LNK2028: unresolved token (0A0004F1) "public: static bool __cdecl DeveloperConsoleManager::DeveloperConsoleLogic::CheckforValidFile(class ATL::CStringT > >)" (?CheckforValidFile#DeveloperConsoleLogic#DeveloperConsoleManager##$$FSA_NV?$CStringT#_WV?$StrTraitMFC_DLL#_WV?$ChTraitsCRT#_W#ATL#####ATL###Z) referenced in function "public: void __thiscall CSaSsiConsoleUi::UploadSsiCheck(void)" (?UploadSsiCheck#CSaSsiConsoleUi##$$FQAEXXZ) E:\MD_69\DeveloperConsoleUI\SaSsiConsoleUI.obj
Error 4 error LNK2019: unresolved external symbol "public: static bool __cdecl DeveloperConsoleManager::DeveloperConsoleLogic::CheckforValidFile(class ATL::CStringT > >)" (?CheckforValidFile#DeveloperConsoleLogic#DeveloperConsoleManager##$$FSA_NV?$CStringT#_WV?$StrTraitMFC_DLL#_WV?$ChTraitsCRT#_W#ATL#####ATL###Z) referenced in function "public: void __thiscall CSaSsiConsoleUi::UploadSsiCheck(void)" (?UploadSsiCheck#CSaSsiConsoleUi##$$FQAEXXZ) E:\MD_69\DeveloperConsoleUI\SaSsiConsoleUI.obj
Error 5 error LNK1120: 2 unresolved externals E:\MD_69\Debug\DeveloperConsoleUi.exe
There is no linker error for the "Add" method.
I have already included "DeveloperConsoleManager.lib" in Linker -> Input -> Additional Dependencies. Please help me find out what exactly am I doing wrong.
I would be glad to add any additional information needed.
Thanks to #Igor Tandetnik and the awesome thing that is internet, I figured it out. I am adding it as an answer so that some one else might benefit.
The problem was with CString. The project in which the function was defined was a dynamic link library (dll) and the call was being made from an MFC application. Now, the issue was that, MFC uses for CString while the non-MFC dll uses .
CString in is defined as:
typedef ATL::CStringT< TCHAR, StrTraitMFC_DLL< TCHAR > > CString;
while in is defined as:
typedef CStringT< TCHAR, StrTraitATL< TCHAR > > CString;
This, as you can clearly see is different. The workaround I used was using CAtlString instead of CString . However, please feel free to suggest any better way if you come across.
After removing the CRT from my DLL I have gotten these weird errors.
Here are they:
LNK2001 unresolved external symbol "void __cdecl std::_Xbad_alloc(void)" (?_Xbad_alloc#std##YAXXZ)
LNK2001 unresolved external symbol "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error#std##YAXPBD#Z)
LNK2001 unresolved external symbol "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range#std##YAXPBD#Z)
unresolved external symbol __dtest
unresolved external symbol __fdtest
unresolved external symbol __invalid_parameter)noinfo_noreturn
unresolved external symbol __stdio_common_vsnprintf_s
unresolved external symbol __stdio_common_vsprintf
unresolved external symbol __std_terminate
If I understand correctly the Xbad_alloc and Xlength_error are because of the new and delete operators? In that case I create my class instance like this:
class sc_Core
{
public:
static sc_Core *Instance(void);
func A();
public:
void *operator new(size_t si)
{
return HeapAlloc(GetProcessHeap(), NULL, si);
}
void operator delete(void *pv) throw()
{
HeapFree(GetProcessHeap(), NULL, pv);
}
private:
sc_Core(void) { }
~sc_Core(void) { }
sc_Core(const sc_Core&) { }
sc_Core(sc_Core&&) {}
sc_Core& operator=(const sc_Core&) {}
sc_Core& operator=(sc_Core&&) {}
static sc_Core *p_Instance;
};
// Global Scope
sc_Core *sc_Core::p_Instance = nullptr;
sc_Core *sc_Core::Instance(void)
{
if (p_Instance == nullptr)
p_Instance = new sc_Core();
return p_Instance;
}
If anyone knows how these occur or how I can fix them it would be very much appreciated!
There's nothing weird about those errors.
Compilers are allowed to assume that they can generate code that rely on their runtime libraries. If you're going omit the runtime library at the link step, then you'll have to provide definitions for the missing symbols in your own code.
Turning off certain compiler features may reduce the number of missing symbols. You could try, for example, turning off exception handling support to see if the internal exception classes are still expected. In debug builds, the compiler may expect even more support from the runtime that in release builds.
I'm trying to get started with C++ but I keep getting this error. I know which parts of my code is generating it, but I think that at least one these parts shouldn't generate them.
I am creating a class called Text that is functioning in a way similar to the std::string class, just to experiment and get a better understanding of value semantics.
Anyhow, these are my files:
Text.h:
#ifndef TEXT
#define TEXT
class Text {
public:
Text(const char *str);
Text(const Text& other);
void operator=(const Text& other);
~Text();
private:
int size;
char* cptr;
};
#endif
Text.cpp:
#include "Text.h"
#include <cstring>
#include <iostream>
using namespace std;
Text::Text(const char* str) {
size = strlen(str) + 1;
cptr = new char[size];
strcpy(cptr, str);
}
Text::Text(const Text& other) {
size = other.size;
cptr = new char[size];
strcpy(cptr, str);
}
void Text::operator=(const Text& other){
delete [] cptr;
size = other.size;
cptr = new char[size];
strcpy(cptr, other.ctpr);
}
Text::~Text() {
delete [] cptr;
}
Main.cpp:
#include <iostream>
#include "Text.h"
using namespace std;
Text funk(Text t) {
// ...
return t;
}
int main() {
Text name("Mark");
Text name2("Knopfler");
name = funk(name);
name = name2;
return 0;
}
So what's causing the error is the function funk, and the first two lines in the main function. I get why it's complaining on the first two lines in the main function, because there are no function called "name" or "name2". But what I'm trying to do is declaring and initialize an object in one line (I'm and old Java guy :p), is this even possible in C++? I can't find anything online indicating this.
The funny thing is that this code is more or less copied from some code my lecturer executes just fine during a lecture. And he has certainly not declared any functions named "name" and "name2" either. Any reasonable explanation for this?
But why is the function funk generating this error as well? All I am doing is returning a copy of the object that I'm sending in.
Thanks in advance!
Edit: Here comes the full error messages. There are five of them. "SecondApplication" is the name of my project.
Error 1 error LNK2019: unresolved external symbol "public: __thiscall Text::Text(char const *)" (??0Text##QAE#PBD#Z) referenced in function _main C:\Users\XXX\Documents\Visual Studio 2013\Projects\SecondApplication\SecondApplication.obj SecondApplication
Error 2 error LNK2019: unresolved external symbol "public: __thiscall Text::Text(class Text const &)" (??0Text##QAE#ABV0##Z) referenced in function "class Text __cdecl funk(class Text)" (?funk##YA?AVText##V1##Z) C:\Users\XXX\Documents\Visual Studio 2013\Projects\SecondApplication\SecondApplication.obj SecondApplication
Error 3 error LNK2019: unresolved external symbol "public: void __thiscall Text::operator=(class Text const &)" (??4Text##QAEXABV0##Z) referenced in function _main C:\Users\XXX\Documents\Visual Studio 2013\Projects\SecondApplication\SecondApplication.obj SecondApplication
Error 4 error LNK2019: unresolved external symbol "public: __thiscall Text::~Text(void)" (??1Text##QAE#XZ) referenced in function "class Text __cdecl funk(class Text)" (?funk##YA?AVText##V1##Z) C:\Users\XXX\Documents\Visual Studio 2013\Projects\SecondApplication\SecondApplication.obj SecondApplication
Error 5 error LNK1120: 4 unresolved externals C:\Users\XXX\Documents\Visual Studio 2013\Projects\SecondApplication\Debug\SecondApplication.exe 1 1 SecondApplication
You'll get the link errors (not compilation errors) that you see if you, for instance, forget to add "Text.cpp" to your project so it doesn't get compiled and linked.
There are two errors in the code - one is in the copy constructor, and one is in the assignment operator.
Since the compiler didn't complain about the two errors, I suspect you forgot to add the file to the project.
So I've been trying to fix a weird bug in a game engine SDK where the Windows loading cursor is used instead of the game's own cursor.
The fix for this is here: http://www.crydev.net/wiki/index.php/Use_Custom_Cursor#Step_1:_Fixing_The_Cursor_Bug.
I have followed the fix, but I keep getting these when building the game DLL:
Error 1 error LNK2019: unresolved external symbol "public: __thiscall MODCursor::MODCursor(void)" (??0MODCursor##QAE#XZ) referenced in function "public: __thiscall CGame::CGame(void)" (??0CGame##QAE#XZ) C:\Users\User\Desktop\Crytek\Mods\CryEngine2\Code\Game.obj GameDll
Error 2 error LNK2019: unresolved external symbol "public: __thiscall MODCursor::~MODCursor(void)" (??1MODCursor##QAE#XZ) referenced in function "public: virtual __thiscall CGame::~CGame(void)" (??1CGame##UAE#XZ) C:\Users\User\Desktop\Crytek\Mods\CryEngine2\Code\Game.obj GameDll
Yeah, normally I can fix this issue quite easily by defining the class properly, but it hasn't worked in this case. What can I be doing wrong?
The files are as they are in the guide for the fix, so there isn't really any point in posting the files here since they would be a waste of space on here. If the files are really needed to investigate this issue, I'll upload them if anyone requests them.
Perhaps there's an error within the fix itself? One possible difference from the fix to my build is that the fix is using Visual Studio 2008, I am using Visual Studio 2013.
Maybe try to put it all inside .h file:
#ifndef _MOD_CURSOR
#define _MOD_CURSOR
#include <windows.h>
#include "resource.h"
#undef GetUserName // This is a macro in windows.h, gives issues with GetUserName() of ISystem
class MODCursor : public ISystemEventListener
{
public:
MODCursor() {
gEnv->pSystem->GetISystemEventDispatcher()->RegisterListener(this);
m_cursor = LoadCursor((HINSTANCE)g_hInst, MAKEINTRESOURCE(IDC_CURSOR1));
SetCursor(m_cursor);
}
~MODCursor(){
gEnv->pSystem->GetISystemEventDispatcher()->RemoveListener(this);
}
private:
virtual void OnSystemEvent( ESystemEvent event,UINT_PTR wparam,UINT_PTR lparam ) {
if(event == ESYSTEM_EVENT_TOGGLE_FULLSCREEN || event == ESYSTEM_EVENT_RESIZE || event == ESYSTEM_EVENT_CHANGE_FOCUS){
if (m_cursor != GetCursor())
SetCursor(m_cursor);
}
}
HCURSOR m_cursor;
};
#endif
I have this piece of code (file luascript.cpp):
bool LuaInterface::initState()
{
m_luaState = luaL_newstate();
if(!m_luaState)
return false;
luaL_openlibs(m_luaState);
#ifdef __LUAJIT__
luaJIT_setmode(m_luaState, 0, LUAJIT_MODE_ENGINE | LUAJIT_MODE_ON);
#endif
registerFunctions();
if(!loadDirectory(getFilePath(FILE_TYPE_OTHER, "lib/"), false, true))
std::clog << "[Warning - LuaInterface::initState] Cannot load " << getFilePath(FILE_TYPE_OTHER, "lib/") << std::endl;
lua_newtable(m_luaState);
lua_setfield(m_luaState, LUA_REGISTRYINDEX, "EVENTS");
m_runningEvent = EVENT_ID_USER;
return true;
}
the declaration (file luajit.h):
LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode);
and the error is:
1>luascript.obj : error LNK2019: unresolved external symbol _luaJIT_setmode referenced in function "public: virtual bool __thiscall LuaInterface::initState(void)" (?initState#LuaInterface##UAE_NXZ)
1>C:\Users\GUIAKI\Documents\trunk.r5918\vc10\Debug\tfs.exe : fatal error LNK1120: 1 unresolved externals
How can I solve it?
Simply remove that line.
You can't link against plain Lua, if you keep it. And if you link against LuaJIT, the JIT compiler is enabled by default, anyway. That line of code is utterly pointless.
Seems like you forgot to link the library being part of "luaJIT" (never heard of it or used it).
There should be a lib file you'll have to add to your project as an additional dependency (linker settings).
Also keep in mind to include the correct headers ("lua.hpp" for C++, "luajit.h" for C).