wlav / cppyy

Other
384 stars 38 forks source link

how to include QT ? #203

Open zoldaten opened 7 months ago

zoldaten commented 7 months ago

hi ! thanks fo cppyy! i have installed on my raspberry pi aarch64 Raspbian Bullseye with pip. and it seems it works with simple:

import cppyy
#working
cppyy.include("foo.h")
cppyy.load_library("foo")
from cppyy.gbl import Foo
f = Foo()
f.bar() #should output 'Hello'

:

>>> %Run test_4.py
(Re-)building pre-compiled headers (options: -O2 -march=native); this may take a minute ...
error: the clang compiler does not support '-march=native'
error: the clang compiler does not support '-march=native'
Error: Parsing Linkdef file etc/dictpch/allLinkDefs.h
/home/pi/.local/lib/python3.9/site-packages/cppyy_backend/loader.py:139: UserWarning: No precompiled header available (failed to build); this may impact performance.
  warnings.warn('No precompiled header available (%s); this may impact performance.' % msg)
error: the clang compiler does not support '-march=native'
Hello
>>> 

but when i try something more complicated i see:

Traceback (most recent call last):
  File "/home/pi/software/vnetwork/build/test_4.py", line 5, in <module>
    cppyy.include("v_smart_cane_demo.h")
  File "/home/pi/.local/lib/python3.9/site-packages/cppyy/__init__.py", line 267, in include
    raise ImportError('Failed to load header file "%s"%s' % (header, err.err))
ImportError: Failed to load header file "my_demo.h"
In file included from input_line_18:1:
In file included from ./my_demo.h:8:
In file included from /usr/local/include/network/demo/demo_base.h:8:
/usr/local/include/network/core/demo_base.h:11:10: fatal error: 'QObject' file not found
#include <QObject>
         ^~~~~~~~~

it cant find QT as i understand. but i have it installed. so i need lib included i think. which one from /opt/Qt6/lib ?

i tried cppyy.include("/opt/Qt6/lib/libQt6Core.so.6.4.2") but it failed.

may be i should include a path ? please see - https://stackoverflow.com/questions/6597117/error-when-including-qt-headers

torokati44 commented 7 months ago

Just curious - is there a reason for not using the official Python bindings for Qt (PySide2)?

zoldaten commented 7 months ago

Just curious - is there a reason for not using the official Python bindings for Qt (PySide2)?

i just need one class func from big project on c++ without rewrite it.

wlav commented 7 months ago

Which version is this? error: the clang compiler does not support '-march=native' should happen anymore on ARM.

As for the header file, it's likely not in any of the standard directories, so it needs to be added. Probably something like:

qtpath = "/usr/include/qt5"
cppyy.add_include_path(qtpath)

And yes, you also still need to load all relevant libraries.

zoldaten commented 7 months ago
qtpath='/opt/Qt6/include'
cppyy.add_include_path (qtpath)

didnt fix (

Which version is this? error: the clang compiler does not support '-march=native' should happen anymore on ARM. have no idea. i havent got clang installed.

wlav commented 7 months ago

Just to be sure, does /opt/Qt6/include/QObject exist?

For the version, the question is about cppyy's version, not clang's. :)