Error at running example
grd opened this issue · 17 comments
The installation of nimble install https://github.com/jerous86/nimqt
was good.
I installed Qt6 on my xubuntu 22.04 with the following command sudo apt install qt6-base-dev
Then git clone https://github.com/jerous86/nimqt
and cd nimqt
So far so good ;-)
Running nim cpp examples/hello.nim
however got me error messages and didn't work :-(
Hint: used config file '/home/user/.choosenim/toolchains/nim-1.6.10/config/nim.cfg' [Conf]
Hint: used config file '/home/user/.choosenim/toolchains/nim-1.6.10/config/config.nims' [Conf]
........................................................................................................................................................
CC: ../../.nimble/pkgs/nimqt-0.1/nimqt/qtcore/qstring.nim
CC: ../../.nimble/pkgs/nimqt-0.1/nimqt/qtcore/qobject.nim
CC: ../../.nimble/pkgs/nimqt-0.1/nimqt.nim
CC: ../../.nimble/pkgs/nimqt-0.1/nimqt/qtwidgets/qapplication.nim
/home/user/.cache/nim/hello_d/@m..@s..@s.nimble@spkgs@snimqt-0.1@snimqt@sqtcore@sqstring.nim.cpp:8:10: fatal error: QtCore/qstring.h: No such file or directory
8 | #include "QtCore/qstring.h"
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
Error: execution of an external compiler program 'g++ -c -std=gnu++14 -funsigned-char -w -fmax-errors=3 -fpermissive -std=c++17 -I/home/user/.nimble/pkgs/nimqt-0.1 -Iqtpaths: Unknown option 'query'. -fPIC -I/home/user/.choosenim/toolchains/nim-1.6.10/lib -I/home/user/nimqt/examples -o /home/user/.cache/nim/hello_d/@m..@s..@s.nimble@spkgs@snimqt-0.1@snimqt@sqtcore@sqstring.nim.cpp.o /home/user/.cache/nim/hello_d/@m..@s..@s.nimble@spkgs@snimqt-0.1@snimqt@sqtcore@sqstring.nim.cpp' failed with exit code: 1
/home/user/.cache/nim/hello_d/@m..@s..@s.nimble@spkgs@snimqt-0.1@snimqt@sqtcore@sqobject.nim.cpp:8:10: fatal error: QtCore/qnamespace.h: No such file or directory
8 | #include "QtCore/qnamespace.h"
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
user@Thinkpad-t440p:~/nimqt$ /home/user/.cache/nim/hello_d/@m..@s..@s.nimble@spkgs@snimqt-0.1@snimqt.nim.cpp:8:10: fatal error: QtWidgets/qlayout.h: No such file or directory
8 | #include "QtWidgets/qlayout.h"
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
/home/user/.cache/nim/hello_d/@m..@s..@s.nimble@spkgs@snimqt-0.1@snimqt@sqtwidgets@sqapplication.nim.cpp:8:10: fatal error: QtWidgets/qapplication.h: No such file or directory
8 | #include "QtWidgets/qapplication.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
I suspect qtpath is behaving differently to what I am used to.
Can you give me the output of qtpaths --query QT_INSTALL_HEADERS
?
qtpaths --query QT_INSTALL_HEADERS
output:
qtpaths: could not find a Qt installation of ''
Btw: I am running Qt6 latest, which is 6.2.4+dfsg-2ubuntu1
Edit:
I also have installed Qt with the Maintenacetool and that is indeed 6.4.1 but that is it. I didn't do anything further.
Maybe try qtchooser (https://manpages.ubuntu.com/manpages/kinetic/en/man1/qtchooser.1.html)?
On my system a similar issue was fixed using export QT_SELECT=qt6
.
What did you do after you run the Qt MaintenanceTool? How did you make Qt 6.4.1 "active" and running?
I did set export QT_SELECT=qt6
in my .bashrc
with source .bashrc
The result of qtchooser -print-env
is: qtchooser: could not find a Qt installation of 'qt6'
But before I did install Qt6: sudo apt install qt6-base-dev
This is happening on both of my Linux systems (one with Xubuntu and on Linux Mint)
What does qtchooser -list-versions
print? Maybe qt6 is not listed among them, but named a bit differently?
On my system setting QT_SELECT
seems to be enough:
ubuntu@nimqt:~/nimqt$ qtchooser -list-versions
4
5
qt4-x86_64-linux-gnu
qt4
qt5-x86_64-linux-gnu
qt5
qt6
ubuntu@nimqt:~/nimqt$ qtchooser -print-env
qtchooser: could not find a Qt installation of ''
ubuntu@nimqt:~/nimqt$ QT_SELECT=qt6 qtchooser -print-env
QT_SELECT="qt6"
QTTOOLDIR="/usr/lib/qt6/bin"
QTLIBDIR="/usr/lib/x86_64-linux-gnu"
The only Qt variables inside my "set" command are:
QT_ACCESSIBILITY=1
QT_QPA_PLATFORMTHEME=gtk2
QT_SELECT=qt6
I run this on my Linux Mint computer so gtk2 is normal.
After I run qtchooser -list-versions
I get this result:
4
5
default
qt4-x86_64-linux-gnu
qt4
qt5-x86_64-linux-gnu
qt5
When I run make all
inside the nimqt directory then I get quite a lot of warnings and errors. They all say this:
g++: warning: could: linker input file unused because linking not done
g++: error: could: linker input file not found: No such file or directory
Now I have something more. It still doesn't compile completely but I think that we are getting there.
What did I do? After struggling with qtchooser I decided to check the manual and after that I made it work.
sudo qtchooser --install qt6 /home/user/Qt/6.4.1/gcc_64/bin/qmake
Now running in nimqt the command make all
results in actually compiling ;-) It compiles the Qt stuff, I am impressed ;-)
But there is an error:
This:
undefined reference to QtPrivate::QMetaTypeInterfaceWrapper<QString>::metaType
In function:
void QObject::setObjectName<void>(QString const&)
Probably leads to:
undefined reference to QObject::doSetObjectName(QString const&)
This is the complete error message:
/usr/bin/ld: /home/user/.cache/nim/calc_d/@mcalc.nim.cpp.o:(.data.rel.ro._ZN10w_internal16MetaDataProviderI10MyLineEditE6arraysE[_ZN10w_internal16MetaDataProviderI10MyLineEditE6arraysE]+0xb0): undefined reference to `QtPrivate::QMetaTypeInterfaceWrapper<QString>::metaType'
/usr/bin/ld: /home/user/.cache/nim/calc_d/@mcalc.nim.cpp.o: in function `void QObject::setObjectName<void>(QString const&)':
@mcalc.nim.cpp:(.text._ZN7QObject13setObjectNameIvEEvRK7QString[_ZN7QObject13setObjectNameIvEEvRK7QString]+0x23): undefined reference to `QObject::doSetObjectName(QString const&)'
collect2: error: ld returned 1 exit status
I have never encountered that error, so maybe it is still linking the wrong libraries.
As mentioned in https://forum.nim-lang.org/t/9785 I have some new code that uses just qmake
to determine paths. This should be more reliable than the qtchooser
mess :)
I'll push the changes later today.
I pushed a bunch of commits, can you check if the undefined references still occur?
There should be no need anymore to use QT_SELECT or qtchooser or anything. It should suffice to define environment variable QMAKE_PATH, e.g.
QMAKE_PATH=/home/user/Qt/6.4.1/gcc_64/bin/qmake make calc
No. after a git pull
I got rid of all the environment variables inside my SET and now I have a different error.
/home/user/nimqt/qt/6.4.1_minimal/nimqt.nim(26, 54) Error: type mismatch: got <string, allow_run_time: bool>
but expected one of:
proc replace_vars(s: string; allow_run_time: static bool;
enable_path_check: bool): string
first type mismatch at position: 3
missing parameter: enable_path_check
expression: nimqt_paths.replace_vars("${Qt_install_headers}", allow_run_time = false)
But good job! I think that you are on the right track.
Huh, weird that I did not encounter that. But that should be fixed now! :)
After I got rid of the SET stuff inside my .bashrc and try to install nimqt again, I got a lot of linker errors, so I did set on de SET stuff again and got the same old story:
usr/bin/ld: /home/user/.cache/nim/calc_d/@mcalc.nim.cpp.o:(.data.rel.ro._ZN10w_internal16MetaDataProviderI10MyLineEditE6arraysE[_ZN10w_internal16MetaDataProviderI10MyLineEditE6arraysE]+0xb0): undefined reference to `QtPrivate::QMetaTypeInterfaceWrapper<QString>::metaType'
/usr/bin/ld: /home/user/.cache/nim/calc_d/@mcalc.nim.cpp.o: in function `void QObject::setObjectName<void>(QString const&)':
@mcalc.nim.cpp:(.text._ZN7QObject13setObjectNameIvEEvRK7QString[_ZN7QObject13setObjectNameIvEEvRK7QString]+0x23): undefined reference to `QObject::doSetObjectName(QString const&)'
collect2: error: ld returned 1 exit status
I am wondering: if you can compile then why can't I? What OS are you using? And what toolchain?
I'm running it on OSX (installed Qt6.4.1 using brew) and an ubuntu virtual machine running in multipass (with Qt6.2.4 installed using apt). On both have nim 1.6.10 installed using choosenim.
On OSX make calc
and on ubuntu QMAKE_PATH=qmake6 make calc
successfully compile.
Something suspicious: in qobject.h
for Qt6.4.1 I find
void setObjectName(const QString &name) { doSetObjectName(name); }
while for Qt6.2.4
void setObjectName(const QString &name);
(and doSetObjectName is not defined in that header)
So my guess is that different Qt versions are used in different places?
After reading your post a couple of times the only thing I have to say is: What a major ***** they are at Qt and I laughed quite a lot! This is so stupid. Never ever change an API ! (unless when you change it with a major release)
Edit: I also used QMAKE_PATH=qmake6 make calc
(so I think that I use Qt6.2.4) and now it says something else:
Traceback (most recent call last)
/home/user/nimqt/examples/calc.nim(124) calc
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
make[1]: *** [Makefile:20: run_calc] Segmentation fault (core dumped)
make[1]: Leaving directory '/home/user/nimqt'
Hmm I also have it on linux (hadn't installed X yet, and was just focused on getting it compiled).
OSX works fine.
It seems to be related to handling commandline arguments.
E.g.
let app=newQApplication(@["test"])
echo static_QCoreApplication_arguments()
I would expect this to print @["test"]
. However, it returns an empty list.
I have no idea yet why this happen, nor how to solve this for now :/
Newest commit fixed it for me, hopefully also for you :)
It was something with deallocated memory, I think. And I guess OSX handles it quite differently than linux.
The install_name_tool
is used on OSX only to add the library paths to the binary. On linux it's not necessary, I think.
It is working!!!!!!
Great job!
It is working on both of my linux computers.
And btw, I don't think that I can deal with the ".ui" files. I am way too novice about Nim. I am still learning it (and I really hate C++). My idea was indeed to parse the XML file but your solution is probably a lot better. So, I am sorry.
But, a very good job!