0

I am reusing some structures from c project. That project uses auto/preincluded header with some type definitions. That means that there is no call:

#include "architecture.h"

in the related source files.

I am trying fix this with defining types from qt pri file:

DEFINES += int8_t="\"signed char\""
DEFINES += uint8_t="\"unsigned char\""
DEFINES += int16_t="\"signed int\""
DEFINES += uint16_t="\"unsigned int\""
DEFINES += int32_t="\"signed long int\""
DEFINES += uint32_t="\"unsigned long int\""

I get compiler errors "duplicate signed", "multiple types in one declaration",...

There is somethin about the types and defines at typedef vs define.

Is there a better way to solve this case with auto include? How to fix this?

Community
  • 1
  • 1
urkon
  • 233
  • 1
  • 5
  • 15
  • Why do you want to create duplicates of types already in [the standard `` header file](http://en.cppreference.com/w/cpp/header/cstdint)? – Some programmer dude Apr 05 '17 at 10:30
  • Because that is not included in some sources I would like to use. Those types are target related and defined by the "architecture.h" that is auto included in the base project of an embeded device. But I do not know the way to force such a include in the qt project using qmake. – urkon Apr 05 '17 at 10:34
  • 2
    If you're using GCC (or Clang) then you can use the `-include` option to forcibly include a header file from the build command line. Read [the GCC manual](https://gcc.gnu.org/onlinedocs/) for more information. – Some programmer dude Apr 05 '17 at 10:50
  • Thats a good hint for those compilers. I am using MinGW. It may go with setting it as QMAKE_CXXFLAGS. – urkon Apr 05 '17 at 11:05
  • I have added a line: `QMAKE_CXXFLAGS += -include path/to/architecture.h` to my qmake pro file and with that forced include of the header. – urkon Apr 06 '17 at 07:47

1 Answers1

1

Using DEFINES +- xyz_t="...." colides with typedefinitions of qt included system headers like <cstdint> used by Qt Objects.

gcc compatible compiler (gcc, MinGW, clang) have option -include <file> to force preinclude.

In qmake this can be used by QMAKE_CXXFLAGS:

QMAKE_CXXFLAGS += -include path/to/file.h

In the included file.h we can include other system type definition headers like:

#include <stdbool.h>
#include <cstddef>

This way types are well and safely defined.

urkon
  • 233
  • 1
  • 5
  • 15