Re: [gtk-osx-users] Can not compile python-launcher.c





On Apr 26, 2020, at 6:02 AM, Timo via gtk-osx-users-list <gtk-osx-users-list gnome org> wrote:

Hello, I'm not able to compile python-launcher.c from gtk-mac-bundler on Mojave. Tried both with the 
system's Python 2 version as the Python 3 version built through jhbuild. For Python 2, the python-config 
command didn't pick up the directory which contains Python.h, so had to include it manually. Here's some 
relevant output:

bash-3.2$ gcc -L$PREFIX/lib `python-config --cflags --ldflags` -o $PREFIX/bin/testapp-launcher 
python-launcher.c
python-launcher.c:21:10: fatal error: 'Python.h' file not found
#include <Python.h>
         ^~~~~~~~~~
1 error generated.

bash-3.2$ gcc -L$PREFIX/lib `python-config --cflags --ldflags` 
-I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -o 
$PREFIX/bin/testapp-launcher python-launcher.c
python-launcher.c:106:5: warning: implicit declaration of function 'Py_SetPath' is invalid in C99
      [-Wimplicit-function-declaration]
    Py_SetPath(path);
    ^
python-launcher.c:106:5: warning: this function declaration is not a prototype [-Wstrict-prototypes]
python-launcher.c:168:27: warning: incompatible pointer types passing 'wchar_t **' (aka 'int **') to
      parameter of type 'char **' [-Wincompatible-pointer-types]
    PySys_SetArgvEx(argc, wargv, 0);
                          ^~~~~
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/sysmodule.h:14:46: note:
      passing argument to parameter here
PyAPI_FUNC(void) PySys_SetArgvEx(int, char **, int);
                                             ^
3 warnings generated.
Undefined symbols for architecture x86_64:
  "_Py_SetPath", referenced from:
      _main in python-launcher-875336.o
ld: symbol(s) not found for architecture x86_64
python-launcher.c:106:5: warning: implicit declaration of function 'Py_SetPath' is invalid in C99
      [-Wimplicit-function-declaration]
    Py_SetPath(path);
    ^
python-launcher.c:106:5: warning: this function declaration is not a prototype [-Wstrict-prototypes]
python-launcher.c:168:27: warning: incompatible pointer types passing 'wchar_t **' (aka 'int **') to
      parameter of type 'char **' [-Wincompatible-pointer-types]
    PySys_SetArgvEx(argc, wargv, 0);
                          ^~~~~
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/sysmodule.h:14:46: note:
      passing argument to parameter here
PyAPI_FUNC(void) PySys_SetArgvEx(int, char **, int);
                                             ^
3 warnings generated.
clang: error: linker command failed with exit code 1 (use -v to see invocation)

bash-3.2$ python-config --cflags --ldflags
-iwithsysroot 
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
 -iwithsysroot 
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
 -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common 
-fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 
-DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE
-L/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
 -lpython2.7 -ldl -framework CoreFoundation


bash-3.2$ gcc -L$PREFIX/lib `python3-config --cflags --ldflags` -o $PREFIX/bin/testapp-launcher 
python-launcher.c
Undefined symbols for architecture x86_64:
  "_PyRun_SimpleFileExFlags", referenced from:
      _main in python-launcher-f4f0b7.o
  "_PySys_SetArgvEx", referenced from:
      _main in python-launcher-f4f0b7.o
  "_Py_Finalize", referenced from:
      _main in python-launcher-f4f0b7.o
  "_Py_Initialize", referenced from:
      _main in python-launcher-f4f0b7.o
  "_Py_SetPath", referenced from:
      _main in python-launcher-f4f0b7.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

bash-3.2$ python3-config --cflags --ldflags
-I/Users/gtk3/gtk/inst/include/python3.8 -I/Users/gtk3/gtk/inst/include/python3.8 -Wno-unused-result 
-Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 
-I/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include -isysroot 
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -mmacosx-version-min=10.14 -arch x86_64 
-I/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include -isysroot 
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -mmacosx-version-min=10.14
-lintl -ldl -framework CoreFoundation

Am I missing something obvious? Thanks.

It seems that python 3.8 requires an additional argument to python3-config, --embed.
From https://docs.python.org/3/whatsnew/3.8.html,
"To embed Python into an application, a new --embed option must be passed to python3-config --libs --embed to 
get -lpython3.8 (link the application to libpython). To support both 3.8 and older, try python3-config --libs 
--embed first and fallback to python3-config --libs (without --embed) if the previous command fails."

Gtk-osx doesn't support Python2.

Regards,
John Ralls




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]