我在 QTCreator 中学习 Qt5+QtQuick2 并开发了一组共享对象,这些共享对象被重命名为具有.vpi
扩展名,但我无法将 Qt 和 QtQuick 对象链接到这个由以下命令共享的新生成对象。
我应该在其文件中将哪些指令传递给 QtCreator,.pro
以便它具有在 Ubuntu 18.04 32 位上与 iVerilog 一起使用所需的最终输出。
由于大小,我不会列出每个命令和每个.pro
文件,只是在最终构建阶段是相对的并且与 QTCreator 的默认设置不同。
文件.pro
:
CONFIG -= qml_debug
unix:!macx: LIBS += -L/usr/lib/i386-linux-gnu
unix:!macx: LIBS += -lvpi
unix:!macx: LIBS += -lveriuser
INCLUDEPATH += /usr/lib/i386-linux-gnu
INCLUDEPATH += /usr/include/iverilog/
INCLUDEPATH += $$PWD/''
DEPENDPATH += /usr/include/iverilog/
DEPENDPATH += /usr/lib/i386-linux-gnu
DEPENDPATH += $$PWD/''
unix:!macx: PRE_TARGETDEPS += /usr/lib/i386-linux-gnu/libveriuser.a
unix:!macx: PRE_TARGETDEPS += /usr/lib/i386-linux-gnu/libvpi.a
## https://stackoverflow.com/questions/27683777/how-to-specify-compiler-flag-to-a-single-source-file-with-qmake
## http://doc.qt.io/qt-5/qmake-advanced-usage.html#adding-compilers
## configura riscuinho.cpp para ser compilado adequadamente para o vpi
SOURCE_OBJVPI = simulinho_vpi.cpp
objvpi.name = Shared VPI Object Simulinho VPI
objvpi.input = SOURCE_OBJVPI
objvpi.dependency_type = TYPE_C
objvpi.depends = simulinho.o qrc_qml.o
#objvpi.variable_out = OBJECTS
objvpi.output = ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_IN_BASE}.so
objvpi.clean = ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_IN_BASE}.*
objvpi.commands = $${QMAKE_CXX} -c $(CXXFLAGS) -fPIC \
${INCPATH} \
-fstack-protector-strong \
-Wformat -Werror=format-security -Wextra -Wshadow \
-fdebug-prefix-map=/build/iverilog-3pPO9t/iverilog-10.1=. \
-g \
-o ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_IN_BASE}$${first(QMAKE_EXT_OBJ)} \
${QMAKE_FILE_IN}
objvpi.commands += &&
objvpi.commands += $${QMAKE_CXX} --shared $(CXXFLAGS) \
$(LIBS) \
${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_IN_BASE}$${first(QMAKE_EXT_OBJ)} qrc_qml.o \
-o ${QMAKE_FILE_OUT} \
simulinho.o
QMAKE_EXTRA_COMPILERS += objvpi
SOURCE_MODULEVPI = simulinho_vpi.so
#modulevpi.name = Gera o módulo simulinho_vpi.vpi com base no simulinho_vpi.so
modulevpi.input = SOURCE_MODULEVPI
#modulevpi.dependency_type = TYPE_C
modulevpi.depends = compiler_objvpi_make_all
modulevpi.output = ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_IN_BASE}.vpi
modulevpi.clean = ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_IN_BASE}.vpi
modulevpi.clean += ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_IN_BASE}.vpi.debug
modulevpi.commands = cp ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
modulevpi.commands += &&
modulevpi.commands += objcopy --only-keep-debug ${QMAKE_FILE_OUT} ${QMAKE_FILE_OUT}.debug
modulevpi.commands += &&
modulevpi.commands += objcopy --strip-debug ${QMAKE_FILE_OUT}
modulevpi.commands += &&
modulevpi.commands += objcopy --add-gnu-debuglink=${QMAKE_FILE_OUT}.debug ${QMAKE_FILE_OUT}
QMAKE_EXTRA_COMPILERS += modulevpi
verilognize_vvp.name = VerilognizeVVP
verilognize_vvp.depends = compiler_objvpi_clean
verilognize_vvp.depends += compiler_modulevpi_clean
verilognize_vvp.depends += compiler_objvpi_make_all
verilognize_vvp.depends += compiler_modulevpi_make_all
verilognize_vvp.variable_out = VERILOGNIZERS_VVP
verilognize_vvp.commands = iverilog -o simulinho.vvp $${_PRO_FILE_PWD_}/simulinho.v
verilognize_vvp.commands += &&
verilognize_vvp.commands += vvp -M. -msimulinho_vpi simulinho.vvp
QMAKE_EXTRA_TARGETS += verilognize_vvp
verilognize.name = Verilognize
verilognize.depends = compiler_objvpi_clean
verilognize.depends += compiler_modulevpi_clean
verilognize.depends += compiler_objvpi_make_all
verilognize.depends += compiler_modulevpi_make_all
verilognize.depends += verilognize_vvp
verilognize.commands = -echo V E R I L O G N I Z E
QMAKE_EXTRA_TARGETS += verilognize
qmake/make 生成的用于创建 .so 的最后命令:
g++ -c -pipe -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_NO_VERSION_TAGGING -DSIMULINHO_SHAREDLIB -D__SIMULINHO_DUMP__ -DQT_NO_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -fPIC -I../SIMULinho -I. -I/usr/lib/i386-linux-gnu -isystem /usr/include/iverilog -I../SIMULinho -isystem /usr/include/i386-linux-gnu/qt5 -isystem /usr/include/i386-linux-gnu/qt5/QtQuick -isystem /usr/include/i386-linux-gnu/qt5/QtGui -isystem /usr/include/i386-linux-gnu/qt5/QtQml -isystem /usr/include/i386-linux-gnu/qt5/QtNetwork -isystem /usr/include/i386-linux-gnu/qt5/QtCore -I. -isystem /usr/include/libdrm -I/usr/lib/i386-linux-gnu/qt5/mkspecs/linux-g++ -fstack-protector-strong -Wformat -Werror=format-security -Wextra -Wshadow -fdebug-prefix-map=/build/iverilog-3pPO9t/iverilog-10.1=. -g -o simulinho_vpi.o ../SIMULinho/simulinho_vpi.cpp
g++ --shared -pipe -O2 -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_NO_VERSION_TAGGING -DSIMULINHO_SHAREDLIB -D__SIMULINHO_DUMP__ -DQT_NO_DEBUG -DQT_QUICK_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -L/usr/lib/i386-linux-gnu -lvpi -lveriuser -lQt5Quick -lQt5Gui -lQt5Qml -lQt5Network -lQt5Core -lGL -lpthread simulinho_vpi.o qrc_qml.o -o simulinho_vpi.so simulinho.o
函数来源:
// source file simulinho_vpi.cpp
...
static int simulinho_ui_calltf(char*user_data){
char *argv[] = {(char*)"SIMULINHO VPI"};
startMainWindow(1,argv);
return 0;
}
...
// source file simulinho.cpp
...
int startMainWindow(int argc, char *argv[]){
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
...
需要注意的是,通过生成的main.cpp
可执行文件由典型的 QT5 方法调用的代码可以正常工作:
#include "simulinho_global.h"
#include "simulinho.h"
int main(int argc, char *argv[])
{
return startMainWindow(argc, argv);
}
最终执行和产生的错误:
cp simulinho_vpi.so simulinho_vpi.vpi && objcopy --only-keep-debug simulinho_vpi.vpi simulinho_vpi.vpi.debug && objcopy --strip-debug simulinho_vpi.vpi && objcopy --add-gnu-debuglink=simulinho_vpi.vpi.debug simulinho_vpi.vpi
iverilog -o simulinho.vvp /home/carlosdelfino/workspace/RISCuinho/SIMULinho/simulinho.v && vvp -M. -msimulinho_vpi simulinho.vvp
simulinho_vpi:`./simulinho_vpi.vpi' failed to open using dlopen() because:
./simulinho_vpi.vpi: undefined symbol: _Z21qRegisterResourceDataiPKhS0_S0_.
/home/carlosdelfino/workspace/RISCuinho/SIMULinho/simulinho.v:3: Error: System task/function $hello() is not defined by any module.
/home/carlosdelfino/workspace/RISCuinho/SIMULinho/simulinho.v:4: Error: System task/function $openUI() is not defined by any module.
/home/carlosdelfino/workspace/RISCuinho/SIMULinho/simulinho.v:5: Error: System task/function $closeUI() is not defined by any module.
simulinho.vvp: Program not runnable, 3 errors.
Makefile:358: recipe for target 'verilognize_vvp' failed
make: *** [verilognize_vvp] Error 3