0

I'm trying to compile a program written in c that has python embedded in it.

I ran python3.3-config -cflags to get the cflags I've used in this command.

% >> clang -v einformer.c -o einformer - I/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/include/python3.3m -I/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/include/python3.3m -Wno-unused-result -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/usr/local/opt/sqlite/include
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -disable-free -disable-llvm-verifier -main-file-name einformer.c -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 136 -v -g -resource-dir /usr/bin/../lib/clang/4.2 -D NDEBUG -I /usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/include/python3.3m -I /usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/include/python3.3m -I /usr/local/include -I /usr/local/opt/sqlite/include -fmodule-cache-path /var/folders/lz/5nhsdlnn3x9g8ry_mkgtgh500000gp/T/clang-module-cache -c-isystem /usr/include/python2.6 -c-isystem . -O3 -Wno-unused-result -Wall -Wstrict-prototypes -fdebug-compilation-dir /Users/ardentapprentice/dev/osx/test -ferror-limit 19 -fmessage-length 140 -fwrapv -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.8.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fno-common -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/lz/5nhsdlnn3x9g8ry_mkgtgh500000gp/T/einformer-T6nymD.o -x c einformer.c
clang -cc1 version 4.2 based upon LLVM 3.2svn default target x86_64-apple-darwin12.2.0
ignoring duplicate directory "/usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/include/python3.3m"
ignoring duplicate directory "/usr/local/include"
  as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/Cellar/python3/3.3.0/Frameworks/Python.framework/Versions/3.3/include/python3.3m
 /usr/local/opt/sqlite/include
 /usr/include/python2.6
 .
 /usr/local/include
 /usr/bin/../lib/clang/4.2/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
einformer.c:92:25: warning: implicit declaration of function 'PyString_AsString' is invalid in C99 [-Wimplicit-function-declaration]
    path_array[i] = PyString_AsString(pypath);
                    ^
1 warning generated.
 "/usr/bin/ld" -demangle -dynamic -arch x86_64 -dynamic -macosx_version_min 10.8.0 -o einformer /var/folders/lz/5nhsdlnn3x9g8ry_mkgtgh500000gp/T/einformer-T6nymD.o -lSystem /usr/bin/../lib/clang/4.2/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "_PyList_GetItem", referenced from:
      _main in einformer-T6nymD.o
  "_PyList_Size", referenced from:
      _main in einformer-T6nymD.o
  "_PyRun_SimpleStringFlags", referenced from:
      _main in einformer-T6nymD.o
  "_PyString_AsString", referenced from:
      _main in einformer-T6nymD.o
  "_Py_Finalize", referenced from:
      _main in einformer-T6nymD.o
  "_Py_Initialize", referenced from:
      _main in einformer-T6nymD.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It seems as though clang is having trouble locating headers maybe? <Python.h> is included in the source I'm not sure what I'm doing wrong :/

Ive spent about 3 hours looking through the python documentation http://docs.python.org/3.3/c-api/index.html and googling around, but I cant seem to find any information that helps me.

4
  • It seems to have found the headers fine but not the libraries. Maybe add --libs to your python3.3-config (assuming it's a similar system to pkg-config)? Commented Feb 26, 2013 at 9:35
  • running python3.3-config --libs gives me -ldl -framework CoreFoundation -lpython3.3m are these the locations of the libraries on my system? how do I tell clang where the libraries are? Commented Feb 26, 2013 at 9:57
  • Try to find the where these libraries are and try to export the env variable LDFLAGS Commented Feb 26, 2013 at 10:09
  • I'm using zsh; when the env variable is exported, it is added to my .zshrc as LDFLAGS=/usr/local/Frameworks/Python.framework/Versions/3.3/lib/ where the dylibs have been symlinked? or should this be the libraries under /Library/Frameworks/Python.framework/Versions/3.3/lib/ Commented Feb 26, 2013 at 10:59

1 Answer 1

1

python3.3-config --cflags only gives the arguments needed to find the headers. python3.3-config --ldflags will give you the linker flags. This means that you should be able to compile your program with a compiler invocation something like:

clang -v einformer.c -o einformer $(python3.3-config --cflags) $(python3.3-config --ldflags)
Sign up to request clarification or add additional context in comments.

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.