【问题标题】:expected primary-expression before "__typeof__"“__typeof__”之前的预期主表达式
【发布时间】:2018-12-06 07:58:32
【问题描述】:

我是 C++ 新手。我正在尝试一小段代码来与 InfluxDB 的本地实例进行交互。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
#include <curl/curlver.h>
#include <curl/easy.h>
#include <curl/mprintf.h>
#include <curl/multi.h>
#include <curl/stdcheaders.h>
#include <curl/system.h>
#include <curl/typecheck-gcc.h>

using namespace std;

bool createInfluxDB(char *url, char *data) {
  CURL *curl;

  curl = curl_easy_init();

  if(curl) {
    CURLcode res;
    /* What Content-type should i use?*/
    struct curl_slist* headers = curl_slist_append(headers, "Content-Type: application/json");
    /*--data-urlencode*/
    char *urlencoded = curl_easy_escape(curl, data, int(strlen(data)));

    curl_easy_setopt(curl, CURLOPT_URL, url); // Error here
    curl_easy_setopt(curl, CURLOPT_POST, 1L);
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, urlencoded);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,     (long)strlen(urlencoded));

    res = curl_easy_perform(curl);

    /*omitted controls*/

    curl_free(urlencoded);
    curl_slist_free_all(headers);
    curl_easy_cleanup(curl);
  }

  return(true);
}

int main(int argc, char *argv[]){

   char *url = "http://localhost:8086/query";
   char *data = "q=CREATE DATABASE mydb";
   /* should i change data string to json?
      data = "{\"q\":\"CREATE DATABASE mydb\" }" */

   bool res = createInfluxDB(url, data);

   /*control result*/

   return(0);
}

在尝试构建它时,我收到以下错误:

expected primary-expression before '__typeof__'

extend list of errors

任何想法可能来自哪里?

我正在开发代码块 16.01,在 Ubuntu 上使用 GCC 编译器。

【问题讨论】:

  • 编译器在哪一行给出了这个错误?
  • 您确定您正确粘贴了错误消息吗?似乎有typeof__typeof__,但没有_typeof_
  • 编译器在第 27 行给我一个错误
  • 第 27 行:curl_easy_setopt(curl, CURLOPT_URL, url);
  • 这是您源文件的第 27 行吗?不是某些包含的头文件的第 27 行吗?如果您注释掉所有期望包含标头的代码怎么办?

标签: c++ curl influxdb


【解决方案1】:

这是由于 curl 库没有链接到编译器。在 Codeblocks 编辑器中解决此问题的正确方法: 项目>构建选项..>“链接器设置”选项卡

在链接库下,单击添加,在弹出窗口中输入库名称,单击确定,再次单击确定。并重新启动代码块。

【讨论】:

    猜你喜欢
    • 2016-07-26
    • 1970-01-01
    • 2020-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-05
    • 2013-08-29
    相关资源
    最近更新 更多