Unresolved External Symbol? error lnk2019 - external

I was wondering if anyone knew what this error meant.
Thanks
error LNK2019: unresolved external symbol "public: void __thiscall LinkedList,class std::allocator > >::LocItem *>::decreasekey(class PriorityList,class std::allocator > >::LocItem * const &)" (?decreasekey#?$LinkedList#HPAVLocItem#?$PriorityList#HV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std######QAEXABQAVLocItem#?$PriorityList#HV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std#####Z) referenced in function "public: void __thiscall PriorityList,class std::allocator > >::decreasekey(class PriorityList,class std::allocator > >::Locator)" (?decreasekey#?$PriorityList#HV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std####QAEXVLocator#1##Z)

It simply means there is a symbol that was not defined. Check your spelling and make sure it exists and is defined in your code.
MSDN Help page

Related

exposing nonstatic member function of class to chaiscript

I have a project that tries to implement keyboard macro scripting with chaiscript. I am writing a class based on xlib to wrap the xlib code.
I have a member function to add a modifier key to an ignored list, because of a xlib quirk.
how could i do something like the following minimal example.
#include <chaiscript/chaiscript.hpp>
#include <functional>
class MacroEngine{
public:
MacroEngine() = default;
//...
void addIgnoredMod(int modifier){
ignoredMods |= modifier;
}
//...
private:
int ignoredMods;
};
int main(int argc, char *argv[]){
MacroEngine me;
chaiscript::ChaiScript chai;
//...
chai.add(chaiscript::fun(std::bind(&MacroEngine::addIgnoredMod, me, std::placeholders::_1)), "setIgnoredMods");
//...
return 0;
}
I tried bind and failed with the following error message:
In file included from ../deps/ChaiScript/include/chaiscript/dispatchkit/proxy_functions_detail.hpp:24:0,
from ../deps/ChaiScript/include/chaiscript/dispatchkit/proxy_functions.hpp:27,
from ../deps/ChaiScript/include/chaiscript/dispatchkit/proxy_constructors.hpp:14,
from ../deps/ChaiScript/include/chaiscript/dispatchkit/dispatchkit.hpp:34,
from ../deps/ChaiScript/include/chaiscript/chaiscript_basic.hpp:12,
from ../deps/ChaiScript/include/chaiscript/chaiscript.hpp:823,
from ../src/main.cpp:2:
../deps/ChaiScript/include/chaiscript/dispatchkit/callable_traits.hpp: In instantiation of ‘struct chaiscript::dispatch::detail::Callable_Traits<std::_Bind<void (MacroEngine::*(MacroEngine, std::_Placeholder<1>))(unsigned int)> >’:
../deps/ChaiScript/include/chaiscript/language/../dispatchkit/register_function.hpp:45:72: required from ‘chaiscript::Proxy_Function chaiscript::fun(const T&) [with T = std::_Bind<void (MacroEngine::*(MacroEngine, std::_Placeholder<1>))(unsigned int)>; chaiscript::Proxy_Function = std::shared_ptr<chaiscript::dispatch::Proxy_Function_Base>]’
../src/main.cpp:21:95: required from here
../deps/ChaiScript/include/chaiscript/dispatchkit/callable_traits.hpp:99:84: error: decltype cannot resolve address of overloaded function
typedef typename Function_Signature<decltype(&T::operator())>::Signature Signature;
^~~~~~~~~
../deps/ChaiScript/include/chaiscript/dispatchkit/callable_traits.hpp:100:86: error: decltype cannot resolve address of overloaded function
typedef typename Function_Signature<decltype(&T::operator())>::Return_Type Return_Type;
^~~~~~~~~~~
I also tried to make the variable static which worked, but it wont work if I try to make it possible to ignore modifiers on a per hotkey basis.
what am i doing wrong? and how can I fix it?
You can do this instead:
chai.add(chaiscript::fun(&MacroEngine::addIgnoredMod, &me), "addIgnoredMod");
Or use a lambda:
chai.add(chaiscript::fun([&me](int modifier){ me.addIgnoredMod(modifier); }), "addIgnoredMod");
Jason Turner, the creator of Chaiscript, commented on it here: http://discourse.chaiscript.com/t/may-i-use-std-bind/244/4
"There’s really never any good reason to use std::bind. I much better solution is to use a lambda (and by much better, I mean much much better. std::bind adds to compile size, compile time and runtime)."

Error when calling static method c++

Consider the following code:
Automobile.h
class Automobile
{
static string m_stCityCode;
static bool CheckCityCode(const Automobile& obj);
};
Automobile.cpp
bool Automobile::CheckCityCode(const Automobile& obj)
{
return m_stCityCode == obj.m_stCityCode;
}
int main()
{
//do something
}
I get the following error
"Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "public: static class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > Automobile::m_stCityCode"
(?m_stCityCode#Automobile##2V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##A) myPro C:\Users\zhivko.rusev\Documents\Visual
Studio 2015\Projects\myPro\myPro\Calls.obj 1 "
I would appreciate every help for solving this problem. Thanks in advance!
The static member needs to be defined. The error message is the linker's way of telling you it isn't. Your code declares the static member but does not define it.
To define it, in a single compilation unit (i.e. a non-header source file) simply add a line at file scope after including the header file
#include "Automobile.h"
std::string Automobile::m_stCityCode = ""; // change the initialiser to whatever suits
Do this in exactly one compilation unit. One is necessary to define the symbols. Multiple definitions (e.g. in multiple source files within your project) will cause the linker to complain about symbols being defined multiple times.
There are other problems in your code as shown, beyond what you have asked about, but I'll assume that just reflects you having left information out.

Flash Namespace error 1004: Namespace was not found or is not a compile-time constant

I have a class: myClass_x.as with contents:
package com.a.b.c
{
public namespace myClass_x = "com.a.b.c:myClass_x";
}
I have a second class: myClass_y with function:
myClass_x function myFunction(param1:int, param2:int, param3:int) : void {...}
I have a third class: myClass_z with function:
override myClass_x function myFunction(param1:int, param2:int, param3:int) : void {...}
When I try to compile, I get error:
1004: Namespace was not found or is not a compile-time constant.
Any ideas what's going wrong?
Are you sure you've imported the namespace at the top of each class?
import com.a.b.c.myClass_x;
You can also get your error if the filename does not exactly match the namespace name.
Above your class block add the line use namespace myClass_x;

Renaming C struct properties using SWIG %apply

I have the below structure in my SWIG interface file and thusly my sample.h header file. I'm assuming the sockaddr, ios_boolean and unsigned char definitions from this structure are the reason why I get the below generated classes. If I know the type on that ios_boolean and unsigned char map to on the Java side is there a way to use an %apply to get rid of the generated pointer classes? I tried %apply int {ios_boolean}; but then I get a SWIGTYPE_p_boolean.java. Any ideas?
%rename (Sample) sample_details_t_;
typedef struct sample_details_t_ {
ios_boolean is_allowed;
unsigned char mac[11];
} sample_t;
generates:
SWIGTYPE_p_unsigned_char.java
SWIGTYPE_p_ios_boolean.java
Exception:
[exec] ewapi_wrap.c:982: error: `true' undeclared (first use in this function)
[exec] ewapi_wrap.c:982: error: (Each undeclared identifier is reported only once
[exec] ewapi_wrap.c:982: error: for each function it appears in.)
[exec] ewapi_wrap.c:982: error: `false' undeclared (first use in this function
You probably want to do something like:
%include <arrays_java.i>
%rename (Sample) sample_details_t_;
%apply bool { ios_boolean };
typedef struct sample_details_t_ {
ios_boolean is_allowed;
unsigned char mac[11];
} sample_t;
This wraps mac as short[] (with constraints on the array size) and is_allowed as boolean on the Java side and results in these files:
Sample.java test.java testJNI.java
Make sure you delete any old SWIGTYPE_*.java files that are lying around from older versions of your SWIG interface, they won't get deleted automatically and might fail to compile if you do something like javac *.java.

C++ Calling Static member function from external file

I have this class defined in Global.h
class Global
{
public:
static string InttoStr(int num);
};
In Global.cpp, i have
Global::InttoStr(int num)
{
//Code To convert integer into string.
}
Now, from SubMove.cpp, when i call Global::InttoStr(num) I get following error:
error LNK2019: unresolved external symbol Global::InttoStr(int) referenced in function SubMove::toString(void)
Then I made the function non-static and called it like so:
Global g;
g.InttoStr(num);
But the error still persists.
I thought it had something to do with extern and searched it but i could not make any connection. Please help.
First off, try this:
string Global::InttoStr(int num)
{
//Code To convert integer into string.
}
Also, are you calling InttoStr from another library ? If so, you'll need to export the class "Global".
Best practice is to use a lib header (in the example below replace LIB_ with the name of the library):
#ifndef SOME_LIB_HEADER
#define SOME_LIB_HEADER
#if defined (LIB_EXPORTS)
#define LIB_API __declspec(dllexport)
#else
#define LIB_API __declspec(dllimport)
#endif // SOME_LIB_HEADER
Define LIB_EXPORTS in your project contianing Global, include the lib header in Global.h, then define the class like this
class LIB_API Global
{
// some code for the class definition
};
Each project should have its own LIB_EXPORTS and LIB_API definition like DLL1_EXPORTS, DLL1_API, DLL2_EXPORTS, DLL2_API etc.
Basically this makes a separate lib treat the previous dll with __declspec(dllimport) and resolve all externs.