This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
I'm trying to write a simple PNG file using libpng in C using VS2013. I installed libpng from Nuget and included png.h, but I can't compile. I get this as my output:
1>main.obj : error LNK2019: unresolved external symbol png_create_write_struct referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_set_longjmp_fn referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_create_info_struct referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_write_info referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_destroy_write_struct referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_init_io referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_free_data referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_set_IHDR referenced in function writeImage
1>main.obj : error LNK2019: unresolved external symbol png_set_text referenced in function writeImage
I've tried playing with the compilation settings, but nothing seems to make it work. I don't get any red lines under any of those declarations when I write the code, so VS must be seeing some of the code.
Besides including png.h you must also link with the appropriate import library (probably called libpng.lib or something similar). In Visual Studio, you would add this to Project Settings → Linker → Input → Additional Dependencies.
Related
I have one project which uses libevent libraries and i am compiling it VS2017. It runs in linux perfectly. I am getting errors like below:
1>ftpcmd.obj : error LNK2019: unresolved external symbol evutil_snprintf referenced in function do_client_read
1>ftpcmd.obj : error LNK2019: unresolved external symbol evutil_inet_pton referenced in function handle_pasv
1>ftpdata.obj : error LNK2001: unresolved external symbol evutil_inet_pton
1>ftpcmd.obj : error LNK2019: unresolved external symbol bufferevent_free referenced in function fs_client_free
1>ftpdata.obj : error LNK2001: unresolved external symbol bufferevent_free
Does anyone know how to link libevent with project? I read some question related to that and they say i need to compile libevent using VS commad prompt. I tried that with nmake -f Makefile.nmake libevent-2.1.8-stable but it failed.
Thanks in advance.
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 built libcurl following the instructions for building libcurl as a static library in the curl/winbuild directory to the letter. It spat out a libcurl_a.lib, a collection of .h files, which I moved into folders that I promptly added to the PATH. I then attempt to build my program with the command
cl (*my source files*) /IC:/PATH_addon/include libcurl_a.lib Ws2_32.lib Wldap32.lib /DCURL_STATICLIB /link /LIBPATH:C:/PATH_addon/lib
Note:
I am building from the command line as the code was not written in an IDE, or on this machine
C:/PATH_addon/ is a folder where I dump all the things that need to be linked into path (it is linked to my path) so that I don't pollute the default path, or my system32 folder
However when I run the command, it tells me that there are 12 unresolved symbols:
libcurl_a.lib(tftp.obj) : error LNK2001: unresolved external symbol __imp___time64
libcurl_a.lib(cookie.obj) : error LNK2001: unresolved external symbol __imp___time64
libcurl_a.lib(hostip.obj) : error LNK2001: unresolved external symbol __imp___time64
libcurl_a.lib(http.obj) : error LNK2001: unresolved external symbol __imp___time64
libcurl_a.lib(ftp.obj) : error LNK2001: unresolved external symbol __imp___time64
libcurl_a.lib(telnet.obj) : error LNK2001: unresolved external symbol __imp__strncpy
libcurl_a.lib(curl_sspi.obj) : error LNK2001: unresolved external symbol __imp__strncpy
libcurl_a.lib(url.obj) : error LNK2001: unresolved external symbol __imp__strncpy
libcurl_a.lib(strerror.obj) : error LNK2001: unresolved external symbol __imp__strncpy
libcurl_a.lib(ftp.obj) : error LNK2001: unresolved external symbol __imp__strncpy
libcurl_a.lib(warnless.obj) : error LNK2019: unresolved external symbol __imp__read referenced in function _curlx_read
OLDNAMES.lib(read.obi) : error LNK2001: unresolved external symbol __imp__read
libcurl_a.lib(warnless.obj) : error LNK2019: unresolved external symbol __imp__write referenced in function _curlx_write
OLDNAMES.lib(write.obi) : error LNK2001: unresolved external symbol __imp__write
libcurl_a.lib(parsedate.obj) : error LNK2019: unresolved external symbol __imp___gmtime64 referenced in function _Curl_gmtime
libcurl_a.lib(strerror.obj) : error LNK2019: unresolved external symbol __imp__strerror referenced in function _Curl_strerror
libcurl_a.lib(curl_threads.obj) : error LNK2019: unresolved external symbol __imp___beginthreadex referenced in function _Curl_thread_create
libcurl_a.lib(smb.obj) : error LNK2019: unresolved external symbol __imp___getpid referenced in function _smb_format_message
libcurl_a.lib(file.obj) : error LNK2019: unresolved external symbol __imp__close referenced in function _file_done
OLDNAMES.lib(close.obi) : error LNK2001: unresolved external symbol __imp__close
libcurl_a.lib(file.obj) : error LNK2019: unresolved external symbol __imp__open referenced in function _file_connect
OLDNAMES.lib(open.obi) : error LNK2001: unresolved external symbol __imp__open
libcurl_a.lib(mime.obj) : error LNK2019: unresolved external symbol __imp__access referenced in function _curl_mime_filedata
OLDNAMES.lib(access.obi) : error LNK2001: unresolved external symbol __imp__access
MSVCRT.lib(_chandler4gs_.obj) : error LNK2019: unresolved external symbol __except_handler4_common referenced in function __except_handler4
Why can't these symbols be resolved, and is there a way to fix this?
Solution (thanks in part to the incredible #Hans Passant):
Adding the /NODEFAULTLIB:LIBCMT flag fixed the issue and allowed for a successful compile and execution.
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
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
I have a project that compiling with GCC, and now I want open and run it with visual studio.what should I do?
I created new C project in visual studio and then add .c files to Source Files and add .h files to Header Files,too. But what should I do for makefile?
I see these error:
Error 9 error LNK2005: _main already defined in basic00.obj fp.obj
Error 10 error LNK2001: unresolved external symbol _optind fp.obj
Error 11 error LNK2001: unresolved external symbol _optopt fp.obj
Error 12 error LNK2001: unresolved external symbol _optarg fp.obj
Error 13 error LNK2019: unresolved external symbol _getopt referenced in function _main fp.obj
Error 14 error LNK2001: unresolved external symbol _opterr fp.obj
Error 15 fatal error LNK1120: 5 unresolved externals C:\Users\user\Documents\Visual Studio 2008\Projects\project.c\Debug\project.c.exe
You need to remove the second main() function.
You're using optind, optopt etc. These functions are defined in POSIX library, VS compiler doesn't have these ones. You need to remove these calls.