Unable to compile project: error in locale.h file

I am trying to compile a project that has the following header: locale.h;

locale.h:

class LOG4CXX_EXPORT Locale { public: ... protected: Locale(const Locale&); Locale& operator=(const Locale&); const LogString language; <-- error const LogString country; <-- error const LogString variant; <-- error }; // class Locale 

Can someone give me some suggestions?

I get this error. I'm not sure what the problem is.

 /LOGGER/include/log4cxx/helpers/locale.h:42:41: error: field 'language' has incomplete type const LogString language; ^ /LOGGER/include/log4cxx/helpers/locale.h:43:41: error: field 'country' has incomplete type const LogString country; ^ /LOGGER/include/log4cxx/helpers/locale.h:44:41: error: field 'variant' has incomplete type 
+5
source share
3 answers

Consider the following code:

 class MyClass; int method1(const MyClass& param); MyClass& method2(); const MyClass instance; // <- error here 

The MyClass forward declaration is a forward declaration . All compilers know that the class exists (it does not know its members, size ...), therefore it is called incomplete type . You can use links or pointers of this class, but it is. See here https://stackoverflow.com/questions/553682/when-can-i-use-a-forward-declaration for details

So it seems that in your code you only have a forward declaration of type LogString , and not a full declaration. Check your included files and include the order to get a full declaration of this class.

+1
source

You are using std :: basic_string, but there is no include for the corresponding header file:

 #include <string> 
0
source

What AnT wrote in a comment is a solution to the problem:

<clocale> includes your <locale.h> instead of the system that it should do; your language is trying to include <string>, which again includes <clocale>.

So in the end you will get a circular inclusion, as I described in your other question https://stackoverflow.com/questions/32379927/header-file-does-not-compile-locale-h , only the chain is longer ...

You need to break this inclusion circle. You can do this by removing the directory where the file is located from the inclusion directories that you pass to gcc (I assume this is -I "/ LOGGER / include / log4cxx / helpers"). Instead, you can specify the path to the parent directory (-I "/ LOGGER / include /"). Instead of #include <locale.h> you will have to use #include <log4cxx / helpers / locale.h>.

In fact, I recommend storing "/ LOGGER / include" as the only directory you give gcc and have all the other files you need through the appropriate subpath - if the rest of the log4cxx files allow this (which I would suggest).

In addition, the only way to solve the problem is to rename your file "locale.h" to something else (in addition, to change the separation of the include path, for example -I "/ LOGGER / include / log4cxx" and #include <helpers / locale .h>; what I chose, however, is the most natural IMO).

0
source

All Articles