1

I have a CentOS 7 install running GCC 4.8.5 and I can successfully compile a cpp file named MyClass. I use the following command to compile the file:

g++ -c -fpermissive  $(pkg-config --cflags --libs libavformat libavcodec libswscale libavutil) ./MyClass.cpp

When I run this command on a Centos 6.7 running GCC 4.4.7, I get the following error:

In file included from ./MyClass.cpp:9:
./MyClass.h:70: warning: ISO C++ forbids initialization of member ‘pFormatCtx’
./MyClass.h:70: warning: making ‘pFormatCtx’ static
./MyClass.h:70: error: invalid in-class initialization of static data member of non-integral type ‘AVFormatContext*’

In my MyClass.h file, I have a private variable:

AVFormatContext   *pFormatCtx = NULL;

This error is repeated for any of the private variables that I initialize to NULL.

Is there an explanation for the difference I am encountering between my two CentOS installs?

This is the complete class:

    //
//  MyClass.h
//  FFMpegPlayground
//

#ifndef __FFMpegPlayground__MyClass__
#define __FFMpegPlayground__MyClass__

#include <stdio.h>

#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif

#ifdef __cplusplus
#define __STDINT_MACROS
#endif

extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <libavutil/frame.h>
}

typedef enum {
    K_STATUS_OK = 0,
    K_CANT_OPEN_FILE = -1,
    K_NO_STREAM_INFO = -2,
    K_NO_VIDEO_STREAM = -3,
    K_CODEC_UNSUPPORTED = -4,
    K_CANT_COPY_CODEC = -5,
    K_CANT_OPEN_CODEC = -6,
    K_CANT_ALLOCATE_FRAME = -7,
    K_SEEK_FAILED = -8,
    K_UNABLE_TO_ACQUIRE_FRAME = -9
} MyClassStatus;

class MyClass{
public:
    MyClass();
    MyClass(const char * filePath);
    MyClass(const char * filePath, double nScale);
    ~MyClass();

    MyClassStatus getStatus();
    void seekToFrame(int frame);
    uint8_t* frameData();
    uint8_t* nextFrameData();
    uint8_t* copyOfNextFrameData();
    int getFrameHeight();
    int getFrameWidth();
    int getCurrentFrame();
    int getFrameDataSize();
    long long getNumberOfFrames();

private:

    bool fileIsLoaded;
    uint8_t* createFrame();
    int currentFrame;

    void internalSeekToFrame(int frame);

    MyClassStatus status;
    AVFormatContext   *pFormatCtx = NULL;
    int               i, videoStream;
    AVCodecContext    *pCodecCtxOrig = NULL;
    AVCodecContext    *pCodecCtx = NULL;
    AVCodec           *pCodec = NULL;
    AVFrame           *pFrame = NULL;
    AVFrame           *pFrameRGB = NULL;
    int               numBytes;
    uint8_t           *buffer = NULL;
    struct SwsContext *sws_ctx = NULL;
    uint8_t           *_createdFrameData = NULL;


    double preferredScale = 1.0;
};

#endif /* defined(__FFMpegPlayground__MyClass__) */
6
  • I think you should post more of your code. Somewhere you declare the variable as a static variable Commented Jan 27, 2016 at 21:16
  • 2
    -fpermissive? No -Wall? Commented Jan 27, 2016 at 21:17
  • I am not compiling for production, just testing my library linking. Otheriwse, yes, I would use -Wall Commented Jan 27, 2016 at 21:24
  • I'll be that guy: GCC 4.4.7 is a 4 year old minor version of a 7 year old branch. There has been a lot of progress in both compilers and the C++ spec since then. I know it's hard to get an organization to update, and even harder to get recent compilers on CentOS, but you yourself point out that this problem only exists on the ancient compiler. Just update. Commented Jan 27, 2016 at 21:25
  • 1
    Names that contain two consecutive underscores (__FFMpegPlayground__MyClass__) and names that begin with an underscore followed by a capital letter are reserved to the implementation. Don't use them. Commented Jan 27, 2016 at 22:07

1 Answer 1

2

In-class initializers for non-static members like

AVFormatContext   *pFormatCtx = NULL;

are a C++11 feature. gcc4.4 is too old for that.

Sign up to request clarification or add additional context in comments.

3 Comments

Ok, so I should move my initialization into my constructor then?
@kernelK Either that, or use a newer compiler.
Ok, this is a link to getting a newer GCC up and running on CentOS 6 superuser.com/questions/381160/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.