I'm trying to compile and run a C code that is using libsndfile library for sound files processing.
I have added the header file using this path:
project's Properties (in C/C++ -> General -> Additional Include Directories)
Also i have linked the library using this path:
Project Properties -> Linker -> Input -> Additional Dependencies.
But while debugging, i get the following errors:
1>sil.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
1>sil.obj : error LNK2019: unresolved external symbol _sf_write_sync referenced in function _main
1>sil.obj : error LNK2019: unresolved external symbol _sf_write_double referenced in function _main
1>sil.obj : error LNK2019: unresolved external symbol _sf_close referenced in function _main
1>sil.obj : error LNK2019: unresolved external symbol _sf_read_double referenced in function _main
1>sil.obj : error LNK2019: unresolved external symbol _sf_open referenced in function _main
1>c:\users\anam\documents\visual studio 2010\Projects\silence\Debug\silence.exe : fatal error LNK1120: 5 unresolved externals
Can someone please identify the problem here? I'm new at using Visual Studio and I really need help!
I faced the same problem. I solved it as follows.
1)Make sure that you are downloading the 32 bit libsndfile(libsndfile-1.0.25-w32-setup.exe) package because the Visual studio compiler is 32 bit.
2)Install the library by clicking on the setup.exe(libsndfile-1.0.25-w32-setup.exe) file of libsndfile.
3)After creating your project, do the following 2 steps:
i)Go to Debug >> Project Properties >> Configuration Properties >> C/C++ >> General >> Additional Include Directories >> Click on the arrow on the right hand side and then click on edit >> Here, add the path of the include folder in your libsndfile directory.
ii)After step (i) is complete, click on Linker in Configuration Properties >> General >> Additional Library Directories >> Click on the arrow on the right hand side and then click on edit >> Here, add the path of the .lib file. You may have to type in the entire path since the browse option does not show the .lib file. So, in my case I typed C:\Program Files (x86)\Mega-Nerd\libsndfile\lib\libsndfile-1.lib.
Finally, you are done! Your code should compile and work now without throwing any errors.
Missing to specify the folder directory of the library (.lib added to Additional Dependencies)
VC++ Directories view
Click on Library Directories, click the drop-down button on the right and choose and specify the directory it should work.
I had a similar issue and the problem was mixing a x64 lib and a win32 project.
Related
I have encountered problem with linking static lib - when there no windows.h and calls to WinAPI, it links and works fine, but when they used, I get this error when building:
error: linking with `link.exe` failed: exit code: 1120
note: external-test.lib(library_win32.cpp.obj) : error LNK2019: unresolved external symbol __imp_MessageBoxW referenced in function init_window
In list of all used libs, there no user32.lib. Maybe it is the problem? How can I tell linker to use it
note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64\\link.exe" ... "kernel32.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
Here build script:
fn main() {
println!("cargo:rustc-link-search={}/src/external",env::var("CARGO_MANIFEST_DIR").unwrap());
}
Solution was simple - link user32 in build script
I patched ZLIB 1.2.11 using IPP 2016 (and 2019), all went fine, all compiled fine (using MSVC). But linker comes with following missing symbols (I added all necessary libs, and I actually tried adding all libs from IPP at all)
1>zlib_x32_debug.lib(deflate.obj) : error LNK2019: unresolved external symbol _ippsDeflateLZ77FastestGetStat_8u referenced in function _custDeflateUpdateTable
1>zlib_x32_debug.lib(deflate.obj) : error LNK2019: unresolved external symbol _ippsDeflateLZ77Fastest_8u referenced in function _lz77_encode_call
1>zlib_x32_debug.lib(deflate.obj) : error LNK2019: unresolved external symbol _ippsDeflateLZ77FastestPrecompHeader_8u referenced in function _lz77_encode_call
1>zlib_x32_debug.lib(deflate.obj) : error LNK2019: unresolved external symbol _ippsDeflateLZ77Fast_8u referenced in function _lz77_encode_call
1>zlib_x32_debug.lib(deflate.obj) : error LNK2019: unresolved external symbol _ippsDeflateLZ77Slow_8u referenced in function _lz77_encode_call
1>zlib_x32_debug.lib(deflate.obj) : error LNK2019: unresolved external symbol _ippsDeflateLZ77FastestGenHuffTable_8u referenced in function _zzdeflateGetTabLen
1>zlib_x32_debug.lib(deflate.obj) : error LNK2019: unresolved external symbol _ippsDeflateLZ77FastestGenHeader_8u referenced in function _zzdeflateGetTabLen
Then I even tried to search the libs for these symbols and they are nowhere to be found... Any ideas?
Please, check that you link proper IPP library bit version to your object files. I mean, 32-bit libraries should be linked to 32-bit object files. Looks, like "zlib_x32_debug.lib" is a 64-bit static lib (and linker looks for 64-bit variant of functions). As far as I remember, 32-bit functions have object files names like "blabla#number" and 64-bit functions are named as "_blabla".
I'm trying to build a simple command line application which uses WinUSB in Visual Studio 2013. I'm getting no compile errors, but lots of linker errors. The following are some of them:
winusblnk.obj : error LNK2019: unresolved external symbol imp__Sleep#4 referenced in function _msDelay
winusbnet.obj : error LNK2001: unresolved external symbol __imp__Sleep#4
What do the references to obj files mean? How do I see these OBJ files? How can I inspect them and see what functions they have inside them?
What does __imp__Sleep#4 mean? What do all the underscores mean? What does the #4 mean? How do I find the reference to this symbol?
What is the difference between error LNK2019 and error LINK2001?
There are lots more similar errors in winusbxxx.obj files.
errhnd.obj : error LNK2019: unresolved external symbol __imp__GetLocalTime#4 referenced in function _logerr
readtemp.obj : error LNK2019: unresolved external symbol _ReadTemperature referenced in function _main
Same questions.
MSVCRTD.lib(gs_report.obj) : error LNK2019: unresolved external symbol __imp__IsDebuggerPresent#0 referenced in function ___raise_securityfailure
MSVCRTD.lib(error.obj) : error LNK2001: unresolved external symbol __imp__IsDebuggerPresent#0
How do I look at the contents of these lib files, and see which obj files they contain, and which functions each of those contain?
There are lots more errors in MSVCRTD.lib
I hope someone can give me some guidance on finding the cause of all these errors.
Thanks - Rowan
I have compiled 32-bit dll library and I have its source and header file. The library is somehow showing print dialog and allows me to print files. I've made 32-bit C# application, which calls printing function in dll and everything is nice.
However, now I need to recompile library to 64-bit (Recompiling my C# project is easy). Basicly I tried two methods.
First one was compiling from Visual's Studio Developer command prompt. This was first time compiling something using command line, so I googled what should I write. I was not attempting to specify 64-bit architecture, because I wanted to be sure that it is working. I used this command to build it.
cl /D_USRDLL /D_WINDLL printing.c User32.Lib WinSpool.Lib Gdi32.Lib ComDlg32.Lib /link /DLL /OUT:printing.dll
It made printing.dll for me, I tried to replace precompiled version I already had and I tried it using my C# app. Everything worked. So I wanted to compile it as 64-bit library. I googled and found out, that I have to use different cl.exe and link.exe located in Program Files\Microsoft Visual Studio 12.0\VC\bin\amd64. So I cd-ed to correct folder and wrote same command. I've got bunch (29) of "unresolved externals", I googled and found out that it is because I am trying to link 32-bit libraries. So I changed all *.Lib-s to C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64*.Lib", retried and still got some (16) unresolved extarnals. Here is the list
/out:printing.exe
/DLL
/OUT:D:\Temp\printing\printing.dll
printing.obj
"C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64\User32.Lib"
"C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64\WinSpool.Lib"
"C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64\Gdi32.Lib"
"C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64\ComDlg32.Lib"
Creating library D:\Temp\printing\printing.lib and object D:\Temp\printing\printing.exp
printing.obj : error LNK2019: unresolved external symbol __report_rangecheckfailure referenced in function RSS_PrintFile
printing.obj : error LNK2019: unresolved external symbol strcpy referenced in function RSS_PrintFileBez
printing.obj : error LNK2019: unresolved external symbol strcmp referenced in function RSS_PrintFileBez
printing.obj : error LNK2019: unresolved external symbol strlen referenced in function RSS_PrintFile
printing.obj : error LNK2019: unresolved external symbol __imp_CreateFileA referenced in function RSS_PrintFile
printing.obj : error LNK2019: unresolved external symbol __imp_ReadFile referenced in function RSS_PrintFile
printing.obj : error LNK2019: unresolved external symbol __imp_CloseHandle referenced in function RSS_PrintFile
printing.obj : error LNK2019: unresolved external symbol __imp_GlobalFree referenced in function RSS_PrintFile
printing.obj : error LNK2019: unresolved external symbol __imp_LocalAlloc referenced in function RSS_PrintFileBez
printing.obj : error LNK2019: unresolved external symbol __imp_LocalHandle referenced in function RSS_PrintFileBez
printing.obj : error LNK2019: unresolved external symbol __imp_LocalFree referenced in function RSS_PrintFileBez
printing.obj : error LNK2019: unresolved external symbol atoi referenced in function RSS_PrintFileBezFromTo
printing.obj : error LNK2001: unresolved external symbol __GSHandlerCheck
printing.obj : error LNK2019: unresolved external symbol __security_check_cookie referenced in function RSS_PrintFile
printing.obj : error LNK2019: unresolved external symbol __security_cookie referenced in function RSS_PrintFile
LINK : error LNK2001: unresolved external symbol _DllMainCRTStartup
D:\Temp\printing\printing.dll : fatal error LNK1120: 16 unresolved externals
I managed to get rid of 4 unresolved externals adding /GS- option to compiler, but I do not know how to fix rest and I could not find any help. So I decided to use Microsoft Visual Studio to build my libary.
I've created new C++ project, set it to be a DLL library, added source and header file, compiled (using standart settings, on 32-bit). I've got bunch of warnings like this one
'function' : incompatible types - from 'char *' to 'LPCWSTR'
and simmilars and one error
'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
So I #include _CRT_SECURE_NO_WARNINGS on first line of printing.c file. Hiting "Build" button then resulted in 1 successful and I got my printing.dll. I replaced printing.dll I've got from command line by this one and I tested dll using my C# app. Pressing print button brought "Select Printer and so" window (as before), but hitting print resulted in opening small window with some chinese text. However, I can easily build it as 64-bit.
I would like to ask what am I doing wrong, why I can not compile C library from command prompt and why Microsoft visual studio somehow makes DLL not working.
I tried to debug DLL library compiled using MVS, but I failed. I do not know which solution should I open (C# testing app, or C DLL solution) and what to do next. C# wont show me code from another solution and even if I up debuger in DLL solution to open C# application it produces error
Debugginng information for "app.exe" could not be found or does not match. Skipped loading symbols for NGen binary.
and even if I press "Continue debugging", any breakpoint says, that it wont be hit, because no symbols were loaded.
So Basicly
How do I get rid of "unresolved externals" errors while compiling as 64-bit using command line?
OR
How do I fix Microsoft Visual Studio to built working dll library (does not matter if 32-bit or 64bit)?
Ok. I've managed to fix this issue. I gave up trying to build 64-bit version using command line and focused on fixing issue about chinese chars. I went to Project -> Project Properties -> Configuration Properties -> C/C++ -> Command Line to see what compiler parameters are passed. Then I went back to command line, and added previously found parameters one by one and testing if dll works. When I added /D "UNICODE", the library stopped working.
This being said, adding #undef UNICODE or setting Configuration Properties -> General -> Project Defaults -> Character Set to Not Set fixed my issue and now I a able to compile my printing library for both x86 and x64 architectures.
I have successfully built Clang with Microsoft C++ and I'm trying to get it to compile a hello world test case; it gets as far as generating an object file, linking with the standard library being the remaining stumbling block:
hello-202520.o : error LNK2019: unresolved external symbol _printf referenced in function _main
LINK : error LNK2001: unresolved external symbol _mainCRTStartup
There are comments from previous years saying Clang doesn't yet do Windows linking at all, but I get the impression those are outdated, and indeed it does now seem to be able to generate Windows format object files:
clang -c hello.c
ren hello.o hello.obj
link hello.obj
... doesn't barf, so the file format seems to be correct, but still gets the unresolved external symbol errors. Likely guess is the Microsoft compiler tags its output object files with an indication of the standard library they need to be linked with whereas Clang doesn't, and eyeballing a hex dump of the respective object files seems to confirm this and gives a hint of the linker command line to use:
link /defaultlib:libcmt /defaultlib:oldnames hello.obj
I had high hopes by this stage but alas it still gives the same unresolved external symbol errors.
What am I still missing?
Turns out Clang was by default generating 32-bit code but I was using 64-bit MSC, and the leading _ on C symbols has been dropped with the move to x64, so specifying -m64 on the clang command line did the job.