libcurl编译错误

时间:2011-07-30 15:11:08

标签: c++-cli compiler-errors libcurl

我使用libcurl并且我在没有编写任何代码的情况下得到这些错误只是编译而且我不知道为什么

Fehler  49  error C2628: '$UnnamedClass$0x05e5b255$395$' gefolgt von 'bool' unzulässig (Semikolon ';' vergessen?)   c:\users\ttg\desktop\curl-7.21.7\lib\setup_once.h   273
Fehler  50  error C2065: '_SH_DENYNO': nichtdeklarierter Bezeichner C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xiosbase  111

首先是一个libcurl文件,它说它后面跟bool(忘了分号?)

第二个未声明的标识符

这是整个代码

#pragma once
#include <curl/curl.h>
#include <curl/easy.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string>
#include <sstream>
#include <iostream>
using namespace std;

namespace fr {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
   // assert(bodyfile == (FILE*) stream); //this assertion fails, but when i comment it, code works. Why?
    int written = fwrite(ptr, size, nmemb, (FILE *)stream);
    return written;
}
    /// <summary>
    /// Zusammenfassung für Form1
    ///
    /// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch
    ///          die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern,
    ///          das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt.
    ///          Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen
    ///          arbeiten, die diesem Formular zugewiesen sind.
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Konstruktorcode hier hinzufügen.
            //
        }

    protected:
        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }

    protected: 

    protected: 

    private:
        /// <summary>
        /// Erforderliche Designervariable.
        /// </summary>
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Erforderliche Methode für die Designerunterstützung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        void InitializeComponent(void)
        {
            this->SuspendLayout();
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(284, 262);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->ResumeLayout(false);

        }
#pragma endregion

    private: System::Void backgroundWorker1_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) {
    CURL *curl_handle;
    const char *headerfilename = "head.out";
    FILE *headerfile;
    const char *bodyfilename = "body.html";
    FILE *bodyfile;
    curl_global_init(CURL_GLOBAL_ALL);
    curl_handle = curl_easy_init();
    curl_easy_setopt(curl_handle, CURLOPT_URL, "http://url");
    curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
    curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
    headerfile = fopen(headerfilename,"w");
    if (headerfile == NULL) {
        curl_easy_cleanup(curl_handle);
        return;
    }
    bodyfile = fopen(bodyfilename,"w");
    if (bodyfile == NULL) {
        curl_easy_cleanup(curl_handle);
        return;
    }
    curl_easy_setopt(curl_handle,   CURLOPT_WRITEHEADER, headerfile);
    curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, bodyfile);
    curl_easy_perform(curl_handle);
    fclose(headerfile);
    fclose(bodyfile);
    curl_easy_cleanup(curl_handle);
             }
    };
}

这是第二个问题的解释:

1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xiosbase(111) : error C2065: '_SH_DENYNO': nichtdeklarierter Bezeichner
1>        C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xiosbase(196): Siehe Verweis auf die Instanziierung der gerade kompilierten Klassen-template "std::_Iosb<_Dummy>".
1>        with
1>        [
1>            _Dummy=int
1>        ]

翻译

error C2065: '_SH_DENYNO': undeclared identifier
See reference to the instantiation of the classes-template being compiled

4 个答案:

答案 0 :(得分:5)

因为libCURL中有一个名为share.h的文件。

您应重命名为curl_share.h &安培;全部替换

 #include "share.h"

通过

 #include "curl_share.h"

答案 1 :(得分:1)

仅将您的包含路径调整为c:\users\ttg\desktop\curl-7.21.7\include,而不是也包括c:\users\ttg\desktop\curl-7.21.7\lib

lib目录中的

根目录中有share.hVC\include\share.h的冲突。

答案 2 :(得分:0)

猜测一下,我会说你正在编译C,但包括C ++标题。 <string> <sstream> and <iostream>是C ++标题。

答案 3 :(得分:0)

您可以通过在预处理器中定义bool来修复有关HAVE_BOOL_T的错误,并在项目中引用名为share.h的两个文件,一个在libcurl中,另一个在您的项目中标准模板库,这就是为什么你会遇到_SH_DENYNO的错误。

相关问题