[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

error LNK2001: unresolved external symbol __imp__gethostname@8

Posted on 2002-05-14
2
Medium Priority
?
1,329 Views
Last Modified: 2008-03-10
i write a simple program to get ip address.
code sample:
#include <windows.h>
#include "stdafx.h"
#include <winsock2.h>

int main(int argc, char* argv[])
{
     char *a = NULL;
     a = new char[255];
     gethostname(a,255);
     printf("%s",a);
     delete a;
    return 0;

}

when i compile the program occur following problem,

Deleting intermediate files and output files for project 'getSoftInf - Win32 Debug'.
--------------------Configuration: getSoftInf - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
getSoftInf.cpp
Linking...
getSoftInf.obj : error LNK2001: unresolved external symbol __imp__gethostname@8
Debug/getSoftInf.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

getSoftInf.exe - 2 error(s), 0 warning(s)

0
Comment
Question by:zhouweijian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 300 total points
ID: 7008105
Hi ,

you'll have to link with Ws2_32.lib ... simply open 'Project->Settings' dialog, select 'Link'-tab
and add Ws2_32.lib to 'Object/library modules'.

hope that helps,

ZOPPO
0
 
LVL 86

Expert Comment

by:jkr
ID: 7008346
... and don't forget to call 'WSAStartup()':

WORD wVersionRequested;
WSADATA wsaData;
int err;
 
wVersionRequested = MAKEWORD( 2, 2 );
 
err = WSAStartup( wVersionRequested, &wsaData );


and  call 'WSACleanup()' at the end of your program...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question