| title | description | ms.date | f1_keywords | helpviewer_keywords | no-loc | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Linker Tools Error LNK2019 |
All about the Microsoft Visual Studio Linker error LNK2019 and how to diagnose and correct it in C and C++ code. |
09/07/2022 |
LNK2019 |
|
|
unresolved external symbol ‘symbol‘ referenced in function ‘function‘
The compiled code for function makes a reference or call to symbol, but the linker can’t find the symbol definition in any of the libraries or object files.
This error message is followed by fatal error LNK1120. To fix error LNK1120, you must fix all LNK2001 and LNK2019 errors first.
Possible causes
There are many ways to get this error. All of them involve a reference to a function or variable that the linker couldn’t resolve, or find a definition for. The compiler can identify when a symbol isn’t declared, but it can’t tell when the symbol isn’t defined. It’s because the definition may be in a different source file or library. If a symbol is referred to but never defined, the linker generates an unresolved external symbol error.
Here are some common problems that cause LNK2019:
The source file that contains the definition of the symbol isn’t compiled
In Visual Studio, make sure the source file that defines the symbol gets compiled as part of your project. Check the intermediate build output directory for a matching .obj file. If the source file isn’t compiled, right-click on the file in Solution Explorer, and then choose Properties to check the properties of the file. The Configuration Properties > General page should show an Item Type of C/C++ Compiler. On the command line, make sure the source file that contains the definition is compiled.
The object file or library that contains the definition of the symbol isn’t linked
In Visual Studio, make sure the object file or library that contains the symbol definition is linked as part of your project. On the command line, make sure the list of files to link includes the object file or library.
The declaration of the symbol isn’t spelled the same as the definition of the symbol
Verify you use the correct spelling and capitalization in both the declaration and the definition, and wherever the symbol is used or called.
A function is used but the type or number of the parameters don’t match the function definition
The function declaration must match the definition. Make sure the function call matches the declaration, and that the declaration matches the definition. Code that invokes function templates must also have matching function template declarations that include the same template parameters as the definition. For an example of a template declaration mismatch, see sample LNK2019e.cpp in the Examples section.
A function or variable is declared but not defined
LNK2019 can occur when a declaration exists in a header file, but no matching definition is implemented. For member functions or static data members, the implementation must include the class scope selector. For an example, see Missing Function Body or Variable.
The calling convention is different between the function declaration and the function definition
Some calling conventions (__cdecl, __stdcall, __fastcall, and __vectorcall) are encoded as part of the decorated name. Make sure the calling convention is the same.
A symbol is defined in a C file, but declared without using extern "C" in a C++ file
A file that’s compiled as C creates decorated names for symbols that are different from the decorated names for the same symbols declared in a C++ file, unless you use an extern "C" modifier. Make sure the declaration matches the compilation linkage for each symbol. Similarly, if you define a symbol in a C++ file that will be used by a C program, use extern "C" in the definition.
A symbol is defined as static and then later referenced outside the file
In C++, unlike C, global constants have static linkage. To get around this limitation, you can include the const initializations in a header file and include that header in your .cpp files, or you can make the variable non-constant and use a constant reference to access it.
A static member of a class isn’t defined
A static class member must have a unique definition, or it will violate the one-definition rule. A static class member that can’t be defined inline must be defined in one source file by using its fully qualified name. If it isn’t defined at all, the linker generates LNK2019.
A build dependency is only defined as a project dependency in the solution
In earlier versions of Visual Studio, this level of dependency was sufficient. However, starting with Visual Studio 2010, Visual Studio requires a project-to-project reference. If your project doesn’t have a project-to-project reference, you may receive this linker error. Add a project-to-project reference to fix it.
An entry point isn’t defined
The application code must define an appropriate entry point: main or wmain for console applications, and WinMain or wWinMain for Windows applications. For more information, see main function and command-line arguments or WinMain function. To use a custom entry point, specify the /ENTRY (Entry-Point Symbol) linker option.
You build a console application by using settings for a Windows application
If the error message is similar to unresolved external symbol WinMain referenced in function function_name, link by using /SUBSYSTEM:CONSOLE instead of /SUBSYSTEM:WINDOWS. For more information about this setting, and for instructions on how to set this property in Visual Studio, see /SUBSYSTEM (Specify Subsystem).
You attempt to link 64-bit libraries to 32-bit code, or 32-bit libraries to 64-bit code
Libraries and object files linked to your code must be compiled for the same architecture as your code. Make sure the libraries your project references are compiled for the same architecture as your project. Make sure the /LIBPATH or Additional Library Directories property points to libraries built for the correct architecture.
You use different compiler options for function inlining in different source files
Using inlined functions defined in .cpp files and mixing function inlining compiler options in different source files can cause LNK2019. For more information, see Function Inlining Problems.
You use automatic variables outside their scope
Automatic (function scope) variables can only be used in the scope of that function. These variables can’t be declared extern and used in other source files. For an example, see Automatic (Function Scope) Variables.
You call intrinsic functions or pass argument types to intrinsic functions that aren’t supported on your target architecture
For example, if you use an AVX2 intrinsic, but don’t specify the /ARCH:AVX2 compiler option, the compiler assumes that the intrinsic is an external function. Instead of generating an inline instruction, the compiler generates a call to an external symbol with the same name as the intrinsic. When the linker tries to find the definition of this missing function, it generates LNK2019. Make sure you only use intrinsics and types supported by your target architecture.
You mix code that uses native wchar_t with code that doesn’t
C++ language conformance work that was done in Visual Studio 2005 made wchar_t a native type by default. If not all files have been compiled by using the same /Zc:wchar_t settings, type references may not resolve to compatible types. Make sure wchar_t types in all library and object files are compatible. Either update from a wchar_t typedef, or use consistent /Zc:wchar_t settings when you compile.
You get errors for *printf* and *scanf* functions when you link a legacy static library
A static library that was built using a version of Visual Studio before Visual Studio 2015 may cause LNK2019 errors when linked with the UCRT. The UCRT header files <stdio.h>, <conio.h>, and <wchar.h>now define many *printf* and *scanf* variations as inline functions. The inlined functions are implemented by a smaller set of common functions. Individual exports for the inlined functions aren’t available in the standard UCRT libraries, which only export the common functions. There are a couple of ways to resolve this issue. The method we recommend is to rebuild the legacy library with your current version of Visual Studio. Make sure the library code uses the standard headers for the definitions of the *printf* and *scanf* functions that caused the errors. Another option for a legacy library that you can’t rebuild is to add legacy_stdio_definitions.lib to the list of libraries you link. This library file provides symbols for the *printf* and *scanf* functions that are inlined in the UCRT headers. For more information, see the Libraries section in Overview of potential upgrade issues.
Third-party library issues and vcpkg
If you see this error when you’re trying to configure a third-party library as part of your build, consider using vcpkg. vcpkg is a C++ package manager that uses your existing Visual Studio tools to install and build the library. vcpkg supports a large and growing list of third-party libraries. It sets all the configuration properties and dependencies required for successful builds as part of your project.
Diagnosis tools
Sometimes it’s difficult to tell why the linker can’t find a particular symbol definition. Often the problem is that you haven’t included the code that contains the definition in your build. Or, build options have created different decorated names for external symbols. There are several tools and options that can help you diagnose LNK2019 errors.
-
The
/VERBOSElinker option can help you determine which files the linker references. This option can help you verify whether the file that contains the definition of the symbol is included in your build. -
The
/EXPORTSand/SYMBOLSoptions of the DUMPBIN utility can help you discover which symbols are defined in your .dll and object or library files. Make sure the exported decorated names match the decorated names the linker searches for. -
The UNDNAME utility can show you the equivalent undecorated external symbol for a decorated name.
Examples
Here are several examples of code that causes LNK2019 errors, together with information about how to fix the errors.
A symbol is declared but not defined
In this example, an external variable is declared but not defined:
// LNK2019.cpp // Compile by using: cl /EHsc /W4 LNK2019.cpp // LNK2019 expected extern char B[100]; // B isn't available to the linker int main() { B[0] = ' '; // LNK2019 }
Here’s another example where a variable and function are declared as extern but no definition is provided:
// LNK2019c.cpp // Compile by using: cl /EHsc LNK2019c.cpp // LNK2019 expected extern int i; extern void g(); void f() { i++; g(); } int main() {}
Unless i and g are defined in one of the files included in the build, the linker generates LNK2019. You can fix the errors by including the source code file that contains the definitions as part of the compilation. Alternatively, you can pass .obj files or .lib files that contain the definitions to the linker.
A static data member is declared but not defined
LNK2019 can also occur when a static data member is declared but not defined. The following sample generates LNK2019, and shows how to fix it.
// LNK2019b.cpp // Compile by using: cl /EHsc LNK2019b.cpp // LNK2019 expected struct C { static int s; }; // Uncomment the following line to fix the error. // int C::s; int main() { C c; C::s = 1; }
Declaration parameters don’t match the definition
Code that invokes function templates must have matching function template declarations. Declarations must include the same template parameters as the definition. The following sample generates LNK2019 on a user-defined operator, and shows how to fix it.
// LNK2019e.cpp // compile by using: cl /EHsc LNK2019e.cpp // LNK2019 expected #include <iostream> using namespace std; template<class T> class Test { // The operator<< declaration doesn't match the definition below: friend ostream& operator<<(ostream&, Test&); // To fix, replace the line above with the following: // template<typename T> friend ostream& operator<<(ostream&, Test<T>&); }; template<typename T> ostream& operator<<(ostream& os, Test<T>& tt) { return os; } int main() { Test<int> t; cout << "Test: " << t << endl; // LNK2019 unresolved external }
Inconsistent wchar_t type definitions
This sample creates a DLL that has an export that uses WCHAR, which resolves to wchar_t.
// LNK2019g.cpp // compile with: cl /EHsc /LD LNK2019g.cpp #include "windows.h" // WCHAR resolves to wchar_t __declspec(dllexport) void func(WCHAR*) {}
The next sample uses the DLL in the previous sample, and generates LNK2019 because the types unsigned short* and WCHAR* aren’t the same.
// LNK2019h.cpp // compile by using: cl /EHsc LNK2019h LNK2019g.lib // LNK2019 expected __declspec(dllimport) void func(unsigned short*); int main() { func(0); }
To fix this error, change unsigned short to wchar_t or WCHAR, or compile LNK2019g.cpp by using /Zc:wchar_t-.
See also
For more information about possible causes and solutions for LNK2019, LNK2001, and LNK1120 errors, see the Stack Overflow question: What is an undefined reference/unresolved external symbol error and how do I fix it?.
I get this error, but I don’t know how to fix it.
I’m using Visual Studio 2013. I made the solution name MyProjectTest
This is the structure of my test solution:

—function.h
#ifndef MY_FUNCTION_H
#define MY_FUNCTION_H
int multiple(int x, int y);
#endif
-function.cpp
#include "function.h"
int multiple(int x, int y){
return x*y;
}
—main.cpp
#include <iostream>
#include <cstdlib>
#include "function.h"
using namespace std;
int main(){
int a, b;
cin >> a >> b;
cout << multiple(a, b) << endl;
system("pause");
return 0;
}
I’m a beginner; this is a simple program and it runs without error.
I read on the Internet and became interested in the unit test, so I created a test project:
Menu File → New → Project… → Installed → Templates → Visual C++ → Test → Native Unit Test Project →
Name: UnitTest1
Solution: Add to solution
Then the location auto-switched to the path of the current open solution.
This is the folder structure of the solution:

I only edited file unittest1.cpp:
#include "stdafx.h"
#include "CppUnitTest.h"
#include "../MyProjectTest/function.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace UnitTest1
{
TEST_CLASS(UnitTest1)
{
public:
TEST_METHOD(TestEqual)
{
Assert::AreEqual(multiple(2, 3), 6);
// TODO: Your test code here
}
};
}
But I get:
error LNK2019: unresolved external symbol.
I know that the implementation of function multiple is missing.
I tried to delete the function.cpp file and I replaced the declaration with the definition, and it ran. But writing both declaration and definition in the same file is not recommended.
How can I fix this error without doing that? Should I replace it with #include "../MyProjectTest/function.cpp" in file unittest.cpp?
Как решить проблему?
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_DeleteGrammarEngine(void *)» (?sol_DeleteGrammarEngine@@YGHPAX@Z) в функции _main
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_CountEntries(void *)» (?sol_CountEntries@@YGHPAX@Z) в функции _main
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «void * __stdcall sol_CreateGrammarEngineW(wchar_t const *)» (?sol_CreateGrammarEngineW@@YGPAXPB_W@Z) в функции _main
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_FindEntry(void *,wchar_t const *,int,int)» (?sol_FindEntry@@YGHPAXPB_WHH@Z) в функции «void __cdecl TestRussian(void *)» (?TestRussian@@YAXPAX@Z)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_DeletePhraseGenerator(void *)» (?sol_DeletePhraseGenerator@@YGHPAX@Z) в функции «void __cdecl TestEnglish(void *)» (?TestEnglish@@YAXPAX@Z)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_DeleteGeneratedPhrase(wchar_t *)» (?sol_DeleteGeneratedPhrase@@YGHPA_W@Z) в функции «void __cdecl TestEnglish(void *)» (?TestEnglish@@YAXPAX@Z)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «wchar_t * __stdcall sol_GeneratePhrase(void *,int,int)» (?sol_GeneratePhrase@@YGPA_WPAXHH@Z) в функции «void __cdecl TestEnglish(void *)» (?TestEnglish@@YAXPAX@Z)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_Paraphrase(void *,int,int,int,int,int,int,int,wchar_t const *,wchar_t *,int,int)» (?sol_Paraphrase@@YGHPAXHHHHHHHPB_WPA_WHH@Z) в функции «void __cdecl TestEnglish(void *)»
(?TestEnglish@@YAXPAX@Z)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_GetVersion(void *,int *,int *,int *)» (?sol_GetVersion@@YGHPAXPAH11@Z) в функции «void __cdecl TestEnglish(void *)» (?TestEnglish@@YAXPAX@Z)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «void * __stdcall sol_CreatePhraseGenerator(void *,int)» (?sol_CreatePhraseGenerator@@YGPAXPAXH@Z) в функции «void __cdecl TestEnglish(void *)» (?TestEnglish@@YAXPAX@Z)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_MatchNGrams(void *,wchar_t const *,int *,int *,int *)» (?sol_MatchNGrams@@YGHPAXPB_WPAH22@Z) в функции «void __cdecl Imitate(wchar_t const *,int)» (?Imitate@@YAXPB_WH@Z)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_LoadKnowledgeBase(void *,wchar_t const *)» (?sol_LoadKnowledgeBase@@YGHPAXPB_W@Z) в функции «void __cdecl Imitate(wchar_t const *,int)» (?Imitate@@YAXPB_WH@Z)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_BuildKnowledgeBase(void *,wchar_t const *,wchar_t const *,int,int)» (?sol_BuildKnowledgeBase@@YGHPAXPB_W1HH@Z) в функции «void __cdecl Imitate(wchar_t const *,int)» (?Imitate@@YAXPB_WH@Z)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_BuildKnowledgeBase2(void *,wchar_t const *,int,int)» (?sol_BuildKnowledgeBase2@@YGHPAXPB_WHH@Z) в функции «void __cdecl Imitate(wchar_t const *,int)» (?Imitate@@YAXPB_WH@Z)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_Set2GramsForPhrase(void *,int,int const *)» (?sol_Set2GramsForPhrase@@YGHPAXHPBH@Z) в функции «void __cdecl TestGenerator(void)» (?TestGenerator@@YAXXZ)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_SetWordsForPhrase(void *,int,int const *,int)» (?sol_SetWordsForPhrase@@YGHPAXHPBHH@Z) в функции «void __cdecl TestGenerator(void)» (?TestGenerator@@YAXXZ)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_StopSynonyms(void *,int,int const *,int)» (?sol_StopSynonyms@@YGHPAXHPBHH@Z) в функции «void __cdecl TestSynonymizer(void)» (?TestSynonymizer@@YAXXZ)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «void __stdcall sol_DeleteProjections(void *)» (?sol_DeleteProjections@@YGXPAX@Z) в функции «void __cdecl TestSynonymizer(void)» (?TestSynonymizer@@YAXXZ)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «int __stdcall sol_GetIEntry(void *,int)» (?sol_GetIEntry@@YGHPAXH@Z) в функции «void __cdecl TestSynonymizer(void)» (?TestSynonymizer@@YAXXZ)
1>fff.obj : error LNK2019: ссылка на неразрешенный внешний символ «void * __stdcall sol_ProjectWord(void *,wchar_t const *,int)» (?sol_ProjectWord@@YGPAXPAXPB_WH@Z) в функции «void __cdecl TestSynonymizer(void)» (?TestSynonymizer@@YAXXZ)
1>C:Users111DesktopfffDebugfff.exe : fatal error LNK1120: 20 неразрешенных внешних элементов
Вот текст программы:
#include «StdAfx.h»
#include <iostream>
#include <vector>
#include <tchar.h>
#include <windows.h>
#include <process.h>
#include <assert.h>
// Grammar Engine API
// API грамматической машины
#include <D:Program Files (x86)SynonymizerSDKincludelemsolarixsynonymizer_engine.h>
#include <D:Program Files (x86)SynonymizerSDKincludelemsolarix_sg_api.h>
using namespace std;
void TestRussian( HFAIND hEngine );
void TestEnglish( HFAIND hEngine );
const int DEF_TIMEOUT = 1000000; // 1000 секунд
static bool exists( const TCHAR *path )
{ return GetFileAttributes(path)!=(DWORD)INVALID_FILE_ATTRIBUTES; }
// **************************************************************
// Вспомогательная процедура — вывод UNICODE текста на консоль
// **************************************************************
static void wide( const wchar_t *ustr )
{
if( ustr==NULL || *ustr==0 )
return;
const int l = wcslen(ustr);
char *abuffer = new char[l+1];
memset( abuffer, 0, l+1 );
WideCharToMultiByte( CP_OEMCP, 0, ustr, l+1, abuffer, l+1, NULL, NULL );
printf( «%s», abuffer );
delete[] abuffer;
return;
}
static HFAIND hEngine = NULL;
static HGREN_PHRASOMAT hFG = NULL;
#if defined TEST_THREADS
unsigned int __stdcall FG_Thread(void*)
{
const wchar_t *words[] = {
L»ПОЛУНОЧИ»,
NULL
};
std::vector<int> ies;
int j=0;
while( words[j]!=NULL )
{
int ie = sol_FindEntry( hEngine, words[j++], NOUN_ru, -1 );
if( ie!=-1 )
ies.push_back(ie);
}
sol_SetWordsForPhrase( hFG, ies.size(), &*ies.begin(), true );
// Сгенерируем парочку предложений с измененным набором слов
for( int i=0; i<1000; i++ )
{
wchar_t *phrase = sol_GeneratePhrase(hFG,0xffffffff,FG_DEBUG);
printf( «#%5d—>», i );
wide(phrase);
printf( «n» );
sol_DeleteGeneratedPhrase(phrase);
}
return 0;
}
#endif
static void Imitate( const wchar_t *src_filename, int language )
{
if( GetFileAttributesW(src_filename)==(DWORD)-1 )
{
return;
}
// генерация квазислучайного текста на основе сведений о матрице переходов,
// создаваемой по исходному тексту.
// Сначала строим матрицу.
int rc1 = sol_BuildKnowledgeBase2( hFG, L»e:\MVoice\lem\scripts\rewriter\путеводитель.txt», 3, 0 );
// Теперь генерация текста.
for( int i=0; i<20; i++ )
{
wchar_t *phrase = sol_GeneratePhrase(
hFG,
FG_GENERATOR_USES_CHAINS,
FG_NO_DEBUG
);
printf( «#%2d «, i );
wide(phrase);
printf( «n» );
sol_DeleteGeneratedPhrase(phrase);
}
// ——————————————————————
// Имитация стиля — строим базу знаний из текста и затем генерируем
// случайный текст на основе информации.
// ——————————————————————
wchar_t tmp_db_folder[MAX_PATH];
swprintf( tmp_db_folder, L»%s\TestKnowledgeBase», _wgetenv(L»TMP») );
CreateDirectoryW( tmp_db_folder, NULL );
// удалим старое содержимое, если оно было.
wchar_t cmdx[MAX_PATH*2];
swprintf( cmdx, L»del /q %s\*.*», tmp_db_folder );
_wsystem( cmdx );
int rc = sol_BuildKnowledgeBase( hEngine, src_filename, tmp_db_folder, language, 0 );
rc = sol_LoadKnowledgeBase( hFG, tmp_db_folder );
for( int i=0; i<20; i++ )
{
wchar_t *phrase = sol_GeneratePhrase(
hFG,
FG_LOGICS | FG_GERUND1
| FG_GERUND2 | FG_COMSENT |
FG_USE_LEX_WHEN_EXHAUSTED
|
FG_DONT_REMOVE_USED |
FG_GENERATOR_USES_NGRAMS,
FG_DEBUG
);
// рассчитываем оценку достоверности фразы по стистическому критерию
int unmatched_2_ngrams=0, n2=0, n3=0;
int rc = sol_MatchNGrams( hEngine, phrase, &unmatched_2_ngrams, &n2, &n3 );
float r=0.0F;
if( (n2+unmatched_2_ngrams)!=0 )
r = float(n2+n3)/float(n2+n3+unmatched_2_ngrams);
printf( «#%2d «, i );
wide(phrase);
printf( » [[%g]]n», r );
sol_DeleteGeneratedPhrase(phrase);
}
return;
}
int main(void)
{
// Грузим морфологию, синтаксис и другие модули.
// Словарь должен быть уже подготовлен и находится в текущем каталоге или одном
// из стандартных для SDK/Integra каталогов. Для подготовки словаря можно запустить
// один из скриптов в sdkscriptsdictionary.
cout << «Loading grammar engine…n»;
bool dict_ok=false;
const TCHAR * paths[] = {
_T(«..\..\..\..\..\..\bin-windows\dictionary.xml»),
_T(«..\..\..\..\..\..\dictionary.xml»),
_T(«dictionary.xml»),
NULL
};
int ipath=0;
while( paths[ipath]!=NULL && dict_ok==false )
{
if( exists(paths[ipath]) )
{
hEngine = sol_CreateGrammarEngine(paths[ipath++]);
if( hEngine!=NULL )
dict_ok=true;
}
}
if( dict_ok )
{
int nentry = sol_CountEntries(hEngine);
cout << «Engine is loaded OKn»;
}
else
{
cout << «Error loading dictionary file ‘diction.xmln»
«You have to download the latest dictionary buildn»
«from http://sourceforge.net/project/solarix»;
return -1;
}
TestRussian(hEngine);
//TestEnglish(hEngine);
// Free allocated resources, delete the engine instance.
sol_DeleteGrammarEngine(hEngine);
cout << «All done.n»;
return 0;
}
static void TestGenerator(void);
static void TestSynonymizer(void);
static void TestParaphraser(void);
static void TestImitator(void);
void TestRussian( HFAIND hEngine )
{
if( sol_FindEntry( hEngine, L»МАМА», /*Solarix::API::*/NOUN_ru, /*Solarix::API::*/RUSSIAN_LANGUAGE )==-1 )
{
cout << «Russian lexicon is missing.n»;
return;
}
TestGenerator();
TestSynonymizer();
// TestParaphraser();
TestImitator();
return;
}
void TestEnglish( HFAIND hEngine )
{
// Проверяем наличие английского лексикона.
if( sol_FindEntry( hEngine, L»MOTHER», /*Solarix::API::*/NOUN_en, /*Solarix::API::*/ENGLISH_LANGUAGE )==-1 )
{
cout << «English lexicon is missing.n»;
return;
}
// Создаем генератор предложений для английского языка
hFG = sol_CreatePhraseGenerator(hEngine,ENGLISH_LANGUAGE);
wchar_t buffer[10001];
memset( buffer, 0, sizeof(buffer) );
bool is_premium = sol_GetVersion( hEngine, NULL, NULL, NULL);
if( is_premium )
{
// Проверяем сложные синонимы (доступно в версии Premium)
const wchar_t *orgs[] =
{
L»I decided to stay»,
L»I’ve decided to stay»,
L»We decide to stay»,
L»He decides to stay»,
L»I am deciding to stay»,
L»You must decide to stay»,
NULL
};
int iorg=0;
while( orgs[iorg]!=NULL )
{
const wchar_t *s = orgs[iorg];
int rc2 = sol_Paraphrase(
hFG,
FG_SYNONYMIZE | FG_SYNONYMIZER_MULTIWORD,
FG_PEDANTIC_ANALYSIS,
FG_NO_NGRAMS,
0,
FG_DEBUG,
FG_YIELD_PLAIN_TEXT,
5,
s,
buffer,
10000,
DEF_TIMEOUT
);
printf( «%s —> «, s );
wide(buffer);
printf( «n» );
iorg++;
}
}
// int rc = sol_Paraphrase( hFG, FG_SYNONYMIZE_OTHERS | FG_SYNONYMIZER_USES_NGRAMS | FG_DEBUG, 5, L»The cat catches the mouse.», buffer, 10000 );
const wchar_t *orgs[] =
{
L»I decided to stay»,
L»The mouse will be surrendering»,
L»The mouse is surrendering»,
L»The jolly mouse», // тут ошибка!
L»The funny mouse»,
L»The mouse surrendered»,
L»is asked»,
L»will be asked»,
L»will be asking»,
L»will be surrendering»,
L»is surrendering»,
L»The mouse surrenders»,
L»The mouse will surrender»,
L»Kitties»,
L»Funny job»,
L»Merry christmas»,
L»Tremendous danger»,
L»Huge disaster»,
L»The mouse gives up.»,
L»The kitty surrendered.»,
L»White cat silently sleeps.»,
L»Black cat catches the moise.»,
NULL
};
int iorg=0;
while( orgs[iorg]!=NULL )
{
const wchar_t *s = orgs[iorg];
int rc = sol_Paraphrase(
hFG,
FG_SYNONYMIZE | FG_SYNONYMIZER_MULTIWORD,
FG_PEDANTIC_ANALYSIS,
FG_NO_NGRAMS,
0,
FG_DEBUG,
FG_YIELD_PLAIN_TEXT,
5,
s,
buffer,
10000,
DEF_TIMEOUT
);
if( wcscmp( s, buffer )==0 )
{
printf( «Error, no synonymization occured for phrase: %sn», s );
}
else
{
printf( «#%d «, iorg );
wide(s);
printf( » —> » );
wide(buffer);
printf( «n» );
}
iorg++;
}
// sol_RandomizePhraseGenerator(hFG);
// Тестируем нефильтрованную по лексике генерацию
for( int i=0; i<30; i++ )
{
wchar_t *phrase = sol_GeneratePhrase(hFG,0,FG_DEBUG);
if( wcsstr( phrase, L»(—» )!=NULL || wcsstr( phrase, L»???» )!=NULL )
{
printf( «Error in phrase generator!n» );
}
printf( «#%2d «, i );
wide(phrase);
printf( «n» );
sol_DeleteGeneratedPhrase(phrase);
}
Imitate( L»..\..\..\..\..\..\scripts\rewriter\etalons-en.txt», ENGLISH_LANGUAGE );
sol_DeletePhraseGenerator(hFG);
Reported In
Reported In shows products that are verified to work for the solution described in this article. This solution might also apply to other similar products or applications.
Software
- LabWindows/CVI Base
- LabWindows/CVI Full
- Microsoft Visual Studio
Other
Microsoft Visual Studio
Issue Details
I am trying to use LabWindows/CVI functions in my Visual Studio C++ project, but when I try to compile my code I receive linking errors similar to the following:
error LNK2019: unresolved external symbol
Solution
In order to compile LabWindows/CVI functions in a Visual Studio C++ program, you first have to build the functions into a dynamic-link library (.dll) with an import library, and then link the import library (.lib) to your C++ project. To build the functions into a DLL and resolve the link errors, complete the following steps:
- If the instrument driver that includes the functions is not already loaded into LabWindows/CVI, you will need to load it by going to Instrument>>Load. In the dialog box that opens, navigate to the .fp file of interest and click Load.
- Open the Function Tree Editor by going to File>>Open>>Function Tree (*.fp). In the dialog box that opens, navigate to the .fp file of interest and click Load.
- Create a DLL project by going to Options>>Create DLL Project. Specify a path and name for your project and click Save. A message will pop up asking you if you want to load the DLL project now, similar to the dialog below. Click Yes.
- Before building the DLL, you will need to configure some of the build settings. First set the build target type by going to Build>>Target Type and making sure there is a checkmark next to Dynamic Link Library. Also set the project to release mode by going to Build>>Configuration and ensuring there is a checkmark next to Release.
- Go to Build>>Target Settings and change the following settings:
- Change the Run-time support option to Full run-time engine, as shown in the image below
- Change the type library settings by clicking Type Library and unchecking Add type library resource to DLL. If you do not uncheck this option, you may run into a type definition error when attempting to build, similar to Definitions for these types could not be found.
Then click OK to exit out of both windows.
- Build the DLL. In LabWindows/CVI 2012 or earlier, select Build>>Create Release Dynamic Link Library. In LabWindows/CVI 2013, select Build>>Build. This will create a dynamic-link library (.dll) and an import library (.lib) containing the LabWindows/CVI functions you are trying to use. We can now link the import library to the Visual Studio project.
- Open your Visual Studio C++ project, and go to Project>>Properties. In the Properties window, go to Configuration Properties>>C/C++>>General. Click the Additional Include Directories field. Then click the arrow that appears and select <Edit…>.
- In the dialog box that opens, click the New Line button, add the directory that contains the header file and click OK.
- Navigate to Configuration Properties>>Linker>>Input. Click the Additional Dependencies field and then click the arrow that appears and select <Edit…>.
- In the dialog box that opens, add the path of the import library to the list of Additional Dependencies.
- Compile your Visual Studio project, and the linking errors should be resolved. If you are still seeing linking errors, it may be that your project is dependent upon more than one library of LabWindows/CVI functions. In this case, you will want to repeat these steps for the other libraries.
Additional Information
If the functions you are trying to use are already bundled into a DLL with an import library, you can skip steps 1 through 6.
If you still has a link error, it is most probably due to name mangling issue. The C++ language allows you to overide some functions (such as methods in Object Oriented Programming). To resolve some names conflits, the C++ compiler add name mangling in order to have a unique name indentifier.
So when you call a C library in C++ programm, the C++ compiler needs to know that it do not need to modify the name. If it is the case, the name created by the C++ compiler is different from what is in your C code, and explain the linkage error.
In order to solve it, you need to add the following code in the header file (.h) related to you .c file.
#ifdef __cplusplus
extern "C" {
#endif
/* The functions you want to keep the same in C and C++ */
#ifdef __cplusplus
}
#endif
error LNK2019: unresolved external symbol in MS VS Community 2013
I was following this tutorial. https://www.youtube.com/watch?v=j-55D2rsCSE @ 9:20 he gets the exact same errors I’m getting but then instead of explaining how to fix it he just cuts out the part where he solves it. He says «it was a quite simple error it was a linker library error». Well its not quite so simple for me, I’ve been trying to figure out what the heck to do for days now. Any help would be appreciated. Thanks guys.
Last edited on
There are many cause of error LNK2019: unresolved external symbol in Visual Studio as you would see here
https://msdn.microsoft.com/en-us/library/799kze2z(v=vs.80).aspx
-The most common is a function declaration but no definition.
-When you have everything #included, an unresolved external symbol is often a missing * or & in the declaration or definition of a function.
The video does not explain much if you have not watched it completely.
Do a Google search and you will surely find you type.
Yea i wouldn’t have come here if i hadn’t done many many many many many google searches first.
Ill go ahead and tell you, from what research ive done i think its because the linker doesnt know where to find the non standard library. (w/e the heck that means) or something like that. but no luck in finding how to fix that particular problem.
Last edited on
Typically you need to do 5 things to include a library in your project:
1) Add #include statements necessary files with declarations/interfaces, e.g.:
#include «library.h»
2) Add an include directory for the compiler to look into
-> Configuration Properties/VC++ Directories/Include Directories (click and edit, add a new entry)
3) Add a library directory for *.lib files:
-> Configuration Properties/VC++ Directories/Library Directories (click and edit, add a new entry)
4) Link the lib’s *.lib files
-> Configuration Properties/Linker/Input/Additional Dependencies (e.g.: library.lib;
5) Place *.dll files either:
-> in the directory you’ll be opening your final executable from or into Windows/system32
I almost didn’t help because YouTube.
It means that you didn’t link to the ‘GLFW’ library. This is a separate package from straight OpenGL that you download from here: http://www.glfw.org/download.html
I didn’t watch the video and I won’t watch it either because I that it will just make me angry. So I don’t know how much he’s told you to do so far, obviously not enough.
thanks for the reply shadowCODE.
There doesn’t appear to be a single .lib or .dll file anywhere in this http://www.glfw.org/ library.
You have to build it OP. This is not an uncommon requirement. Tell us what platform you are using and we can walk you through the basics.
EDIT: I just built this after seeing your post, so like 30 mins ago. This is one of the easier ones.
Last edited on
thanks computergeek.
I’m using visual studio community 2013 on a 64 bit windows machine.
Last edited on
Last edited on
Hey man no problem. You dont owe me anything. Im just so glad for the help. So:
I downloaded the 64 bit binaries. Extracted «glfw-3.1.1.bin.WIN64» right to «C:UsersUserDocumentsVisual Studio 2013ProjectsProject3Project3» next to my main.cpp.
I added «#include «glfw-3.1.1.bin.WIN64includeGLFWglfw3.h»» to the top of my main.cpp.
I went to «Project3 Property Pages -> Configuration Properties -> VC++ Directories -> Include Directories -> edit» and tried adding both «C:UsersAaronDocumentsVisual Studio 2013ProjectsProject3Project3glfw-3.1.1.bin.WIN64includeGLFW» and «C:UsersAaronDocumentsVisual Studio 2013ProjectsProject3Project3glfw-3.1.1.bin.WIN64include» because shadowCODE’s instructions were not perfectly precise on this point.
I went to «Project3 Property Pages -> Configuration Properties -> VC++ Directories -> Library Directories» and tried adding all three of the options «C:UsersUserDocumentsVisual Studio 2013ProjectsProject3Project3glfw-3.1.1.bin.WIN64lib-mingw» and «C:UsersUserDocumentsVisual Studio 2013ProjectsProject3Project3glfw-3.1.1.bin.WIN64lib-vc2012» and «C:UsersUserDocumentsVisual Studio 2013ProjectsProject3Project3glfw-3.1.1.bin.WIN64lib-vc2013». I suspect the last one is right but i tried it first and it didnt work so i tried all of them.
I went to «Project3 Property Pages -> Configuration Properties -> Linker -> Input -> Additional Dependencies» and tried adding «libglfw3.a» and «glfw3.lib» and «glfw3dll.lib».
I copied and pasted «C:UsersUserDocumentsVisual Studio 2013ProjectsProject3Project3glfw-3.1.1.bin.WIN64lib-vc2013glfw3.dll» to «C:UsersUserDocumentsVisual Studio 2013ProjectsProject3Debug» where visual studio is building the project by default.
Obviously i didnt try all the complications at first. I made it simple and then tried all the extra stuff when simple didnt work. I tried to try all of the possible combinations of all of the things i described up there but im sure i missed some.
Ive tried programming and quit like a half dozen times now because i always run into this giant wall of difficulty that is compiling and using non standard libraries. I feel like if i can just scale this wall one time it might open the floodgates. I really do love programming its just so frustrating that i never seem to be able to get past the barrier of the difficulty of using third party libraries.
You’ll only want to link to one of the libraries per instance and it will be one of them with the ‘.lib’ suffix, since by convention those designate libraries compiled for MSVS where as a ‘.a’ suffix is used for mingw. Usually there is one library for debugging and another for production, it’s not immediately clear which one is which here. If I had to guess I would say the larger one is for debugging.
so it seems like the problem is probably with the last step from shadowCODE’s instructions. its very confusing because first he tells me to add the directory of the dll’s in my configuration properties and then to link the directory of the dll’s in my configuration properties. Then he tell me to move them. Why would i add the directory and then link to the directory only to move the files 1 step later?
also where he says
Link the lib’s *.lib files … e.g.: library.lib
that is a bit confusing as well because my configuration properties only allows me to link to select the folder with the libs in it and not any lib specifically.
i could just move the dll’s to the file where visual studio is building the executable but then the glfw header would be referencing the wrong directory wouldnt it? i mean surely the glfw header or its counterpart .cpp must be referencing the dll at some point, seems like i would surely break something if i just went and moved the dll.
Last edited on
Topic archived. No new replies allowed.