compiling GCC project with visual studio [duplicate] - c

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.

Related

Linker error while building libevent project

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.

visual studio 2015 error unresolved external symbol __imp___fmode referenced in function _cpdf_open

i am getting below error on build after upgrading to visual studio 2015:
Error LNK2019 unresolved external symbol __imp___fmode referenced in
function _cpdf_open .....ClibPDF.lib(cpdfInit.obj) 1
Error LNK2019 unresolved external symbol __imp___iob referenced in
function __cpdf_file_open ....ClibPDF.lib(cpdfInit.obj) 1
Error LNK2001 unresolved external symbol
__imp___iob ReportGenerator .......ClibPDF.lib(cpdfMemBuf.obj) 1 Error LNK2001 unresolved external symbol
__imp___iob ReportGenerator ........ClibPDF.lib(cpdfUtil.obj) 1
Please suggest how to remove the error

Understanding VSC++ linker errors

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

Fatal error LNK1120 when compiling c project

I tried to compile main.c from this project Emacs-FullScreen-Win32 by using visual studio developer command prompt but I get the following error:
main.c
Microsoft (R) Incremental Linker Version 11.00.60610.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:main.exe
main.obj
main.obj : error LNK2019: unresolved external symbol __imp__ShowWindowAsync#8 re
ferenced in function _WinMain#16
main.obj : error LNK2019: unresolved external symbol __imp__SetWindowPos#28 refe
renced in function _WinMain#16
main.obj : error LNK2019: unresolved external symbol __imp__MessageBoxW#16 refer
enced in function _WinMain#16
main.obj : error LNK2019: unresolved external symbol __imp__GetWindowLongW#8 ref
erenced in function _WinMain#16
main.obj : error LNK2019: unresolved external symbol __imp__SetWindowLongW#12 re
ferenced in function _WinMain#16
main.obj : error LNK2019: unresolved external symbol __imp__FindWindowW#8 refere
nced in function _WinMain#16
main.obj : error LNK2019: unresolved external symbol __imp__CommandLineToArgvW#8
referenced in function _is_topmost_requested
main.exe : fatal error LNK1120: 7 unresolved externals
Those unresolved external problems are likely due to you not properly linking the libraries that those functions are from. In your project settings, go to project properties. Expand configuration properties, then expand linker. In the linker's input settings, you can specify libraries that the program requires in the "additional dependencies" option.

Visual Studio 2013 and libpng [duplicate]

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.

Resources