I want to use Matlab's C API within QT (http://www.mathworks.com/help/techdoc/matlab_external/f39876.html#bsfvqhp-1) under Windows for opening a .mat file. In my .pro file I have included
INCLUDEPATH += "C:\Program Files\MATLAB\R2010b\extern\include"
which works fine (the code compiles). But when trying to link the libmat.lib file (I have read the .dll files cannot be linked directly) using
LIBS += -L"C:\Program Files\MATLAB\R2010b\extern\lib\win32\microsoft" -llibmat
the application crashes on execution. The error given says [file].exe exited with code -1073741515
I'm neither a QT nor a Windows expert but for this project I am forced to use both (I guess it would be easier to fix this in GNU/Linux) so any help would be appreciated. Using Windows XP, QT version 4.7.0 with Qt Creator 2.0.1, and Matlab R2010b.
The last output from the compiler just in case it is useful:
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug/MainUI.exe debug/main.o debug/maingui.o debug/matparser.o debug/matutils.o debug/moc_maingui.o -L'c:/Qt/2010.05/qt/lib' -lmingw32 -lqtmaind "-LC:\Program Files\MATLAB\R2010b\extern\lib\win32\microsoft" -llibmat -lQtGuid4 -lQtCored4
I just tested building a simple C program that uses the MAT-File Interface Library with no problems. The example file is located in: matlabroot/examples/eng_mat/matcreat.c. I am compiling using MinGW on a Windows XP 32-bit machine. Here is the Makefile I used:
# root directory of MATLAB installation
MATLABROOT="/c/Program Files/MATLAB/R2010b"
.PHONY : all clean run
all: matcreat
matcreat:
gcc ${MATLABROOT}/extern/examples/eng_mat/matcreat.c -o matcreat \
-I${MATLABROOT}/extern/include \
-L${MATLABROOT}/extern/lib/win32/microsoft -llibmat -llibmx
clean:
rm -rf matcreat *.exe *.mat
run:
# UNIX uses LD_LIBRARY_PATH to find libs at runtime, Windows/MinGW uses PATH
#PATH=${MATLABROOT}/bin/win32:"${PATH}" ./matcreat
I suspect that the Matlab library will have been compiled with MSVC and since you say you are compiling your own code with MingW I would imagine the two are incompatible.
Have a look at the MingW page on mixing compilers for more information.
Related
I am statically linking an QT application, but for some reason when i open the executable i am getting errors for missing dlls.
Basically i am linking the following libs:
### LINKER FLAGS ###
LDFLAGS = -LC:/Qt/5.15.0/mingw81_32/lib
LDLIBS = -lQt5Widgets -lQt5Gui -lQt5Core
Why am i getting errors for missing dlls when i am statically linking everything?
The compilation and linking passes correctly, the executable is generated also..i have no idea why it needs dlls.
EDIT:
Missing dlls:
libgcc_s_dw2-1.dll,
libstdc++-6.dll,
Qt5Code.dll,
Qt5Widgets.dll
To elaborate on CristiFati's reply, you need a line like this in your project file:
QMAKE_LFLAGS += -static-libstdc++ -static-libgcc
though I'd prefer:
QMAKE_LFLAGS_RELEASE += -static-libstdc++ -static-libgcc
Note that if you want a truly standalone, self-contained binary, you'll need to build yourself a static Qt library. That's kind of a big deal, and unfortunately not as well documented as most of Qt-land is.
I've try few things but I still have this error when trying to cmake for blackfin:
CMake Error at CMakeLists.txt:116 (message):
Fatal error: QT (version >= 4.5.0) required. Cmake tries to detect QT4 by
searching for 'qmake' in your PATH.If you have QT4 installed, make sure
qmake is found in your PATH. If you compiled QT4 yourself make sure your
new qmake ist found _first_ in your PATH.
I'm trying to compile the source of musescore 0.9.5 to keep it compatible with the existing version of QT in uClinux options
What I did is to compile the uClinux kernel with QT lib so I can have the suitable embedded QT.
then I modified the Makefile of musescore to build with uclinux compilers. I've try different things so I show here the latest trial:
bfin:
mkdir build;
mkdir install; \
cd build;
cmake -DCMAKE_TOOLCHAIN_FILE=bfin.cmake -DCMAKE_VERBOSE_MAKEFILE=TRUE -\
DQT_QMAKE_EXECUTABLE=/home/william/Development_new/Music_Recognition/code/uCLin\
ux/rev2011R1/uclinux-dist/lib/qt-embedded/build-qt-embedded-linux-opensource-sr\
c-4.5.1/bin -libdir=/home/william/Development_new/Music_Recognition/cod\
e/uCLinux/rev2011R1/uclinux-dist/lib/qt-embedded/build-qt-embedded-linux-openso\
urce-src-4.5.1/lib \
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
mscore;
in the CMakeLists.txt I did add:
link_directories(/home/william/Development_new/Music_Recognition/code/uCLinux/r\
ev2011R1/uclinux-dist/lib/qt-embedded/build-qt-embedded-linux-opensource-src-4.\
5.1/bin)
SET(CMAKE_MODULE_PATH /home/william/Development_new/Music_Recognition/code/uCLi\
nux/rev2011R1/uclinux-dist/lib/qt-embedded/build-qt-embedded-linux-opensource-s\
rc-4.5.1/bin)
SET(CMAKE_PREFIX_PATH /home/william/Development_new/Music_Recognition/code/uCLi\
nux/rev2011R1/uclinux-dist/lib/qt-embedded/build-qt-embedded-linux-opensource-s\
rc-4.5.1/bin)
SET(QT_QMAKE_EXECUTABLE /home/william/Development_new/Music_Recognition/code/uC\
Linux/rev2011R1/uclinux-dist/lib/qt-embedded/build-qt-embedded-linux-opensource\
-src-4.5.1/bin)
my bfin.cmake look like that:
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
#
SET (BFIN "/opt/uClinux/bfin-uclinux")
# specify the cross compiler
SET(CMAKE_C_COMPILER ${BFIN}/bin/bfin-uclinux-gcc)
SET(CMAKE_CXX_COMPILER ${BFIN}/bin/bfin-uclinux-g++)
SET(CMAKE_LINKER ${BFIN}/bin/bfin-uclinux-ld)
#/opt/uClinux/bfin-uclinux/bfin-uclinux/runtime/usr/lib
LINK_DIRECTORIES("${BFIN}/usr/lib")
SET(CMAKE_FIND_ROOT_PATH
/opt/uClinux/bfin-uclinux/bfin-uclinux
/opt/uClinux/bfin-linux-uclibc
/opt/uClinux/bfin-linux-uclibc/bfin-linux-uclibc/runtime)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Thanks in advance for the help,
William
You need to put qmake in your $PATH. If you prefer to use QT_QMAKE_EXECUTABLE it has to point to the actual qmake binary and not the directory.
That being said, MuseScore 0.9.5 is a very very old version of MuseScore, the current version is 1.1 and 1.2 is coming soon. Check http://musescore.org for more information about MuseScore and don't hesitate to contact the developers on #musescore on freenode.net or on the developer mailing list at http://musescore.org/mailing-list
I have a project in Qt which consists of the set of projects. Projects is building via MinGW and it does not create any .cov file.
I installed bullseye and enabled coverage build but it still does not create *.con file if I try to set path variable like
C:\Program Files\BullseyeCoverage\bin;%PATH%
the build is constantly failing I always get
gcc: CreateProcess: No such file or directory
The file to build whole project is following :
d:\QtSDK\Desktop\Qt\4.7.4\mingw\bin\qmake.exe Simulator.pro -r -spec win32-g++ "CONFIG+=release"
PATH=D:\QtSDK\mingw\bin\;%PATH%
D:\QtSDK\mingw\bin\mingw32-make -f ./Makefile
How can I measure code coverage? Please help.
If somebody interested in this question - I already figured it out.
Here is a solution -
To set bullseye interceptors before your gcc compiler just replace variables
QMAKE_CC = %Bullseye gcc path%
QMAKE_CXX = %Bullseye g++ path%
This variable should be defined in *.pro file or in gcc config file, which is located in
%QTSDKPath%\Desktop\Qt\4.7.4\mingw\mkspecs\win32-g++\ // if you are using gcc from win32
You also need to set environment variable:
BULLSEYE_PATH=%PATH TO REAL COMPILER%
How to change compiler (GCC) in Qt? I've installed GCC 4.4 and 4.6. At the momment Qt uses 4.4 but I'd like it to use 4.6. How to do it?
In the build sequence it may have a qmake command like qmake YourProject.pro -r -spec linux-g++-64 the choice of the tool chain is done in the spec file here linux-g++-64. Your will find this file in path-to-the-sdk/qt/mkspecs/linux-g++-64 (you get the concept right?)... If you open the spec file you will see that it includes the linux spec and the g++ spec.
One solution is to copy the g++ spec file and rename it g++-4.6 for example edit it and change :
QMAKE_CC = gcc
QMAKE_CXX = g++
to :
QMAKE_CC = gcc-4.6
QMAKE_CXX = g++-4.6
Idem for the linux-g++-64 it can be copied to linux-g++-4.6-64 and modify the include(...) command to include your new g++-4.6 file.
Finally build your project with qmake YourProject.pro -r -spec linux-g++-4.6-64.
I hope it's clear :) ...
I realise I am very late for the party but on Linux it is as simple as follows:
qmake -makefile <your-project.pro> -spec linux-clang
On my system, all sorts of different mkspecs are available at:
/usr/lib/x86_64-linux-gnu/qt5/mkspecs
Running make CC=my-custom-gcc CXX=my-custom-g++ LINK=my-custom-g++ seems to do the trick for me. But it might not be 100% safe (i.e. I wouldn't be surprised if running qmake with Linux specs and then specifying mingw32 compilers would fail).
If you are using Qt Creator 2.2.0, you can try Tools > Options > Tool Chains and then Add > MinGW.
I am working on a project where I have to read a dicom image.
I am unable to install dcmtk. I am using win7 64-bit and vs2010.
Please explain the procedure to include dcmtk in my program.
To use the Windows + DCMTK + QT, you need to execute these follow steps:
Compile the DCMTK (Step 1.A)
Create your sample application (Step 2)
Create your QT project file referring the compiled/installed DCMTK Libs (Step 3.B)
Compile your application in your IDE (Step 4.B)
If you are reading this and don't want to use the Qt, I am answering a version without Qt as well.
Windows+VisualStudio+DCMTK: Steps 1.A, 2, 3.A and 4.A
Linux+GCC+DCMTK: Steps 1.B, 2, N/A, 4.C
1) Compile the DCMTK
First of all, to use the DCMTK library in your application, you should compile the DCMTK source code to generate the libraries:
While I am writing this, the last available version is 3.6.0. So, we should download it:
ftp://dicom.offis.de/pub/dicom/offis/software/dcmtk/dcmtk360/dcmtk-3.6.0.zip
After the download is finished, you need to unzip the folder. The DCMTK source doesn't have a project file, but it is not a problem, there is a CMakelist file responsible for generating a project file in your desirable Operational System/Compiler. If you are not familiar with CMake tool, you can read more here (https://cmake.org/)
1.A) Compiling on Windows/Visual Studio 2012
1.A.1) You need to have an installed compiler, in my case, it was the Visual Studio 2012
1.A.2) Run the CMake tool to generate a project file to Visual Studio 2012. You need be able to fill the source DCMTK directory.
1.A.3) Now, execute the VisualStudio 2012, open the file sln created in the previous step (2) and compile the target ALL_BUILD
1.A.4) Re-Execute VisualStudio in Admin mode (because of permission C:\Program Files) to compile the target INSTALL (it will copy and install the DCMTK to default path: C:/Program Files/DCMTK/, we can reference it such PATH_WHERE_DCMTK_WAS_INSTALLED)
(1.B) Compiling on GNU/Linux GCC
I have tested at Ubuntu/CentOS. The first, you should go to DCMTK Source and run these following three commands:
$ ./configure --prefix=path_to_dcmtk
$ make all
$ sudo make install
example: path_to_dcmtk = /home/user/dcmtk
2) Creating your sample application
Create a file called your_sample/testapp.cxx with the following content. This a demonstration found in DCMTK Forum to open a DICOM file and print the patient's name.
#include "dcmtk/dcmdata/dctk.h"
#include <iostream>
using namespace std;
int main()
{
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile("test.dcm");
if (status.good())
{
OFString patientsName;
if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientsName).good())
{
cout << "Patient's Name: " << patientsName << endl;
}else{
cerr << "Error: cannot access Patient's Name!" << endl;
}
}else{
cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
}
return 0;
}
3) Creating the Application Project using the VisuaStudio as Compiler
The created file at the previous step needs to be placed in a project. You can choose between the option Windows VisualStudio (3.1) and Windows Qt (3.2). If you are using Linux, you can skip this step.
3.A) Windows with Visual Studio 2012 IDE
To create a Visual Studio project, you can use the Wizard and set the necessary settings such: Linker, Libraries, etc. However, to make easier on this answer, I will use the CMakeList.txt to create a Project for Visual Studio 2012. So, please, create a file called your_sample/CmakeList.txt with the following content:
PROJECT(testapp)
SET(DCMTK_DIR ABSOLUTE_PATH_WHERE_DCMTK_WAS_INSTALLED)
#an example: SET(DCMTK_DIR "C:\\Users\\test\\test_dcmtk\\DCMTK")
# settings for Microsoft Visual C++ 6
SET(CMAKE_C_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_CXX_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")
ADD_DEFINITIONS(-D_REENTRANT)
INCLUDE_DIRECTORIES(${DCMTK_DIR}/include)
LINK_DIRECTORIES(${DCMTK_DIR}/lib)
ADD_EXECUTABLE(testapp testapp)
TARGET_LINK_LIBRARIES(testapp netapi32 wsock32 ofstd dcmdata)
3.B) Windows QtCreator IDE using the VisuaStudio as Compiler
To create a project file for QtCreator IDE. You need to create a file called your_sample/my_project.pro with the following content:
SOURCES += testapp.cxx
CONFIG += debug console
DEFINES += _REENTRANT
QMAKE_CFLAGS_RELEASE -= -MD
QMAKE_CFLAGS_RELEASE = -MT
QMAKE_CFLAGS_DEBUG -= -MDd
QMAKE_CFLAGS_DEBUG = -MTd
QMAKE_CXXFLAGS_RELEASE -= -MD
QMAKE_CXXFLAGS_RELEASE += -MT
QMAKE_CXXFLAGS_DEBUG -= -MDd
QMAKE_CXXFLAGS_DEBUG += -MTd
INCLUDEPATH += (RELATIVE_PATH_WHERE_DCMTK_WAS_INSTALLED)/include
#an example: INCLUDEPATH += ../../../test_dcmtk/DCMTK/include
LIBS += -L"(RELATIVE_PATH_WHERE_YOU_INSTALLED_DCMTK)/lib" \
-ladvapi32 \
-ldcmdata \
-loflog \
-lofstd \
-lws2_32 \
-lnetapi32 \
-lwsock32
#an example: LIBS += -L"../../../test_dcmtk/DCMTK/lib" \
4.A) Windows with Visual Studio 2012 IDE
Open the project file at VisualStudio and click on Build.
4.B) Windows with QtCreator IDE using the VisuaStudio as Compiler
Open the project file at QT and click on Build.
4.C) GNU/Linux - Command Line with GCC
g++ testapp.cxx -DHAVE_CONFIG_H -I/path_to_dcmtk/include -L/path_to_dcmtk/lib -pthread -ldcmdata -lz -loflog -lofstd -o main
Please, note that whether you have compiled the libraries in DEBUG mode, your application should be compiled in DEBUG mode as well.
References
How Install
http://support.dcmtk.org/docs/file_install.html
DCMTK Docs
http://support.dcmtk.org/docs/
FAQ #40: How do I use the DCMTK libraries in my own application? [MSVC]
http://forum.dcmtk.org/viewtopic.php?f=4&t=652
CMake Configuration
http://support.dcmtk.org/wiki/dcmtk/howto/cmakeconfiguration360
Try to follow the instructions for the Dcmtk installation. If you don't know how to include the library in your project, study the qmake manual.
The Common Toolkit guys have addressed some of these issues. You could also use the Insight Toolkit
http://www.commontk.org/index.php/Main_Page
http://itk.org
In fact there is a bit of documentation on the ITK wiki, but ITK uses gdcm instead of dcmtk.
http://www.itk.org/Wiki/ITK_FAQ#How_to_read_a_volume_from_a_DICOM_series
We have a project that is an implementation of DCMTk in Qt -- we call it QtDICOM, and it forms the foundation of many of our products (http://fluxinc.ca/medical)/. Worth a look (https://bitbucket.org/fluxinc/qt-dicom). We haven't documented the configuration particularly well, but you can probably figure it out if you have a look.
Note: It does depend on DCMTk being built and included in the various paths.