Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extern keyword "missing type specifier"

Tags:

c++

c

extern

I'm creating a DLL using Visual C++ Express, and when declaring extern ValveInterfaces* VIFace inside Required.h, the compiler is telling me that ValveInterfaces isn't defined. (I want to expose VIFace to any file including Required.h)

Here is the structure of my files:

DLLMain.cpp

#include "Required.h" //required header files, such as Windows.h and the SDK  

ValveInterfaces* VIFace;  

//the rest of the file

Required.h

#pragma once
//include Windows.h, and the SDK
#include "ValveInterfaces.h"

extern ValveInterfaces* VIFace; //this line errors

ValveInterfaces.h

#pragma once
#ifndef _VALVEINTERFACES_H_
#define _VALVEINTERFACES_H_
#include "Required.h"

class ValveInterfaces
{
public:
    ValveInterfaces(void);
    ~ValveInterfaces(void);
    static CreateInterfaceFn CaptureFactory(char *pszFactoryModule);
    static void* CaptureInterface(CreateInterfaceFn fn, char * pszInterfaceName);
    //globals
    IBaseClientDLL* gClient;
    IVEngineClient* gEngine;
};
#endif

Screenshot of errors: http://i.imgur.com/lZBuB.png

like image 734
Richie Li Avatar asked Jan 16 '12 07:01

Richie Li


1 Answers

That first error:

error C2143: syntax error : missing ';' before '*'

is a dead giveaway that the ValveInterfaces type has not been defined at the point where you first try to use it.

This almost invariably occurs because the type of ValveInterfaces is unknown. It's a little hard to tell since you've cut out huge swathes of ValveInterfaces.h but, even if it's defined there, it could be a weird combination of #pragma once and the apparent misplacement of the _REQUIRED_H include guards (they would normally be in required.h) which is causing you grief.

like image 135
paxdiablo Avatar answered Sep 25 '22 15:09

paxdiablo