Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 2nd, 2012, 11:12 AM
welshamy welshamy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 welshamy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 11 sec
Reputation Power: 0
Python module build error. Compiler doesn't understand C++ syntax

I'm trying to build a Python module written in C++. In the module file I use C++ types I defined in other files and I include their header files in the C++ module file.

The problem I'm having is that when I build the module with my build script (listed below) I get errors implying that the compiler doesn't understand C++ syntax. I get the error listed below. I included the directory containing the types I use as include_dirs and library_dirs in the Extension command in my build script but that didn't help.

Here is the error I get:
===================================

Code:
running build
running build_ext
building 'xx' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c xxmodule.c -o build/temp.linux-x86_64-2.7/xxmodule.o
In file included from cdtm-model.h:4:0,
                 from xxmodule.c:19:
corpus.h:12:3: error: unknown type name ‘doc’
corpus.h:18:1: error: unknown type name ‘class’
corpus.h:18:14: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
In file included from xxmodule.c:19:0:
cdtm-model.h:6:1: error: unknown type name ‘class’
cdtm-model.h:7:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
cdtm-model.h:21:1: error: unknown type name ‘class’
cdtm-model.h:22:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
xxmodule.c: In function ‘xx_main_est’:
xxmodule.c:169:3: error: unknown type name ‘corpus’
xxmodule.c:169:15: error: ‘new’ undeclared (first use in this function)
xxmodule.c:169:15: note: each undeclared identifier is reported only once for each function it appears in
xxmodule.c:169:19: error: expected ‘,’ or ‘;’ before ‘corpus’
xxmodule.c:170:3: error: unknown type name ‘settings’
xxmodule.c:171:10: error: request for member ‘read_setting’ in something not a structure or union
xxmodule.c:170:12: warning: variable ‘setting’ set but not used [-Wunused-but-set-variable]
xxmodule.c:169:11: warning: unused variable ‘c’ [-Wunused-variable]
error: command 'gcc' failed with exit status 1


====================================

When I changed
Code:
struct doc {...};
to
Code:
struct {...} doc;
in my header file, the compiler stopped complaining about having "unknown type name 'doc'". It seems like the compiler can't understand C++ syntax.

Here is my build script is:

Code:
from distutils.core import setup, Extension

cdtmmodule = Extension('xx',
                    library_dirs = ['/home/welshamy/workspace/cidtm/cdtm'],
                    sources = ['xxmodule.c'])

setup (name = 'cdtm',
       version = '1.0',
       description = 'This is the cDTM package',
       ext_modules = [cdtmmodule])

Reply With Quote
  #2  
Old November 2nd, 2012, 05:07 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,360 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 55 m 30 sec
Reputation Power: 383
gcc recognizes file types.
Looks like you have files named
.c

On my *nix system I name files with the extension
.C
to have gcc to invoke the c++ compiler.

Clearly, that might not be portable. I'm not sure what your files should be named, perhaps one of
.C
.c++
.cpp

or you could pass an option (probably) that tells gcc which compiler to use,

or maybe by invoking gcc with g++ you'd access the c++ compiler.
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old November 3rd, 2012, 12:40 PM
welshamy welshamy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 welshamy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 11 sec
Reputation Power: 0
Thanks b49P23TIvg. I changed the module extension from .c to .cpp and the problem is solved.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Python module build error. Compiler doesn't understand C++ syntax

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap