Tux
Tux

Reputation: 11

Can't link Python libraries inside C program

I want to run a basic python script inside a C program using Eclipse. This is the code:

#include <Python.h>

int main(int argc, char *argv[])
{
  Py_SetProgramName(argv[0]);  /* optional but recommended */
  Py_Initialize();
  PyRun_SimpleString("from time import time,ctime\n"
                     "print 'Today is',ctime(time())\n");
  Py_Finalize();
  return 0;
}

I am trying to link to several shared libraries like libpython2.7.so in Eclipse linker settings but I always get this error:

Invoking: GCC C Linker
gcc -L/usr/lib/x86_64-linux-gnu/ -o "Test"  ./src/Test.o   -llibpython2.7
/usr/bin/x86_64-linux-gnu-ld: cannot find -llibpython2.7
collect2: error: ld returned 1 exit status

I can't find any tutorial with the name of the lib that should be linked.

Upvotes: 0

Views: 66

Answers (1)

Attie
Attie

Reputation: 6969

Typically -l doesn't require the lib prefix or the .so suffix...

Try using -lpython2.7 instead of -llibpython2.7.

Upvotes: 1

Related Questions