[Distutils] setup.py demo.C build (gcc vs. g++) (distutils)

Mowry, Peter peter.mowry at amd.com
Wed May 16 19:19:41 CEST 2007


> echo $CC $CPP $CXX $LDSHARED
g++ g++ g++ g++

> python2.5 setup.py build --compiler=unix
running build
running build_ext
building 'demo' extension
creating build
creating build/temp.linux-x86_64-2.5
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wstrict-prototypes
-fpermissive -fPIC
-I/tool/pandora64/.package/python-2.5/include/python2.5 -c demo.C -o
build/temp.linux-x86_64-2.5/demo.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid for
C/ObjC but not for C++
creating build/lib.linux-x86_64-2.5
gcc -pthread -shared build/temp.linux-x86_64-2.5/demo.o -o
build/lib.linux-x86_64-2.5/demo.so

I saw CC CPP CXX LDSHARED - and set them all to g++, but it still does
two calls to gcc, not g++ :-(

--Thanks



> setup.py:
#!/tool/pandora64/bin/python2.5

from distutils.core import setup, Extension

ext_demo = Extension('demo',
  sources = ['demo.C'])

setup (name = 'PackageName',
       version = '1.0',
       description = 'This is a demo package',
       ext_modules = [ext_demo])



> demo.C:
#include <Python.h>

static PyObject* spam_system(PyObject *self, PyObject *args)
{
	const char* command;
	int sts;
	
	if (!PyArg_ParseTuple(args, "s", &command))
		return NULL;
	sts = system(command);
	return Py_BuildValue("i", sts);
}

static PyMethodDef demo_methods[] = {
	{"spam_system", spam_system, METH_VARARGS, "spam_system() doc
string"},
	{NULL, NULL}
};

PyMODINIT_FUNC
initdemo(void)
{
	Py_InitModule("demo", demo_methods);
}



-----Original Message-----
From: Phillip J. Eby [mailto:pje at telecommunity.com] 
Sent: Wednesday, May 16, 2007 11:24 AM
To: Mowry, Peter; Matt Good
Cc: distutils-sig at python.org; David Arnold
Subject: RE: [Distutils] setup.py demo.C build (gcc vs. g++) (distutils)

At 09:56 PM 5/15/2007 -0500, Mowry, Peter wrote:
>set CC="g++"
>set CC=g++
>Neither of these work :-(

I may have misspoken; it may be the CXX variable you need to set, 
rather than CC.


>I also tried:
>python2.5 setup.py demo.C build --compiler=g++
>
>python2.5 setup.py demo.C build --help-compiler
>gives bcpp, cygwin, emx, mingw32, msvc, mwerks, unix (g++ is not an
>option)

That's because those are compiler *types*, not executables.  To 
override the executables, you need to use environment variables like 
CC, CPP, CXX, CCSHARED, LDSHARED, etc.  See the 
"customize_compiler()" function in the "distutils.sysconfig" module, 
as that's what sets the executable names that will be invoked.







More information about the Distutils-SIG mailing list