0

I was trying to build c through python distutils. I want to replace CC with gcc and follow this page

CC=gcc python setup.py build

Then I got

gcc -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c hello.c -o build/temp.linux-x86_64-2.7/hello.o

creating build/lib.linux-x86_64-2.7

x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/hello.o -o build/lib.linux-x86_64-2.7/hello.so

CC only changed to gcc on first stage, and it would become original x86_64-linux-gnu-gcc, I am not sure is there anything missing, thanks.

2
  • How about defining the linker with LD? Commented Sep 4, 2017 at 8:36
  • didn't work, However, I found the answer, it was LDSHARED needed to be defined Commented Sep 4, 2017 at 8:42

2 Answers 2

0

You must set "CC" with

os.environ["CC"] = "GCC"

However, this sometimes does not work in windows and involves some changes in the config files.

  1. Create file "C:\Python27\Lib\distutils\distutils.cfg" and write this inside

Then insert the following code:

[build] compiler = gcc

  1. Remove all instances of "-mno-cygwin" gcc option from file "C:\Python27\Lib\distutils\cygwinccompiler.py":
  2. In the same file convert this:

    self.set_executables(compiler='gcc -mno-cygwin -O -Wall', compiler_so='gcc -mno-cygwin -mdll -O -Wall', compiler_cxx='g++ -mno-cygwin -O -Wall', linker_exe='gcc -mno-cygwin', linker_so='%s -mno-cygwin %s %s' % (self.linker_dll, shared_option, entry_point))

    to this:

    self.set_executables(compiler='gcc -O -Wall', compiler_so='gcc -mdll -O -Wall', compiler_cxx='g++ -O -Wall', linker_exe='gcc', linker_so='%s %s %s' % (self.linker_dll, shared_option, entry_point))

Sign up to request clarification or add additional context in comments.

Comments

0

I found the answer here, LDSHARED is the variable I need.

The full command would be like this

CC=gcc LDSHARED=gcc -pthread -shared python setup.py build

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.