Skip to content Skip to sidebar Skip to footer

Hello World Program In Cython Fails With Gcc After Installation Of Python-dev And Linking Libraries

I created a simple hello world program and tried to execute the generated C program using gcc but no matter what I do I get a massive list of undefined references. There are many

Solution 1:

It's better to use python2-config to get the appropriate flags to pass to your compiler:

gcc `python2-config --cflags--ldflags` hello.c -o hello

Because you're compiling and linking in a single invocation, you'll need to pass both --cflags and --ldflags to python2-config.

Solution 2:

Your libpython2.7.so is located in /usr/lib/python2.7/config-x86_64-linux-gnu, not /usr/lib/python2.7. So you need to tell gcc where to look for the library, by adjusting your -L argument.

gcc -I /usr/include/python2.7 -L /usr/lib/python2.7/config-x86_64-linux-gnu -lpython2.7 hello.c -o hello

Post a Comment for "Hello World Program In Cython Fails With Gcc After Installation Of Python-dev And Linking Libraries"