[GCC] Any tag of gcc to compile Cpp file which includes the 3rd party C header file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
GCC experts, I encounter a problem here need your help:
There is 3rd part header file (header.h) define a structure a below,
it can be passed compiling when treat it as C language. But we trying
to include this file in CPP file, and the compiling is failed since
g++ compiling more restriction or other reason.

shell@hercules$ g++ main.cpp
In file included from main.cpp:1:
header.h:10: error: conflicting declaration ‘typedef struct conn_t conn_t’
header.h:9: error: ‘struct conn_t’ has a previous declaration as ‘struct conn_t’
main.cpp: In function ‘int main()’:
main.cpp:8: error: aggregate ‘conn_t list’ has incomplete type and
cannot be defined

Header file header.h:

 1  #ifndef __HEADER_H__
 2  #define __HEADER_H__
 3  #ifdef __cplusplus
 4  extern "C" {
 5  #endif
 6  typedef struct
 7  {
 8      int data;
 9      struct conn_t *next;
10  }conn_t;
11
12  #ifdef __cplusplus
13  }
14  #endif
15
16  #endif // __HEADER_H__

Cpp file main.cpp

 1  #include "header.h"
 2  #include <iostream>
 3
 4  using namespace std;
 5  int main()
 6  {
 7      conn_t list;
 8      list.data = 1;
 9      list.next = NULL;
10      cout<<"hello:"<<list.data<<endl;
11      return 0;
12  }

Question: Is there any tag of gcc/g++ to compile it?
First, the header file is 3rd party C header file, it can be compiled
in C language;
Second, the header file can not be updated, just for specific purpose,
I have to includes this header file in my C++ file, and then during
compile the C++, the header file also will be treat as C++, that's
what problem I encountered.
--
Cheers,
Liao-Yuan



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux