Linking libusb to my project - c++

I am having problem figure out how to use libusb, I put "libusb-1.0.18-rc1\libusb"
in include directories (using Visua Studio), but it doesn't work.
Can anyone enlighten me. Thanks a lot!
error message:
1>test.obj : error LNK2019: unresolved external symbol _libusb_exit#4 referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _libusb_close#4 referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _libusb_release_interface#8 referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _libusb_bulk_transfer#24 referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _libusb_claim_interface#8 referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _libusb_detach_kernel_driver#8 referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _libusb_kernel_driver_active#8 referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _libusb_free_device_list#8 referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _libusb_open_device_with_vid_pid#12 referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _libusb_get_device_list#8 referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _libusb_set_debug#8 referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _libusb_init#4 referenced in function _main

If you havne't done so already you will need to build the libraries you will be linking to, they are located in \libusb-1.0.18-rc1\msvc. There are multiple projects there depending on your Visual Studio version and whether you want a DLL or a static LIB file.
In either case you will need to right click on your project, then under Configuration Properties -> Linker -> Input -> Additional Dependencies add a reference to the LIB file you created. If you are linking to the static LIB file you're done, it will build the code in to your executable. If you're linking to the LIB file for the DLL make sure the DLL is available in your execution path. In either case this should resolve your unresolved externals.

I think you must take the 32-Bit Version of the libusb-Library/DLL and ensure 32 Bit Compile at Project Properies. That solved my Problem with LNK2019.

Related

Static linking SSL with Poco

I'm trying to build dll with static linking Poco library which require OpenSSl.
When I build Poco library with static linking with libeay32MDd.lib and ssleay32MDd.lib it works good but require OpenSSL's DLLs. If I use libeay32MTd.lib and ssleay32MTd.lib, it throws the following errors :
libeay32MTd.lib(e_capi.obj) : error LNK2019: unresolved external
symbol __imp_CertOpenStore referenced in function capi_open_store
8>libeay32MTd.lib(e_capi.obj) : error LNK2019: unresolved external
symbol __imp_CertCloseStore referenced in function capi_find_key
8>libeay32MTd.lib(e_capi.obj) : error LNK2019: unresolved external
symbol __imp_CertEnumCertificatesInStore referenced in function
capi_find_cert 8>libeay32MTd.lib(e_capi.obj) : error LNK2019:
unresolved external symbol __imp_CertFindCertificateInStore referenced
in function capi_find_cert 8>libeay32MTd.lib(e_capi.obj) : error
LNK2019: unresolved external symbol
__imp_CertDuplicateCertificateContext referenced in function capi_load_ssl_client_cert 8>libeay32MTd.lib(e_capi.obj) : error
LNK2019: unresolved external symbol __imp_CertFreeCertificateContext
referenced in function capi_find_key 8>libeay32MTd.lib(e_capi.obj) :
error LNK2019: unresolved external symbol
__imp_CertGetCertificateContextProperty referenced in function capi_cert_get_fname
you need to link with crypt32.lib

Compile FFmpeg Zeranoe Build with Visual Studio 2013

I downloaded the most recent Zeranoe dev build here, included the header files to my code, placed extern "C" around the includes, since this is a C++ project and FFmpeg is a C library, and added the libs to Visual Studio as well, and I get this linker error:
1>Camera.obj : error LNK2019: unresolved external symbol _av_free referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_freep referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_frame_alloc referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_frame_free referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _avcodec_register_all referenced in function __catch$??0Camera#MicroDFV_Camera##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##0PAX#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _avcodec_alloc_context3 referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _avcodec_open2 referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _avcodec_close referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_init_packet referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_packet_unref referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _avcodec_find_encoder referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _avcodec_encode_video2 referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_opt_set referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>Camera.obj : error LNK2019: unresolved external symbol _av_image_alloc referenced in function __catch$?NewFrameReceived#Camera#MicroDFV_Camera##AAEXKKKGPAE#Z$0
1>M:\Desktop\OpenCVTest\Debug\OpenCVTest.exe : fatal error LNK1120: 14 unresolved externals
Searching here and on Google I found many recommendations, such as to add #pragma comment(lib,...), and that the libs are static, so their order is important, and none of this helps.
So I scratched my head even more and realized that the Zeranoe build is made with MinGW-w64, so probably it won't link with Visual Studio. I inspected the lib using dumpbin and the symbols on the libs don't have the underscore, so I am pretty sure it won't work.
The other Zeranoe builds for Windows don't have libs, they are just plain .exe or exe + .dll.
Will I have to make my own VS2013 build of FFmpeg to link it, or is there some alternative way?

linker problems for EasyHook in Visual C++ 10

I have downloaded EasyHook 2.7 source and I try to compile it in my Visual Studio 2012 environment.
After solving a lot of warnings, I have found other warnings that I cannot solve, and these are:
1>error.obj : error LNK2019: unresolved external symbol _CoTaskMemAlloc#4 referenced in function _RtlGetLastErrorStringCopy#0
1>error.obj : error LNK2019: unresolved external symbol _CopyMemory#12 referenced in function _RtlGetLastErrorStringCopy#0
1>reloc.obj : error LNK2019: unresolved external symbol _ud_init#4 referenced in function _LhDisassembleInstruction#20
1>reloc.obj : error LNK2019: unresolved external symbol _ud_set_mode#8 referenced in function _LhDisassembleInstruction#20
1>reloc.obj : error LNK2019: unresolved external symbol _ud_set_input_buffer#12 referenced in function _LhDisassembleInstruction#20
1>reloc.obj : error LNK2019: unresolved external symbol _ud_set_syntax#8 referenced in function _LhDisassembleInstruction#20
1>reloc.obj : error LNK2019: unresolved external symbol _ud_disassemble#4 referenced in function _LhDisassembleInstruction#20
1>reloc.obj : error LNK2019: unresolved external symbol _ud_translate_intel#4 referenced in function _LhDisassembleInstruction#20
1>reloc.obj : error LNK2019: unresolved external symbol _ud_set_asm_buffer#12 referenced in function _LhDisassembleInstruction#20
1>C:\Users\Jaime Stuardo\Downloads\EasyHook-2.7.5159.0-Source\\Debug\x86\EasyHook32Drv.sys : fatal error LNK1120: 9 unresolved externals
What lib files I need to add so that the linker will not fail? notice that the first 2 functions belong to Windows API, so it is very curious it does not link.
Regards
Jaime
For the Windows functions, just look them up on MSDN. CoTaskMemAlloc says you need to link OLE32.LIB. CopyMemory says KERNEL32.LIB. The functions beginning with ud come from a library which Easyhook depends on: "EasyHook makes use of the udis86 library by Vivek.

Linking Error between matlab R2013a and MS VC++ 2013

I am writing a BCI game application in VC++ and require to implement Common Spatial Pattern Filtering (CSP) for feature extraction. Due to the hefty coding involved, I prefer to use an existing CSP Matlab function that I have. I followed the steps as given in here. However, I am getting the following Link error message:
1>------ Build started: Project: Test4, Configuration: Debug Win32 ------
1>test.obj : error LNK2019: unresolved external symbol _mxGetScalar referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _mxDestroyArray referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _mxCreateDoubleScalar referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _engEvalString referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _engOpen referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _engClose referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _engGetVariable referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _engPutVariable referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol _engOutputBuffer referenced in function _main
1>D:\Test4\Debug\Test4.exe : fatal error LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Could anyone please help me fix the problem? Any comments would be appreciated. Thanks in advance.
As I said in the referred post, you have to keep the platforms consistent:
The platforms of MATLAB and VC++ compile platform must be the same, i.e. Win32/x86 VC++ compile platform can only use x86 MATLAB and x64 VC++ compile platform can only use x64 MATLAB.
You're using MATLAB x64, thus you have to build your VC project in x64 too.

Unresolved External Symbols when using CUDA Driver API VS2012

I've been trying to use the CUDA driver API to load a .ptx file and a function from it with this code:
CUdevice device;
cuDeviceGet(&device,0);
CUcontext ctx;
cuCtxCreate(&ctx,0,device);
CUmodule mod;
cuModuleLoad(&mod,"kernel.ptx");
CUfunction func;
cuModuleGetFunction(&func,mod,"kernel");
CUdeviceptr ints;
cuMemAlloc(&ints,(sizeof(int)*30));
However at compile time I get these errors:
1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuDeviceGet#8 referenced in function _main
1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuCtxCreate_v2#12 referenced in function _main
1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuModuleLoad#8 referenced in function _main
1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuModuleGetFunction#12 referenced in function _main
1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuMemAlloc_v2#8 referenced in function _main
1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuMemcpyHtoD_v2#12 referenced in function _main
1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuMemcpyDtoH_v2#12 referenced in function _main
1>kernel.cu.obj : error LNK2019: unresolved external symbol _cuLaunchKernel#44 referenced in function _main
I created a new CUDA 5.5 project in VS2012 and typed this directly into the generated .cu file however at compile time I got these errors. If I do a test that doesn't use the driver api I don't get any errors!
Those errors occur when you are not linking against cuda.lib.
For those who does not know how to add cuda.lib into linking process like me (using VS2017):
Right click on the project, goto Properties at the bottom of the menu
Goto Linker-->Input
In Additional Dependencies, make sure that cuda.lib is there. In my case, this solved the 2019 link error.
Besides, if you click on the edit item in the drop menu, there is a Macros button that you can click and view all pre-defined Macros in your VS project.