wininet.h不能编译使用带有代码块的GNU GCC编译器(wininet.h not compiling using GNU GCC compiler with code blocks)

其他开发 IT屋
百度翻译此文   有道翻译此文
问 题

i'm getting a peculiar issue when trying to compile my program. I don't have a huge ammount of experience with C++. I'm trying to simple create a function that can FTP put a file upto my plain FTP server. I'm using codeblocks IDE, and the GNU GCC compiler, and in the end, i thought to try a full fledged example i found online to test if it was me writing some silly code. I have installed the windows SDK with all libs, so i can confirm the files are present, and if i build without any code, there is no linker errors.

I copied the OP's code, as it looked fine, and he complained of no such issues. http://social.msdn.microsoft.com/Forums/en-US/76eb8b89-4b96-41ba-b869-e30711f29256/ftpputfile?forum=vcgeneral

However when i attempt to build my project, i get a plethora of errors:

||=== Build: Debug in uploader (compiler: GNU GCC Compiler) ===|
C:\C++\uploader\main.cpp||In function 'void FileSubmit()':|
C:\C++\uploader\main.cpp|10|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
C:\C++\uploader\main.cpp|11|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
C:\C++\uploader\main.cpp|12|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
obj\Debug\main.o:main.cpp|| undefined reference to `InternetOpenA@20'|
obj\Debug\main.o:main.cpp|| undefined reference to `InternetConnectA@32'|
obj\Debug\main.o:main.cpp|| undefined reference to `FtpPutFileA@20'|
obj\Debug\main.o:main.cpp|| undefined reference to `InternetCloseHandle@4'|
obj\Debug\main.o:main.cpp|| undefined reference to `InternetCloseHandle@4'|
||=== Build failed: 5 error(s), 3 warning(s) (0 minute(s), 1 second(s)) ===|

Any idea what i'm doing wrong here? Do i need to be using certain compiler settings?

解决方案

For anyone else experiencing this problem. The solution to this, as implied by Igor in the commends on the op, was too manually add a link to the lib. In code blocks, this is accomplished by going to project --> Build Options, click the linker tab, and then manually browse to the file and include it. This has now made my project compile. Why code blocks requires this I don't know. But it does, so thanks Igor.

本文地址:IT屋 » wininet.h not compiling using GNU GCC compiler with code blocks

问 题
试图编译我的程序时,我遇到了一个特殊的问题。我对C ++没有太多的经验。我试图简单地创建一个可以将FTP文件放到我的普通FTP服务器上的函数。我使用的代码块IDE和GNU GCC编译器,最后,我想尝试一个完整的例子,我在网上找到它来测试它是否是我写一些愚蠢的代码。我已经安装了所有库的Windows SDK,所以我可以确认文件存在,如果我没有任何代码构建,则没有链接器错误。

我复制了OP的代码,因为它看起来很好,他抱怨没有这样的问题。
http ://social.msdn.microsoft.com/Forums/en-US/76eb8b89-4b96-41ba-b869-e30711f29256/ftpputfile?forum = vcgeneral



然而,当我尝试构建我的项目时,我收到了很多错误:

  || ===构建:Debug in上传器(编译器:GNU GCC编译器)=== | 
C:\ C ++ \uploader\main.cpp ||在函数'void FileSubmit()':|
C:\ C ++ \uploader\main.cpp | 10 |警告:不推荐将字符串常量转换为'char *'[-Wwrite-strings] |
C:\ C ++ \uploader\main.cpp | 11 |警告:不推荐将字符串常量转换为'char *'[-Wwrite-strings] |
C:\ C ++ \uploader\main.cpp | 12 |警告:不推荐将字符串常量转换为'char *'[-Wwrite-strings] |
obj\Debug\main.o:main.cpp ||未定义的引用'InternetOpenA @ 20'|
obj\Debug\main.o:main.cpp ||对'InternetConnectA @ 32'|的未定义引用
obj\Debug\main.o:main.cpp ||未定义的引用'FtpPutFileA @ 20'|
obj\Debug\main.o:main.cpp ||对'InternetCloseHandle @ 4'的未定义引用|
obj\Debug\main.o:main.cpp ||对'InternetCloseHandle @ 4'的未定义引用|
|| ===构建失败:5个错误,3个警告(0分(s),1秒(s))=== |


任何想法我在这里做错了吗?我需要使用某些编译器设置吗?


解决方案

对于任何遇到此问题的人。
这个解决方案,正如伊戈尔所暗示的,在操作上表示赞同,过于人为地添加了一个链接到lib。在代码块中,这是通过转到项目 - >构建选项,单击链接器选项卡,然后手动浏览到该文件并包含它来完成的。这现在使我的项目编译。为什么代码块需要这个我不知道。但它确实如此,所以谢谢伊戈尔。

本文地址:IT屋 » wininet.h不能编译使用带有代码块的GNU GCC编译器

官方微信
扫一扫关注IT屋
微信公众号搜索 “ IT屋 ” ,选择关注
与百万开发者在一起