C ++ Ftp文件上传编译错误(Codelite)

时间:2014-06-28 07:12:38

标签: c++ ftp

我写了这段代码,用于通过ftp上传文件。但是,我无法使用Codelite进行编译。我使用了最新的codelite和mingw。请帮帮我。

#include <windows.h>
#include <wininet.h>
#include <iostream>

using namespace std;

int main() {

    HINTERNET hSession = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
    HINTERNET hService = InternetConnect(hSession, "www.server.com", INTERNET_DEFAULT_FTP_PORT, "username", "password", INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0);
    FtpPutFile(hService, "filename.ext", "filename.ext", FTP_TRANSFER_TYPE_BINARY, 0);
    InternetCloseHandle(hService);
    InternetCloseHandle(hSession);

    return 0;
}

这是错误代码。

./Release/main.cpp.o:main.cpp:(.text.startup+0x40): undefined reference to `InternetOpenA@20'
./Release/main.cpp.o:main.cpp:(.text.startup+0x85): undefined reference to `InternetConnectA@32'
./Release/main.cpp.o:main.cpp:(.text.startup+0x62): undefined reference to `FtpPutFileA@20'
./Release/main.cpp.o:main.cpp:(.text.startup+0x6d): undefined reference to `InternetCloseHandle@4'
./Release/main.cpp.o:main.cpp:(.text.startup+0x78): undefined reference to `InternetCloseHandle@4'

1 个答案:

答案 0 :(得分:0)

你的代码编译得很好,你有链接错误

According to MSDN,您需要关联Wininet

要在codelite IDE中执行此操作,请打开项目设置(点击工作区标签下的扳手图标),导航至常用设置 - &gt;接头

只需在 Libraries 字段下粘贴图书馆名称(参见随附的屏幕截图)

HTH,

叶兰

enter image description here