简体   繁体   English

在Visual Studio中构建项目

[英]Building Projects in Visual Studio

I am new to Windows and Visual Studio. 我是Windows和Visual Studio的新手。 I have a strong background in programming in Linux though. 我在Linux编程方面有很强的背景。 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. 发生的事情是该代码调用了VS无法找到的一堆函数。 Specifically all the errors are 具体来说,所有错误都是

ping.obj : error LNK2019 unresolved external symbol ping.obj:错误LNK2019无法解析的外部符号

The example code is from Ch11 or Network Programming for Windows. 该示例代码来自Ch11或Windows网络编程。 It's about creating raw sockets to use to make a ping program. 这是关于创建用于创建ping程序的原始套接字的。 Also, the code came with a Makefile but I don't know how to use it with VS... 另外,该代码带有Makefile,但我不知道如何在VS中使用它。

So, basically I need to know how to just put some code into VS and have it build properly. 因此,基本上,我需要知道如何将一些代码放入VS中并使其正确构建。 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++ 编辑:我正在使用VS 2008和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 edit2:我制作了一个makefile项目,并用cl ping.cpp resolve.cpp -out:ping.exe Ws2_32.lib填充了build命令。

now it's telling me my build was successful, but there's no .exe anywhere... arg!! 现在,它告诉我我的构建成功,但是在任何地方都没有.exe。 Windows makes no sense to me. Windows对我来说毫无意义。

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. edit3:这对我来说很有意义。 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. 在Windows中,令人费解的是linux中一个非常简单直接的过程。

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. 我的猜测是您没有链接到必需的库,并且由于您正在编写ping应用程序,因此我猜想它是Windows套接字库。 Chances are you need to add ws2_32.lib as a linked module. 您可能需要将ws2_32.lib添加为链接模块。

Try doing this: Go to Project Options->Linker->Input 尝试这样做:转到项目选项->链接器->输入

Add Ws2_32.lib 添加Ws2_32.lib

If that doesn't fix it, please post the entire link error. 如果仍不能解决问题,请发布整个链接错误。 It should make it more clear what is missing. 应该更清楚地说明缺少的内容。

I beleive that you also need to include the stdafx.h header. 我相信您还需要包括stdafx.h标头。 It's the header file that the IDE puts in your project when you create it. 这是IDE在创建项目时将其放在项目中的头文件。 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. 自从我使用VS 2008编写任何C ++以来已经有一段时间了,但是如果我没有记错的话,我会遇到很多与此相关的问题。 If I recall, the stdafx header adds a bunch of compiler directives that are required by the VS 2008 compiler. 如果我还记得,stdafx标头会添加一堆VS 2008编译器所需的编译器指令。

Is that in C++? 那是C ++吗?

Take a look at this article from msdn, I think that's what you are looking for. 看一下msdn上的这篇文章 ,我认为这就是您想要的。 I don't know what version of visual studio you have, but I don't think things change much from version to version. 我不知道您的Visual Studio版本是什么,但我认为各个版本之间的变化并不大。 Anyway, you'll find all the versions on that site. 无论如何,您会在该站点上找到所有版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM