[英]Protobuffers in c++ and error LNK2019: unresolved external symbol
[英]LNK2019: Error. unresolved external symbol in C++ program using InternetOpen InternetReadFIle
我曾尝试编写一个简单的程序来从网站获取信息。 我无法编译,因为我得到InternetReadFile,InternetOpenUrl等的LNK2019错误,例如
1> GetInternetInfo.obj:错误LNK2019:函数_main中引用的未解析的外部符号_ imp _InternetReadFile @ 16
我认为这意味着我没有定义这些函数,我没有包含正确的库。 我认为包括#include会修复它,但它似乎没有帮助。 我在使用C ++的Visual Studio 2010上运行它。 以下是我的计划。 任何帮助表示赞赏。
#include <string>
#include <iostream>
#include <fstream>
#include <windows.h>
#include <wininet.h>
#include <winsock.h>
#include <stdio.h>
#include <stdarg.h>
using namespace std;
int main()
{
HINTERNET hOpen, hURL;
LPCWSTR NameProgram = L"Webreader"; // LPCWSTR == Long Pointer to Const Wide String
LPCWSTR Website;
char file[101];
unsigned long read;
//Always need to establish the internet connection with this funcion.
if ( !(hOpen = InternetOpen(NameProgram, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 )))
{
cerr << "Error in opening internet" << endl;
return 0;
}
Website = L"http://www.google.com";
hURL = InternetOpenUrl( hOpen, Website, NULL, 0, 0, 0 ); //Need to open the URL
InternetReadFile(hURL, file, 100, &read);
while (read == 100)
{
InternetReadFile(hURL, file, 100, &read);
file[read] = '\0';
cout << file;
}
cout << endl;
InternetCloseHandle(hURL);
return 0;
}
请在项目设置中包含“Wininet.lib”。
项目 - >属性 - >配置属性 - >链接器 - >输入 - >附加依赖项
您还可以在include部分之后将此行添加到代码中,而不是将库添加到属性中:
#pragma comment(lib, "wininet.lib")
你有链接到wininet.lib
吗?
http://msdn.microsoft.com/en-us/library/aa385103(VS.85).aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.