Error LNK2019 unresolved external symbol _cmd_ln_init referenced in function _main - pocketsphinx

I am trying to run my code using the library pocketsphinx. Even though I have used the .lib files for the library it still isn't working. My code:
#include "stdafx.h"
#include <pocketsphinx.h>
#define MODELDIR "c:/sphinx/model"
int main(int argc, char *argv[])
{
ps_decoder_t *ps = NULL;
cmd_ln_t *config = NULL;
config = cmd_ln_init(NULL, ps_args(), TRUE,
"-hmm", MODELDIR "/en-us/en-us",
"-lm", MODELDIR "/en-us/en-us.lm.bin",
"-dict", MODELDIR "/en-us/cmudict-en-us.dict",
NULL);
return 0;
}
Errors:
Error LNK2019 unresolved external symbol _cmd_ln_init referenced in function _main
Error LNK2019 unresolved external symbol _ps_args referenced in function _main

Related

LNK2019: unresolved external symbol __imp_curl_easy_init referenced in function main

I am using yahoo-finance api in my task.
I installed curl with visual studio nmake, and this is info of my curl package:
libcurl-vc22-x64-debug-dll-ssl-dll-zlib-dll-ipv6-sspi
Then I write a toy code for testing but I got the errors below.
Build started...
1>------ Build started: Project: del3, Configuration: Debug x64 ------
1>Source.obj : error LNK2019: unresolved external symbol __imp_curl_easy_init referenced in function main
1>Source.obj : error LNK2019: unresolved external symbol __imp_curl_easy_setopt referenced in function main
1>Source.obj : error LNK2019: unresolved external symbol __imp_curl_easy_cleanup referenced in function main
1>C:\Users\user\source\repos\del3\x64\Debug\del3.exe : fatal error LNK1120: 3 unresolved externals
1>Done building project "del3.vcxproj" -- FAILED.
I tried to link the libs manually like #pragma comment(lib, "ws2_32.lib") or add the lib in the properties->linker->input->additional dependencies but not it didn't work.
I also read this article https://curl.se/mail/lib-2018-07/0079.html
But I don't really undertand.
Can someone help me? Thanks!
#include <curl/curl.h>
#include <sstream>
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "Wldap32.lib")
#pragma comment(lib, "crypt32.lib")
#pragma comment(lib, "normaliz.lib")
size_t writeCallback(char* content, size_t size, size_t nmemb, void* userdata) {
// Append the content to user data
((std::string*)userdata)->append(content, size * nmemb);
// Return the real content size
return size * nmemb;
}
int main() {
CURL* curl = curl_easy_init();
std::string responseBuffer;
std::string url = "https://query1.finance.yahoo.com/v7/finance/download/^GSPC?period1=1512086400&period2=1514678400&interval=1d&events=history";
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
// Write result into the buffer
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseBuffer);
// Perform the request
// CURLcode res = curl_easy_perform(curl);
// Cleanup
curl_easy_cleanup(curl);
}
return 0;
}

error calling vc++ method error LNK2019: unresolved external symbol referenced in function _wmain

shows error calling vc++ 2010 express sp1 method of a object:
error LNK2019: unresolved external symbol "public: int __thiscall
oper::ShowMyResult(void)" (?ShowMyResult#oper##QAEHXZ) referenced in
function _wmain
ooad_oops_exer.h
#include "stdafx.h"
class oper {
public:
void DisplayDefault( );
void DisplayWidth( int n );
void DisplayLongs( );
int ShowMyResult();
};
ooad_oops_exer.cpp
#include "ooad_oops_exer.h"
//
#ifndef SOCKET_CLIENT_CLASS
#define SOCKET_CLIENT_CLASS
const double d1 = 1.23456789;
const long l1 = 16;
int base = 10;
void oper::DisplayDefault( )
{
cout << endl << "default display" << endl;
}
void oper::DisplayWidth( int n )
{
cout << endl << "fixed width display set to " << n << ".\n";
}
void oper::DisplayLongs( )
{
cout <<endl<<"hello";
}
int oper::ShowMyResult()
{
DisplayWidth(15);
DisplayDefault( );
cout <<endl<<"ShowMyResult";
return 0;
}
//
#endif
main.cpp
#include "stdafx.h"
#include "ooad_oops_exer.h"
int _tmain(int argc, _TCHAR* argv[])
{
oper op;
int k = op.ShowMyResult();
cin.get();
return 0;
}
EDIT
1> Generating Code... 1>Debug\ooad_oops_exer.obj : warning LNK4042:
object specified more than once; extras ignored 1>main.obj : error
LNK2019: unresolved external symbol "public: int __thiscall
oper::ShowMyResult(void)" (?ShowMyResult#oper##QAEHXZ) referenced in
function _wmain 1>C:\xxx\OOAD_OOPS_PROJ\Debug\OOAD_OOPS_PROJ.exe :
fatal error LNK1120: 1 unresolved externals 1>

Compiling a working 32bit .dll for 64bit, errors

I have with a lot of help put together a 32bit plugin (.dll) for the 32bit Teamspeak program which works great.
People are now asking me to compile this for the 64bit Teamspeak client.
But...........
When I do I get the following errors.
1>------ Build started: Project: GetFSComFreqs, Configuration: Release x64 ------
Creating library C:\Users\Roo\Desktop\pluginsdk\src\x64\Release\GetFSComFreqs.lib and object C:\Users\Roo\Desktop\pluginsdk\src\x64\Release\GetFSComFreqs.exp
GetFSComFreqs.obj : error LNK2019: unresolved external symbol SimConnect_Close referenced in function "void __cdecl DLLStop(void)" (?DLLStop##YAXXZ)
GetFSComFreqs.obj : error LNK2019: unresolved external symbol SimConnect_Open referenced in function "void __cdecl DLLStart(void)" (?DLLStart##YAXXZ)
SimConnectProcs.obj : error LNK2001: unresolved external symbol SimConnect_Open
GetFSComFreqs.obj : error LNK2019: unresolved external symbol SimConnect_CallDispatch referenced in function "void __cdecl DLLStart(void)" (?DLLStart##YAXXZ)
SimConnectProcs.obj : error LNK2019: unresolved external symbol SimConnect_AddToDataDefinition referenced in function "void __cdecl OnRecvOpen(struct SIMCONNECT_RECV_OPEN *,unsigned long,void *)" (?OnRecvOpen##YAXPEAUSIMCONNECT_RECV_OPEN##KPEAX#Z)
SimConnectProcs.obj : error LNK2019: unresolved external symbol SimConnect_RequestDataOnSimObject referenced in function "void __cdecl OnRecvOpen(struct SIMCONNECT_RECV_OPEN *,unsigned long,void *)" (?OnRecvOpen##YAXPEAUSIMCONNECT_RECV_OPEN##KPEAX#Z)
SimConnectProcs.obj : error LNK2019: unresolved external symbol SimConnect_GetNextDispatch referenced in function "unsigned int __cdecl MessageRoutine(void *)" (?MessageRoutine##YAIPEAX#Z)
C:\Users\Roo\Desktop\pluginsdk\src\x64\Release\GetFSComFreqs.dll : fatal error LNK1120: 6 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
A part of the Code...
#include "stdafx.h"
#define FSAPI __stdcall
HANDLE hSimConnect = 0;
HANDLE hMsgThread = 0;
HINSTANCE ThisModule = 0;
HRESULT hr = 0;
char ThisModuleName[MAX_PATH];
void FSAPI StartSimConnect()
{
if (NULL == hSimConnect)
{
GetModuleFileName(ThisModule, ThisModuleName, MAX_PATH);
hr = SimConnect_Open(&hSimConnect, ThisModuleName, NULL, NULL, NULL, 0);
hr = SimConnect_CallDispatch(hSimConnect, SimConnectDispatch, NULL);
if (FAILED(hr)) hSimConnect = 0;
else hMsgThread = (HANDLE)_beginthreadex(NULL, NULL, MessageRoutine, NULL, NULL, NULL);
}
}
void FSAPI StopSimConnect()
{
if (NULL != hSimConnect)
{
hr = SimConnect_Close(hSimConnect);
hSimConnect = 0;
}
}
int main() {}
void FSAPI DLLStart(void)
{
if (NULL == hSimConnect)
{
GetModuleFileName(ThisModule, ThisModuleName, MAX_PATH);
hr = SimConnect_Open(&hSimConnect, ThisModuleName, NULL, NULL, NULL, 0);
hr = SimConnect_CallDispatch(hSimConnect, SimConnectDispatch, NULL);
if (FAILED(hr)) hSimConnect = 0;
else hMsgThread = (HANDLE)_beginthreadex(NULL, NULL, MessageRoutine, NULL, NULL, NULL);
}
}
void FSAPI DLLStop(void)
{
if (NULL != hSimConnect)
{
hr = SimConnect_Close(hSimConnect);
hSimConnect = 0;
}
}
You are getting unresolved external symbols errors.
If all those SimConnect_* functions are coming from an external source, you need to link you program with the appropriate import library.
If you just changed the build configuration from win32 to x64, it might be the case that these import libraries were not changed into your x64 configuration.

stack select() function doesn't work in Visual Studio

The following is part of the example code from http://curl.haxx.se/libcurl/c/sendrecv.html:
static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
{
struct timeval tv;
fd_set infd, outfd, errfd;
int res;
tv.tv_sec = timeout_ms / 1000;
tv.tv_usec= (timeout_ms % 1000) * 1000;
FD_ZERO(&infd);
FD_ZERO(&outfd);
FD_ZERO(&errfd);
FD_SET(sockfd, &errfd); /* always check for error */
if(for_recv)
{
FD_SET(sockfd, &infd);
}
else
{
FD_SET(sockfd, &outfd);
}
///* select() returns the number of signalled sockets or -1 */
res = select(sockfd + 1, &infd, &outfd, &errfd, &tv);
return res;
}
It worked fine on Linux, but when I brought it over Visual Studio 2010, it complains about the select() function. I compiled and linked all the cURL libraries/dlls correctly, and I even downloaded stuff as http request.
But when I tried to use the socket select() function, it complains with the following error:
error LNK2028: unresolved token (0A00034C) "extern "C" int __stdcall select(int,struct fd_set *,struct fd_set *,struct fd_set *,struct timeval const *)" (?select##$$J220YGHHPAUfd_set##00PBUtimeval###Z) referenced in function "int __cdecl `anonymous namespace'::wait_on_socket(unsigned int,int,long)" (?wait_on_socket#?A0x7d9db21b##$$FYAHIHJ#Z)
error LNK2019: unresolved external symbol "extern "C" int __stdcall select(int,struct fd_set *,struct fd_set *,struct fd_set *,struct timeval const *)" (?select##$$J220YGHHPAUfd_set##00PBUtimeval###Z) referenced in function "int __cdecl `anonymous namespace'::wait_on_socket(unsigned int,int,long)" (?wait_on_socket#?A0x7d9db21b##$$FYAHIHJ#Z)
Also, it seems that the select() function is compatible with Windows:
http://msdn.microsoft.com/en-us/library/ms740141(VS.85).aspx
Am I missing something? Can someone tell me how to get around this problem?
Thanks, --Rudy
You must link with the Microsoft socket library. Tell your linker to use Ws2_32.lib within your project.
In Visual Studio 2010 add this lib to Project->Properties->Linker->Input->Add. Dependencies.
Or add this lib inside your code with:
#pragma comment(lib, "Ws2_32.lib")

OpenCV Build on Visual Studio LINK error

I have followed this tutorial here as mentioned exactly
I now try to run simple OpenCV code on Visual Studio but it I keep getting linker errors.
I am trying this OpenCV tutorial in particular
Here is the error I keep getting :
1>Linking...
1>LINK : warning LNK4067: ambiguous entry point; selected 'mainCRTStartup'
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey#cv##YAHH#Z) referenced in function _main
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &)" (?imshow#cv##YAXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##ABV_InputArray#1##Z) referenced in function _main
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "public: __thiscall cv::_InputArray::_InputArray(class cv::Mat const &)" (??0_InputArray#cv##QAE#ABVMat#1##Z) referenced in function _main
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "void __cdecl cv::namedWindow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?namedWindow#cv##YAXABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) referenced in function _main
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?imread#cv##YA?AVMat#1#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) referenced in function _main
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree#cv##YAXPAX#Z) referenced in function "public: __thiscall cv::Mat::~Mat(void)" (??1Mat#cv##QAE#XZ)
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::copySize(class cv::Mat const &)" (?copySize#Mat#cv##QAEXABV12##Z) referenced in function "public: class cv::Mat & __thiscall cv::Mat::operator=(class cv::Mat const &)" (??4Mat#cv##QAEAAV01#ABV01##Z)
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" (?deallocate#Mat#cv##QAEXXZ) referenced in function "public: void __thiscall cv::Mat::release(void)" (?release#Mat#cv##QAEXXZ)
1>C:\Users\Saher\Documents\Visual Studio 2008\Projects\OpenCV_Proj\Debug\OpenCV_Proj.exe : fatal error LNK1120: 8 unresolved externals``
For the following code :
// OpenCV_Proj.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
I have been trying to get OpenCV to work for VS2008 for a while and any help regarding this issue will be apprectiated.
NOTE: In the readme file of the tutorial the following is what I followed:
1) Add build\bin and one of build\{x86|x64}\{vc9\vc10\mingw}\bin to your system path (to use DLLs)
Add build\{x86|x64}\{vc9\vc10\mingw}\lib or
build\{x86|x64}\{vc9\vc10\mingw}\staticlib as library directories to your linker settings,
Add build\include and build\include\opencv as include directories to your compiler settings.
Any help with getting this to work is really appreciated.
Those symbols are defined inside the OpenCV libraries, so you need to configure the project and let the linker know which OpenCV libraries you are using.
At the very least you should add: opencv_core230.lib and opencv_highgui230.lib (for OpenCV 2.3.0)
For more info on how to do this on VS2010, check this tutorial.
Go to properties->Linker->input and
add cv210.lib; cxcore210.lib; highgui210.lib;cvaux210.lib;
Your problem will be solved.
Have a happy coding....
I faced the same issue. After using dumpbin to see the exported symbols of highgui, I found that the linker is trying to link against a symbol that has debug_build_guard at the end.
If you built OPENCV in release mode, You cannot compile your application in DEBUG mode. Try flipping it to RELEASE and it magically works :)

Resources