Using libcurl on windows, in my c++ project, with visual studio, does not work because string get corrupted

风格不统一 提交于 2020-01-16 17:36:20

问题


As explained in the title, I am trying to use the libcurl C API to submit simple http query.

I am using windows as an OS, C++ as a language, Visual Studio 2008 as an IDE.

My code is quiet simple:

I initialize curl: CURLcode init = curl_global_init(CURL_GLOBAL_ALL);

I initialize my handle: CURL* handle = curl_easy_init();

I set the url: CRULcode set_url = curl_easy_setopt(handle, CURLOPT_URL, "http://www.example.com")

I submit my request: CURLcode submit = curl_easy_perform(handle);

As a result, the init and set_url return codes are 0 (CURLE_OK), the subimt return code is 2 (CURLE_URL_MALFORMAT).

When I debug I realize that my URL got corrupted, and instead of being http://www.example.com it becomes: xj: in release mode and 0|: in debug mode. It happens as soon as I enter curl_easy_setopt

The URL string gets definitely corrupted.

There must be one of my settings that is wrong, so here is a summary of my settings (in debug mode)

  • Use MFC in a Shared DLL
  • Use Multi-Byte Character Set
  • preprocessor includes CURL_STATICLIB
  • Multi-threaded Debug DLL /MDd
  • Linking againgst libcurld.lib (version 7.21.3) compile using the vc6curl.dsw project
  • also linking againgst ws2_32.lib wldap32.lib

回答1:


"Linking againgst libcurld.lib (version 7.21.3) compile using the vc6curl.dsw project"

This is the problem.

Static libraries must be built with the same compiler and the same runtime libraries (/MDd).

You can avoid this with DLL version of libcurl.



来源:https://stackoverflow.com/questions/4618101/using-libcurl-on-windows-in-my-c-project-with-visual-studio-does-not-work-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!