【问题标题】:Expected initializer before 'token'“令牌”之前的预期初始化程序
【发布时间】:2015-11-14 12:53:58
【问题描述】:

我知道关于此错误消息有几个问题,但我没有找到适合我的情况的解决方案。我想从库中导出 Filter 类。 Visual Studio 2013 编译正常,但 gcc 抛出错误:

prog.cpp:16:17: error: expected initializer before 'Filter'
 class DllExport Filter{
                 ^
prog.cpp:22:6: error: 'Filter' has not been declared
 void Filter::setFilter(const std::vector<float>& vFilter, unsigned int uNumThreads) {
      ^

代码:

#ifndef _GNULINUX
#define DllExport __declspec(dllexport)
#else
#define DllExport __attribute__((visibility("default")))
#endif

#include <string>
#include <vector>
#include <iostream>

#ifdef __cplusplus
extern "C" {
    namespace FilterAPI {
#endif

class DllExport Filter{
public:
    static void setFilter(const std::vector<float>& vFilter, unsigned int uNumThreads);

};

void Filter::setFilter(const std::vector<float>& vFilter, unsigned int uNumThreads) {
}

#ifdef __cplusplus
}  //  namespace FilterAPI
}  //  extern "C" {
#endif

另请参阅 https://ideone.com/3VV4AH

编辑:

make 文件中的标志是:

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8

# compile CXX with /usr/bin/c++
CXX_FLAGS = -fPIC  

CXX_DEFINES = -DFilter_Library_EXPORTS

【问题讨论】:

  • 我编译你的代码没有任何错误g++ -D_GNULINUX -c ideone_3VV4AH.cpp 你如何编译你的代码?

标签: c++


【解决方案1】:

我认为您的问题定义错误, 应该是#ifndef __linux,你可以找到gcc默认值 gcc -dM -E - &lt; /dev/null

【讨论】:

    【解决方案2】:

    我认为您不需要明确将可见性声明为“默认”。这在 Windows 上很重要,是的,但在 Linux/POSIX 上,默认值就是你想要的。

    #ifdef _WIN32
      #define DllExport __declspec(dllexport)
    #else
      #define DllExport
    #endif
    

    至少这是更常见的成语。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多