unresolved external errors - c++

I have the following .h and .cpp files
If i have to I will include the full codes of the function definitions
When i compile my program i get the errors shown at the end
hash.h
#define BUCKETS 64
#define B_ENTRIES 50000
int curr_tanker;
typedef unsigned long int ulong;
typedef struct bucket
{
int bucket_id;
ulong bucket_entries;
}bucket;
typedef struct tanker_record
{
ulong tanker_id;
ulong tanker_size;
ulong num_of_entries;
ulong bucket_entry_count;
}tanker_record;
typedef struct fpinfo
{
unsigned long chunk_offset;
unsigned long chunk_length;
unsigned char fing_print[33];
}fpinfo;
struct fpinfo* InitHTable(fpinfo *);
int CreateTanker(tanker_record tr[]);
int Hash_CreateEntry(struct fpinfo *,struct fpinfo he,tanker_record tr);
ht.cpp
#include <stdlib.h>
#include <string.h>
#include<stdio.h>
#include <iostream>
#include "ht.h"
struct fpinfo* InitHTable(struct fpinfo ht[][B_ENTRIES])
{
}
int CreateTanker(tanker_record tr[])
{
}
int
Hash_CreateEntry(struct fpinfo *t[][B_ENTRIES],struct fpinfo he,tanker_record tr[])
{
}
static void
WriteHTtoFile(struct fpinfo *t[][B_ENTRIES],int this_tanker)
{
}
main.cpp
#include<iostream>
#include"ht.cpp"
#include<conio.h>
#include<stdlib.h>
void main(int argc, char **argv)
{
static fpinfo hash_table[BUCKETS][B_ENTRIES];
static tanker_record tr[100];
InitHTable(&hash_table[0][0]);
CreateTanker(tr);
struct fpinfo fp;
...
ar = Hash_CreateEntry(&hash_table[0][0], fp,tr[0]);
i get the following errors when i try to compile it using vc2010
1>main.obj : error LNK2005: "struct fpinfo * __cdecl InitHTable(struct fpinfo (* const)[50000])" (?InitHTable##YAPAUfpinfo##QAY0MDFA#U1##Z) already defined in ht.obj
1>main.obj : error LNK2005: "int __cdecl CreateTanker(struct tanker_record * const)"
(?CreateTanker##YAHQAUtanker_record###Z) already defined in ht.obj
1>main.obj : error LNK2005: "int __cdecl Hash_CreateEntry(struct fpinfo * (* const)[50000],struct fpinfo,struct tanker_record * const)" (?Hash_CreateEntry##YAHQAY0MDFA#PAUfpinfo##U1#QAUtanker_record###Z) already defined in ht.obj
1>main.obj : error LNK2005: "int curr_tanker" (?curr_tanker##3HA) already defined in ht.obj
1>main.obj : error LNK2019: unresolved external symbol "int __cdecl Hash_CreateEntry(struct fpinfo *,struct fpinfo,struct tanker_record)"
(?Hash_CreateEntry##YAHPAUfpinfo##U1#Utanker_record###Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "struct fpinfo * __cdecl InitHTable(struct fpinfo *)" (?InitHTable##YAPAUfpinfo##PAU1##Z) referenced in function _main
THANKS FOR YOUR HELP!!

You're including ht.cpp from main.cpp, which will include all the definitions of functions already defined in ht.cpp itself.
You want to include ht.h instead.
It won't help in this situation, but you should also protect the header file with include guards:
#ifndef HT_H
#define HT_H
// contents of ht.h
#endif
You also need the arguments of the function declarations to match those of the definitions:
struct fpinfo* InitHTable(struct fpinfo[][B_ENTRIES]);
// Missing: ^^^^^^^^^^^
int CreateTanker(tanker_record tr[]); // OK
int Hash_CreateEntry(struct fpinfo*[][B_ENTRIES],struct fpinfo,tanker_record[]);
// Missing ^^^^^^^^^^^^^ ^^

Add an "include guard" in your header, so that it its contents aren't "seen" twice after preprocessing. For Microsoft, #pragma once at the beginning of the .h file. In general, add:
#ifndef __YOUR_HEADER_H
#define __YOUR_HEADER_H
// all the stuff from the header here
#endif
Make sure to adopt a consistent "unique" naming scheme for each of your headers. __YOUR_HEADER_H would do, for example customio.h into __CUSTOM_IO_H.

Related

Unresolved external symbol referenced in function error

I've looked at other people's solutions to this problem and none of them, unfortunately, have solved my issue. I was having this error in my dev project, so I started from scratch, followed this tutorial to the letter, including the file names and locations, and I am still getting
1>unittest1.obj : error LNK2019: unresolved external symbol "public:
static int __cdecl HelloWorld::getTwo(void)"
(?getTwo#HelloWorld##SAHXZ) referenced in function "public: void
__thiscall UnitTest1::UnitTest1::TestMethodGetTwo(void)" (?TestMethodGetTwo#UnitTest1#1#QAEXXZ)
1>unittest1.obj : error
LNK2019: unresolved external symbol "public: int __thiscall
HelloWorld::getN(void)const " (?getN#HelloWorld##QBEHXZ) referenced in
function "public: void __thiscall
UnitTest1::UnitTest1::TestMethodGetN(void)"
(?TestMethodGetN#UnitTest1#1#QAEXXZ)
The code is in the tutorial I linked but I will copy it below. I don't understand what I could be doing wrong at this point - my test project depends on my build project, my definitions for these functions are in the class.
HelloWorld.h
#pragma once
class HelloWorld
{
int n = 10;
public:
static int getTwo();
int getN() const;
};
HelloWorld.cpp
#include "stdafx.h"
#include "HelloWorld.h"
int main()
{
return 0;
}
int HelloWorld::getTwo()
{
return 2;
}
int HelloWorld::getN() const
{
return n;
}
unittest1.cpp (in test project)
#include "stdafx.h"
#include "CppUnitTest.h"
#include "../HelloWorld/HelloWorld.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace UnitTest1
{
TEST_CLASS(UnitTest1)
{
public:
TEST_METHOD(TestMethodGetTwo)
{
Assert::AreEqual(2, HelloWorld::getTwo());
}
TEST_METHOD(TestMethodGetN)
{
HelloWorld hw = HelloWorld();
Assert::AreNotEqual(0, hw.getN());
}
};
}
For some reason the linker can't find my definitions, and I'm out of ideas about why that might be.

Error LNK2028: unresolved token (0A00000D) "extern "C" void __cdecl

I have two projects inside one solution (using VS 2013).
First project - mtriangle. Contains C code.
Second project - GeoGui. Contains Windows Forms project (used C++).
I try to use functions from mtriangle in GeoGui.
I have the following code:
Project mtriangle
triangle.h
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport) void trimain(char *, struct triangulateio *, struct triangulateio *, struct triangulateio *);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
void trifree(VOID *memptr);
#ifdef __cplusplus
}
#endif
triangle.c
void trimain(char *triswitches, struct triangulateio *in,
struct triangulateio *out, struct triangulateio *vorout)
{
// Implementation here, will be provided if need
}
Project GeoGui
mainForm.h
#pragma once
extern "C"
{
#include "triangle.h"
}
...
private: System::Void dlgFileOpen_FileOk(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e) {
struct triangulateio *in;
struct triangulateio *out;
struct triangulateio *voronoi;
trimain("p", in,out,voronoi);
}
When I try to build solution, error message appears:
Error 13 error LNK2028: unresolved token (0A00000D) "extern "C" void __cdecl trimain(char *,struct triangulateio *,struct triangulateio *,struct triangulateio *)" (?trimain##$$J0YAXPADPAUtriangulateio##11#Z) referenced in function "private: void __clrcall GeoGUI::mainForm::dlgFileOpen_FileOk(class System::Object ^,class System::ComponentModel::CancelEventArgs ^)" (?dlgFileOpen_FileOk#mainForm#GeoGUI##$$FA$AAMXP$AAVObject#System##P$AAVCancelEventArgs#ComponentModel#4##Z) C:\Users\Administrator\Documents\Visual Studio 2013\Projects\mtriangle\GeoGUI\GeoGUI.obj GeoGUI
Error 14 error LNK2019: unresolved external symbol "extern "C" void __cdecl trimain(char *,struct triangulateio *,struct triangulateio *,struct triangulateio *)" (?trimain##$$J0YAXPADPAUtriangulateio##11#Z) referenced in function "private: void __clrcall GeoGUI::mainForm::dlgFileOpen_FileOk(class System::Object ^,class System::ComponentModel::CancelEventArgs ^)" (?dlgFileOpen_FileOk#mainForm#GeoGUI##$$FA$AAMXP$AAVObject#System##P$AAVCancelEventArgs#ComponentModel#4##Z) C:\Users\Administrator\Documents\Visual Studio 2013\Projects\mtriangle\GeoGUI\GeoGUI.obj GeoGUI
Could you, please, advise - what I do incorrectly?
Thank you!
I read this article
What is an undefined reference/unresolved external symbol error and how do I fix it?
and, especially, this section:
"Symbols were defined in a C program and used in C++ code."
it recommends do the following:
If an entire library is included in a header file (and was compiled as
C code); the include will need to be as follows;
> extern "C" {
> #include "cheader.h" }
But as I pointed above in sample, I've already done it:
> extern "C" {
> #include "triangle.h"
> }
This is a difference.

IrrLicht - Linker error, redefinition

I am working on a project in which I am using the external library IrrLicht. The problem I am having is that the external header files which I include also have definitions in them. The linker doesnt like this very much and it complains about redefinition. Should I go for another library or is this a way to work this around? Oh btw I am working with vs 2010.
Example math3.h
#ifndef MATH_H
#define MATH_H
#include "quat.h"
class Point{
public:
float x;
float y;
float z;
Point (float _x, float _y, float _z){
x=_x;
y=_y;
z=_z;
}
Point(){
x=0;
y=0;
z=0;
}
irr::core::vector3df operator-(Point p){
return irr::core::vector3df(this->x-p.x,this->y-p.y,this->z-p.z);
}
float distance(Point p){
return sqrt((this->x-p.x)*(this->x-p.x)+(this->y-p.y)*(this->y-p.y)+(this->z-p.z)*(this->z-p.z));
}
Point operator+(irr::core::vector3df v){
return Point(this->x+v.X,this->y+v.Y,this->z+v.Z);
}
};
collidables.h
#ifndef COLLIDABLES_H
#define COLLIDABLES_H
#include "quat.h"
#include "math3.h"
class Sphere{
public:
Point cm;
float R;
irr::core::vector3df speed;
};
quat.h
#ifndef QUAT_H
#define QUAT_H
#include "irrlicht.h"
#endif
InitializeItems.cpp
#include <vector>
#include <time.h>
#include "InitializeItems.h"
#include "math3.h"
#include "quat.h"
#include "collidables.h"
#define SQRT2 1.4142135;
#define DIVSQRT2 0.70710678118;
std::vector<Sphere> InitializeAtoms(int N, float R)
{
std::vector<Sphere> spheres;
spheres.reserve(N);
srand(time(NULL));
Sphere sph;
for (int i=0;i<N;i++){
sph.cm=Point(rand()%2*N*R,rand()%2*N*R,rand()%2*N*R);
sph.R=R;
sph.speed=irr::core::vector3df(rand()%10,rand()%10,rand()%10);
spheres.push_back(sph);
}
return spheres;
}
std::vector<Molecule3> InitializeMol (int N, float R){
std::vector<Molecule3> mols;
mols.reserve(N);
srand(time(NULL));
Molecule3 m;
for (int i=0;i<N;i++){
m.cm=Point(rand()%2*N*R,rand()%2*N*R,rand()%2*N*R);
m.R=R;
m.sph1=m.sph2=m.sph3=(m.cm-Point(0,0,0));
m.orientation=irr::core::quaternion(rand(),rand(),rand(),rand());
m.orientation.normalize();
m.w=AxisAngle(irr::core::vector3df(rand(),rand(),rand()),rand()%360);
m.w.v.normalize();
irr::core::vector3df temp1,temp2,temp3;
temp1=irr::core::vector3df(-R,-R,0);
temp2=irr::core::vector3df(R,-R,0);
temp3=irr::core::vector3df(0,R,0);
temp1=fromRotation(m.orientation,temp1);
temp2=fromRotation(m.orientation,temp2);
temp3=fromRotation(m.orientation,temp3);
m.sph1+=temp1;
m.sph2+=temp2;
m.sph3+=temp3;
mols.push_back(m);
}
return mols;
}
InitializeItems.h
#ifndef INITIALIZEITEMS_H
#define INITIALIZEITEMS_H
#include <vector>
#include "collidables.h"
std::vector<Sphere> InitializeAtoms(int N, float R);
std::vector<Molecule3> InitializeMol(int N, float R);
#endif
Linker Errors:
1>main.obj : error LNK2005: "class irr::core::quaternion __cdecl fromVector(class irr::core::vector3d<float>)" (?fromVector##YA?AVquaternion#core#irr##V?$vector3d#M#23##Z) already defined in InitiliazeItems.obj
1>main.obj : error LNK2005: "class irr::core::vector3d<float> __cdecl purequatToVector(class irr::core::quaternion)" (?purequatToVector##YA?AV?$vector3d#M#core#irr##Vquaternion#23##Z) already defined in InitiliazeItems.obj
1>main.obj : error LNK2005: "class irr::core::vector3d<float> __cdecl fromRotation(class irr::core::quaternion,class irr::core::vector3d<float>)" (?fromRotation##YA?AV?$vector3d#M#core#irr##Vquaternion#23#V123##Z) already defined in InitiliazeItems.obj
1>physics.obj : error LNK2005: "class irr::core::quaternion __cdecl fromVector(class irr::core::vector3d<float>)" (?fromVector##YA?AVquaternion#core#irr##V?$vector3d#M#23##Z) already defined in InitiliazeItems.obj
1>physics.obj : error LNK2005: "class irr::core::vector3d<float> __cdecl purequatToVector(class irr::core::quaternion)" (?purequatToVector##YA?AV?$vector3d#M#core#irr##Vquaternion#23##Z) already defined in InitiliazeItems.obj
1>physics.obj : error LNK2005: "class irr::core::vector3d<float> __cdecl fromRotation(class irr::core::quaternion,class irr::core::vector3d<float>)" (?fromRotation##YA?AV?$vector3d#M#core#irr##Vquaternion#23#V123##Z) already defined in InitiliazeItems.obj
1>visuals.obj : error LNK2005: "class irr::core::quaternion __cdecl fromVector(class irr::core::vector3d<float>)" (?fromVector##YA?AVquaternion#core#irr##V?$vector3d#M#23##Z) already defined in InitiliazeItems.obj
1>visuals.obj : error LNK2005: "class irr::core::vector3d<float> __cdecl purequatToVector(class irr::core::quaternion)" (?purequatToVector##YA?AV?$vector3d#M#core#irr##Vquaternion#23##Z) already defined in InitiliazeItems.obj
1>visuals.obj : error LNK2005: "class irr::core::vector3d<float> __cdecl fromRotation(class irr::core::quaternion,class irr::core::vector3d<float>)" (?fromRotation##YA?AV?$vector3d#M#core#irr##Vquaternion#23#V123##Z) already defined in InitiliazeItems.obj
edit: added linker errors
edit2: link to github for whole project
https://github.com/DxsGeorge/Collider
It seems that "already defined" problems comes from the other three classes (main, physics, visuals), so show more info about them, anyway I suggest you to instead of using
#ifndef
#define
#endif
Use
#pragma once
at the beginning of the header file, which will do the same thing (on visual studio only) and will be less error prone.

error LNK2019: unresolved external symbol, all typical causes ruled out

Every answer (from what I've seen, which is a lot) to this question on this site has been addressed in my case, and I'm still at an impasse. I'm working with legacy code, having to hack my way through setting up a properly connected development environment. Using VS 2012, I have a solution with 22 projects in it with a spiderweb of dependencies between them. 1 project, phtranscript, depends on code from another project hunspell, and phtranscript's code is in turn needed by a 3rd project speechRecognizer. Here are the associated files and the compiler/linker output:
In project phtranscript:
phTranscript.h:
#ifndef _phTranscript_h__
#define _phTranscript_h__
#include <vector>
#include <string>
#include <map>
#include "config.h"
#include "character.h"
...
class hunspellMorph{
public:
static hunspellMorph *instance();
protected:
hunspellMorph();
private:
hunspellMorph(const hunspellMorph &);
hunspellMorph& operator=(const hunspellMorph &);
public:
~hunspellMorph();
void Morph(const std::string &in,std::vector<std::string> &out);
private:
class impl;
impl *pImpl_;
};
#endif
hunspellMorph.cpp:
#include "phTranscript.h"
#include "hunspell.hxx"
#include <treeNode.h>
#include <string.h>
class hunspellMorph::impl{
private:
Hunspell hs;
public:
impl();
void Morph(const std::string &in,std::vector<std::string> &out);
};
void hunspellMorph::impl::Morph(const std::string &in,std::vector<std::string> &out){
char **slst;
int re = hs.analyze(&slst,in.c_str());
...
freelist(&slst,re);
}
hunspellMorph::hunspellMorph(){
pImpl_ = new impl();
}
hunspellMorph::~hunspellMorph(){
delete pImpl_;
}
....
In project hunspell:
hunspell.hxx:
#include "affixmgr.hxx"
#include "suggestmgr.hxx"
#include "csutil.hxx"
#include "langnum.hxx"
#define SPELL_COMPOUND (1 << 0)
#define SPELL_FORBIDDEN (1 << 1)
#define SPELL_ALLCAP (1 << 2)
#define SPELL_NOCAP (1 << 3)
#define SPELL_INITCAP (1 << 4)
#define MAXDIC 20
#define MAXSUGGESTION 15
#define MAXSHARPS 5
#ifndef _HUNSPELL_HXX_
#define _HUNSPELL_HXX_
class Hunspell
{
...
public:
Hunspell(const char * affpath, const char * dpath, const char * key = NULL);
~Hunspell();
int analyze(char ***slst,const char *word,int d=0);
...
};
#endif
csutil.hxx:
#ifndef __CSUTILHXX__
#define __CSUTILHXX__
// First some base level utility routines
#define NOCAP 0
#define INITCAP 1
#define ALLCAP 2
#define HUHCAP 3
#define HUHINITCAP 4
#define MORPH_STEM "st:"
#define MORPH_ALLOMORPH "al:"
#define MORPH_POS "po:"
#define MORPH_DERI_PFX "dp:"
#define MORPH_INFL_PFX "ip:"
#define MORPH_TERM_PFX "tp:"
#define MORPH_DERI_SFX "ds:"
#define MORPH_INFL_SFX "is:"
#define MORPH_TERM_SFX "ts:"
#define MORPH_SURF_PFX "sp:"
#define MORPH_FREQ "fr:"
#define MORPH_PHON "ph:"
#define MORPH_HYPH "hy:"
#define MORPH_PART "pa:"
#define MORPH_HENTRY "_H:"
#define MORPH_TAG_LEN strlen(MORPH_STEM)
#define MSEP_FLD ' '
#define MSEP_REC '\n'
#define MSEP_ALT '\v'
// default flags
#define DEFAULTFLAGS 65510
#define FORBIDDENWORD 65510
#define ONLYUPCASEFLAG 65511
typedef struct {
unsigned char l;
unsigned char h;
} w_char;
#define w_char_eq(a,b) (((a).l == (b).l) && ((a).h == (b).h))
...
// free character array list
void freelist(char *** list, int n);
#endif
hunspell.cxx:
#include "license.hunspell"
#include "license.myspell"
#ifndef MOZILLA_CLIENT
#include <cstdlib>
#include <cstring>
#include <cstdio>
#else
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#endif
#include "hunspell.hxx"
#include "./config.h"
#include "./treeNode.h"
#include "cache.h"
#include <string>
#include <vector>
#ifndef MOZILLA_CLIENT
#ifndef W32
using namespace std;
#endif
#endif
Hunspell::Hunspell(const char * affpath, const char * dpath, const char * key)
{
...
}
Hunspell::~Hunspell()
{
...
}
int Hunspell::analyze(char ***slst,const char *word,int d){
...
}
csutil.cxx:
#include "license.hunspell"
#include "license.myspell"
#ifndef MOZILLA_CLIENT
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cctype>
#else
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#endif
#include "csutil.hxx"
#include "atypes.hxx"
#include "langnum.hxx"
#ifdef OPENOFFICEORG
# include <unicode/uchar.h>
#else
# ifndef MOZILLA_CLIENT
# include "utf_info.cxx"
# define UTF_LST_LEN (sizeof(utf_lst) / (sizeof(unicode_info)))
# endif
#endif
#ifdef MOZILLA_CLIENT
#include "nsCOMPtr.h"
#include "nsServiceManagerUtils.h"
#include "nsIUnicodeEncoder.h"
#include "nsIUnicodeDecoder.h"
#include "nsICaseConversion.h"
#include "nsICharsetConverterManager.h"
#include "nsUnicharUtilCIID.h"
#include "nsUnicharUtils.h"
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
static NS_DEFINE_CID(kUnicharUtilCID, NS_UNICHARUTIL_CID);
#endif
#ifdef MOZILLA_CLIENT
#ifdef __SUNPRO_CC // for SunONE Studio compiler
using namespace std;
#endif
#else
#ifndef W32
using namespace std;
#endif
#endif
...
void freelist(char *** list, int n) {
if (list && (n > 0)) {
for (int i = 0; i < n; i++) if ((*list)[i]) free((*list)[i]);
free(*list);
*list = NULL;
}
}
And here's the output on a clean build between the different projects:
6>------ Build started: Project: hunspell, Configuration: Debug Win32 ------
...
6> hunspell.vcxproj -> C:\temp\speech\divided_rm_speech_proj\Debug\hunspell.exe
...
10>------ Build started: Project: phtranscript, Configuration: Debug Win32 ------
...
10> phtranscript.vcxproj -> C:\temp\speech\divided_rm_speech_proj\Debug\phtranscript.exe
...
19>------ Build started: Project: speechRecognizer, Configuration: Debug Win32 ------
...
19> Generating Code...
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "void __cdecl freelist(char * * *,int)" (?freelist##YAXPAPAPADH#Z) referenced in function "public: void __thiscall hunspellMorph::impl::Morph(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &)" (?Morph#impl#hunspellMorph##QAEXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AAV?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##4##Z)
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::Hunspell(char const *,char const *,char const *)" (??0Hunspell##QAE#PBD00#Z) referenced in function "public: __thiscall hunspellMorph::impl::impl(void)" (??0impl#hunspellMorph##QAE#XZ)
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::~Hunspell(void)" (??1Hunspell##QAE#XZ) referenced in function "public: __thiscall hunspellMorph::impl::~impl(void)" (??1impl#hunspellMorph##QAE#XZ)
19>hunspellMorph.obj : error LNK2019: unresolved external symbol "public: int __thiscall Hunspell::analyze(char * * *,char const *,int)" (?analyze#Hunspell##QAEHPAPAPADPBDH#Z) referenced in function "public: void __thiscall hunspellMorph::impl::Morph(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &)" (?Morph#impl#hunspellMorph##QAEXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AAV?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##4##Z)
19>C:\temp\speech\divided_rm_speech_proj\Debug\speechRecognizer.exe : fatal error LNK1120: 4 unresolved externals
Keep in mind there is a lot of code taken out, so if something's missing that's important let me know and I'll update this description.
In Visual Studio 2012's environment setup, phtranscript's project properties have a hunspell reference established under common properties, the include directories field includes the hunspell include directory, and the library directories field includes the hunspell library output folder (this is all under VC++ Directories), the C/C++ additional include directories also lists the hunspell include directory. I left the Linker->Input additional libraries field alone since I get "already declared symbol" linker errors when I have both it and the VC++ directory specified. Under Project Dependencies I check hunspell and ensure it precedes phtranscript in the build order. Lastly, I have manually added the existing hunspell libraries (after they've been compiled) to the phtranscript project. In the speechrecognizer project, I've taken identical steps as they correspond to the phtranscript project dependencies.
The code is pretty much a nightmare imo. What're the minimal amount of changes needed to fix this? Preferably just by changing/adding something on the IDE side instead of code changes (although those are inevitable).
UPDATE:
All the projects were designated as applications under project properties. After changing them to static libraries (all but the 1 project meant to execute), the link errors became this:
21>speechRecognizer.lib(hunspellMorph.obj) : error LNK2019: unresolved external symbol "void __cdecl freelist(char * * *,int)" (?freelist##YAXPAPAPADH#Z) referenced in function "public: void __thiscall hunspellMorph::impl::Morph(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &)" (?Morph#impl#hunspellMorph##QAEXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AAV?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##4##Z)
21>speechRecognizer.lib(hunspellMorph.obj) : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::Hunspell(char const *,char const *,char const *)" (??0Hunspell##QAE#PBD00#Z) referenced in function "public: __thiscall hunspellMorph::impl::impl(void)" (??0impl#hunspellMorph##QAE#XZ)
21>speechRecognizer.lib(hunspellMorph.obj) : error LNK2019: unresolved external symbol "public: __thiscall Hunspell::~Hunspell(void)" (??1Hunspell##QAE#XZ) referenced in function "public: __thiscall hunspellMorph::impl::~impl(void)" (??1impl#hunspellMorph##QAE#XZ)
21>speechRecognizer.lib(hunspellMorph.obj) : error LNK2019: unresolved external symbol "public: int __thiscall Hunspell::analyze(char * * *,char const *,int)" (?analyze#Hunspell##QAEHPAPAPADPBDH#Z) referenced in function "public: void __thiscall hunspellMorph::impl::Morph(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &)" (?Morph#impl#hunspellMorph##QAEXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AAV?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##4##Z)
21>C:\temp\speech\divided_rm_speech_proj\Debug\interface11.exe : fatal error LNK1120: 8 unresolved externals
These link errors wait until compiling the application at the very end to spring up, rather than when compiling speechrecognizer as an application. There are other unresolved linkages, but they seem independent (albeit related) to this problem.
Your output tells me, that both projects are compiled to *.exe files. I do not know how do you expect 'phtranscript' to use modules, that are part of 'hunspell', in this case.
If you create such dependencies, hunspell should be static (or dynamic) library, which phtranscript links to. I believe you DO set all dependencies correctly, but VS does not have anything to link together and that's why linker is so angry at you - it can not use *.exe as a dependency.
Simple solution: change 'hunspell' type to 'static library (.lib)' or 'dynamic library (.dll)' and setup 'phtranscript' to use it as an input library.

C++ WinSock2 Errors

Yesterday I've tried to make a socket server in C++, but I get errors upon compiling.
The errors:
Error 6 error LNK2019: unresolved external symbol _imp_socket#12 referenced in function "public: static unsigned long __cdecl Env::GetSocket(void)" (?GetSocket#Env##SAKXZ) C:\Users\JoshuaTha\Documents\Visual Studio 2010\Projects\HabboV5\HabboV5\Network.obj HabboV5
Error 5 error LNK2019: unresolved external symbol _imp_listen#8 referenced in function "public: void __thiscall Network::Start(void)" (?Start#Network##QAEXXZ) C:\Users\JoshuaTha\Documents\Visual Studio 2010\Projects\HabboV5\HabboV5\Network.obj HabboV5
Error 4 error LNK2019: unresolved external symbol _imp_htons#4 referenced in function "public: void __thiscall Network::Start(void)" (?Start#Network##QAEXXZ) C:\Users\JoshuaTha\Documents\Visual Studio 2010\Projects\HabboV5\HabboV5\Network.obj HabboV5
Error 3 error LNK2019: unresolved external symbol _imp_bind#12 referenced in function "public: void __thiscall Network::Start(void)" (?Start#Network##QAEXXZ) C:\Users\JoshuaTha\Documents\Visual Studio 2010\Projects\HabboV5\HabboV5\Network.obj HabboV5
Error 2 error LNK2001: unresolved external symbol "public: static class Network * Env::Network" (?Network#Env##2PAV0#A) C:\Users\JoshuaTha\Documents\Visual Studio 2010\Projects\HabboV5\HabboV5\HabboV5.obj HabboV5
Error 7 error LNK1120: 5 unresolved externals C:\Users\JoshuaTha\Documents\Visual Studio 2010\Projects\HabboV5\Debug\HabboV5.exe HabboV5
My main .cpp class:
// HabboV5.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include "Env.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout.write("hi", 2);
cout << "Hello World!" << endl;
Env::Network = new Network();
Env::Network->Start();
while (1)
{
char input[256];
cin.getline(input, 256);
}
}
Network.h:
#pragma once
#include <WinSock2.h>
class Network
{
private:
SOCKET socket;
public:
Network(void);
void Start();
};
Network.cpp:
#include "StdAfx.h"
#include "Network.h"
#include <WinSock2.h>
#include "Env.h"
Network::Network(void)
{
}
void Network::Start()
{
this->socket = Env::GetSocket();
SOCKADDR_IN sInformation;
sInformation.sin_family = AF_INET;
sInformation.sin_addr.s_addr = INADDR_ANY;
sInformation.sin_port = htons(30000);
bind(this->socket, (SOCKADDR*) (&sInformation), sizeof(sInformation));
listen(this->socket, 10);
}
Env.h:
#include "stdafx.h"
#include "Network.h"
#include <WinSock2.h>
class Env
{
public:
static Network* Network;
static DWORD GetSocket()
{
return socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
}
};
In the linker options (on the project right-click, linker, input) you need add wsock32.lib or ws2_32.lib to the list of input files.