【问题标题】:C++ compilation using mpic++ error使用 mpic++ 错误的 C++ 编译
【发布时间】:2016-12-01 20:03:37
【问题描述】:

我正在尝试在 Linux 系统上使用 mpic++ 编译程序。该程序包含我们教授提供的源文件,正是这些文件引发了错误。在 Visual Studio C++ 中编译代码没有问题,但我们需要在 Linux 系统上启动它,当我将它移动到 Linux 系统以使用 mpic++ 编译它时出现错误。

mpic++ -std=c++11 -Wall -c CommonApprox.cpp
In file included from ApproxIface.h:3:0,
                 from CommonApprox.h:3,
                 from CommonApprox.cpp:1:
referencedIface.h:23:19: error: '__stdcall' declared as a 'virtual' field
referencedIface.h:23:19: error: expected ';' at end of member declaration
referencedIface.h:23:90: error: ISO C++ forbids declaration of 'QueryInterface'           with no type [-fpermissive]
referencedIface.h:24:17: error: '__stdcall' declared as a 'virtual' field
referencedIface.h:24:17: error: expected ';' at end of member declaration
referencedIface.h:24:17: error: redeclaration of 'ULONG IReferenced::__stdcall'
referencedIface.h:23:19: note: previous declaration 'HRESULT IReferenced::__stdc          all'

错误不断发生,这些只是最初的几个。此特定错误引用的代码如下所示。

#define IfaceCalling __stdcall

class IReferenced {
    /* Actually, this is IUnknown of the WinAPI's COM
    HRESULT and ULONG are used to allow possible and easy interoperability
    accross different compilers and languages on Windows
    */

public:
     virtual HRESULT IfaceCalling QueryInterface(/*REFIID */ void*  riid,     void ** ppvObj) = 0;
     virtual ULONG IfaceCalling AddRef() = 0;
     virtual ULONG IfaceCalling Release() = 0;
};

据我所知,我们不允许更改提供给我们的代码。

感谢您的帮助。

编辑:

我使用 makefile 来编译程序。

OBJECTS = CommonApprox.o DatabaseHandler.o MaskHandler.o Output.o StatsHandler.o GlucoseLevels.o AkimaInterpolation.o CatmullRomInterpolation.o ApproxIface.o referencedImpl.o main.o

CFLAGS = -std=c++11 -Wall
LIBS = -lsqlite3 -ltbb
CC = mpic++

all: ku_ppr_distr

ku_ppr_distr : $(OBJECTS)
    $(CC) $(CFLAGS) $^ $(LIBS) -o $@ 
    rm -f *.o

CommonApprox.o: CommonApprox.cpp CommonApprox.h hresult.h
    $(CC) $(CFLAGS) -c CommonApprox.cpp

DatabaseHandler.o: DatabaseHandler.cpp DatabaseHandler.h
    $(CC) $(CFLAGS) -c DatabaseHandler.cpp

MaskHandler.o: MaskHandler.cpp MaskHandler.h 
    $(CC) $(CFLAGS) -c MaskHandler.cpp

Output.o: Output.cpp Output.h 
    $(CC) $(CFLAGS) -c Output.cpp

StatsHandler.o: StatsHandler.cpp StatsHandler.h
    $(CC) $(CFLAGS) -c StatsHandler.cpp

GlucoseLevels.o: GlucoseLevels.cpp GlucoseLevels.h
    $(CC) $(CFLAGS) -c GlucoseLevels.cpp

AkimaInterpolation.o: AkimaInterpolation.cpp AkimaInterpolation.h
    $(CC) $(CFLAGS) -c AkimaInterpolation.cpp

CatmullRomInterpolation.o: CatmullRomInterpolation.cpp CatmullRomInterpolation.h
    $(CC) $(CFLAGS) -c CatmullRomInterpolation.cpp

ApproxIface.o: ApproxIface.cpp ApproxIface.h
    $(CC) $(CFLAGS) -c ApproxIface.cpp

referencedImpl.o: referencedImpl.cpp referencedImpl.h
    $(CC) $(CFLAGS) -c referencedImpl.cpp

main.o: main.cpp
    $(CC) -w $(CFLAGS) -c main.cpp

%.o: %.c
    $(CC) -c $<  

clean: 
    rm -f *.o

【问题讨论】:

    标签: c++ compilation mpi mpic++


    【解决方案1】:

    mpic++g++(Linux 上的 GNU C++ 编译器)的包装器。 __stdcall 是 Visual C++ 特定的编译器指令,用于控制 g++ 无法识别的生成代码。您可以尝试将__stdcall 的空定义添加到您的makefile,即

    CFLAGS = -D__stdcall= -std=c++11 -Wall

    这应该会消除很多错误消息。

    【讨论】:

    • 感谢回复,我通过添加#ifndef _WINDOWS #define __stdcall #endif 解决了这个问题(对不起,我不知道如何在评论中编写多行代码)
    • 我以为你说过你不允许更改给你的代码 - 这就是为什么我建议你在 makefile 中这样做:)
    猜你喜欢
    • 2015-11-05
    • 2012-08-16
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多