views:

442

answers:

3

I am new to Windows and Visual Studio. I have a strong background in programming in Linux though. I'm trying to build (is build just one word for compile and link) a this sample code from a textbook. I made an empty project added the source and header files to the project. The code compiles fine. However, I get all these errors at link time. What's happening is that the code calls a bunch of functions that VS can't find. Specifically all the errors are

ping.obj : error LNK2019 unresolved external symbol

The example code is from Ch11 or Network Programming for Windows. It's about creating raw sockets to use to make a ping program. Also, the code came with a Makefile but I don't know how to use it with VS...

So, basically I need to know how to just put some code into VS and have it build properly. If anyone could help me with that or point me to a decent resource I'd really appreciate it.

edit: I'm using VS 2008 and C++

edit2: I made a makefile project and filled in the build command with cl ping.cpp resolve.cpp -out:ping.exe Ws2_32.lib

now it's telling me my build was successful, but there's no .exe anywhere... arg!! Windows makes no sense to me.

Here is what it's telling me:

1>------ Build started: Project: ping, Configuration: Debug Win32 ------
1>Performing Makefile project actions
1>Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>cl : Command line warning D9035 : option 'o' has been deprecated and will be removed           in a future release
1>ping.cpp
1>resolve.cpp
1>Generating Code...
1>Microsoft (R) Incremental Linker Version 9.00.21022.08
1>Copyright (C) Microsoft Corporation.  All rights reserved.
1>/out:ping.exe 
1>/out:ut:ping.exe 
1>ping.obj 
1>resolve.obj 
1>Ws2_32.lib 
1>Build log was saved at "file://c:\Documents and Settings\Devin.DEVIN-DESK\My     
Documents\Visual Studio 2008\Projects\raw_socks\ping\Debug\BuildLog.htm"
1>ping - 0 error(s), 1 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

edit3: this makes sense to me. I have two headers and two source files and I can't seem to compile and link, no matter what I do. What's a very straightforward and easy process in linux is convoluted in Windows.

A: 

Is that in C++?

Take a look at this article from msdn, I think that's what you are looking for. I don't know what version of visual studio you have, but I don't think things change much from version to version. Anyway, you'll find all the versions on that site.

Rezlaj
+2  A: 

My guess is that you are not linking to a required library, and since you're writing a ping app, I'd guess its the Windows Sockets library. Chances are you need to add ws2_32.lib as a linked module.

Try doing this: Go to Project Options->Linker->Input

Add Ws2_32.lib

If that doesn't fix it, please post the entire link error. It should make it more clear what is missing.

Reed Copsey
+1  A: 

I beleive that you also need to include the stdafx.h header. It's the header file that the IDE puts in your project when you create it. It's been awhile since I wrote any C++ using VS 2008, but if I remember correctly, I ran into a bunch of issues w/ that. If I recall, the stdafx header adds a bunch of compiler directives that are required by the VS 2008 compiler.

regex