How does QMake process .prl files of static libraries? - c++

I need to pass certain #define from library to main application. As far as I understand, it can be achieved with .prl files.
I've created simple subdirs project to test it:
This is main project file:
TEMPLATE = subdirs
SUBDIRS += \
app \
lib
app.depends = lib
This is library project file:
QT -= gui
TARGET = lib
TEMPLATE = lib
# Added create_prl option
CONFIG += staticlib create_prl
# This is the define I want to pass to main application
PRL_EXPORT_DEFINES += TEST_PRL_DEFINE
SOURCES += lib.cpp
HEADERS += lib.h
This is main application file:
QT += core
QT -= gui
CONFIG += c++11
TARGET = app
# Added link_prl option
CONFIG += console link_prl
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../lib/release/ -llib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../lib/debug/ -llib
else:unix: LIBS += -L$$OUT_PWD/../lib/ -llib
INCLUDEPATH += $$PWD/../lib
DEPENDPATH += $$PWD/../lib
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/release/liblib.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/debug/liblib.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/release/lib.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../lib/debug/lib.lib
else:unix: PRE_TARGETDEPS += $$OUT_PWD/../lib/liblib.a
However, when I build the project (in Qt Creator, if that matters), no #define seems to be passed to main application except the standard ones:
cd lib\ && ( if not exist Makefile C:\Qt\5.4\mingw491_32\bin\qmake.exe C:\Qt\projects\test_prl\lib\lib.pro -spec win32-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile ) && C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile
mingw32-make[1]: Entering directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/lib'
C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[2]: Entering directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/lib'
# Here you can see that TEST_PRL_DEFINE is added to defines of library project
g++ -c -pipe -fno-keep-inline-dllexport -g -frtti -Wall -Wextra -fexceptions -mthreads -DTEST_PRL_DEFINE -DUNICODE -DQT_QML_DEBUG -DQT_CORE_LIB -I"..\..\test_prl\lib" -I"." -I"..\..\..\5.4\mingw491_32\include" -I"..\..\..\5.4\mingw491_32\include\QtCore" -I"debug" -I"..\..\..\5.4\mingw491_32\mkspecs\win32-g++" -o debug\lib.o ..\..\test_prl\lib\lib.cpp
ar -ru debug\liblib.a debug/lib.o
ar: creating debug\liblib.a
mingw32-make[2]: Leaving directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/lib'
mingw32-make[1]: Leaving directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/lib'
cd app\ && ( if not exist Makefile C:\Qt\5.4\mingw491_32\bin\qmake.exe C:\Qt\projects\test_prl\app\app.pro -spec win32-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile ) && C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile
mingw32-make[1]: Entering directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app'
C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[2]: Entering directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app'
# Here no TEST_PRL_DEFINE is added to #defines of main application project
g++ -c -pipe -fno-keep-inline-dllexport -g -std=c++0x -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_CORE_LIB -I"..\..\test_prl\app" -I"." -I"..\..\test_prl\lib" -I"..\..\..\5.4\mingw491_32\include" -I"..\..\..\5.4\mingw491_32\include\QtCore" -I"debug" -I"..\..\..\5.4\mingw491_32\mkspecs\win32-g++" -o debug\main.o ..\..\test_prl\app\main.cpp
g++ -Wl,-subsystem,console -mthreads -o debug\app.exe debug/main.o -LC:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app/../lib/debug/ -llib -LC:/Qt/5.4/mingw491_32/lib -lQt5Cored
mingw32-make[2]: Leaving directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app'
mingw32-make[1]: Leaving directory 'C:/Qt/projects/build-test_prl-Desktop_Qt_5_4_2_MinGW_32bit-Debug/app'
However, lib.prl file is created during build process and placed next to liblib.a.
How should I use create_prl/link_prl options?

better write clean makefiles on your own - the whole qmake stuff is far beyond any hope.
right now, I have to find why it silenty adds totally broken linker options like -L/usr/lib ... they're appearing in .prl files, but no idea where it comes from. smells like they never ever read the pkg-config manpage ...

Related

Using clang as a library in C++ project

I am trying to use clang as a library, but I am not sure how to link the files in the Makefile.
Trying out the ASTVisitor code from: https://clang.llvm.org/docs/RAVFrontendAction.html
Here is my Makefile for reference:
CC=g++
Includes= /usr/lib/llvm-6.0/include/
Libs= /usr/lib/llvm-6.0/lib/
CLANGLIBS=-lclangTooling -lclangFrontendTool -lclangFrontend -lclangDriver -lclangSerialization -lclangCodeGen -lclangParse -lclangSema -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangAnalysis -lclangARCMigrate -lclangRewrite -lclangRewriteFrontend -lclangEdit -lclangAST -lclangLex -lclangBasic -lclang
run:
LD_PRELOAD=../../llvm-project/build/lib/libclang.so ./clang_parser.out
all: clang_parser.cpp
$(CC) -I$(Includes) -L$(Libs) clang_parser.cpp -o a.out $(CLANGLIBS)
clean:
rm clang_parser.out
I have installed clang as a library i.e. done sudo apt-get install libclang-dev
I get the following error:
clang_parser.cpp:13:10: fatal error: clang/Frontend/FrontendActions.h: No such file or directory
#include <clang/Frontend/FrontendActions.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:10: recipe for target 'all' failed
make: *** [all] Error 1
Any best practices on using apt installed packages in C/C++ projects are appreciated too.
Installed a number of packages just to make sure:
sudo apt-get install libclang-dev llvm clang clang-tools
This is the compilation command for reference (it includes all libraries which may be used):
clang++ `llvm-config --cxxflags --ldflags` clang_parser.cpp $(CLANGLIBS2) `llvm-config --libs --system-libs` -g -o tool
where
CLANGLIBS2=-lclangTooling -lclangFrontendTool -lclangFrontend -lclangDriver -lclangSerialization -lclangCodeGen -lclangParse -lclangSema -lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangAnalysis -lclangARCMigrate -lclangRewrite -lclangRewriteFrontend -lclangEdit -lclangAST -lclangASTMatchers -lclangLex -lclangBasic -lclang
Set up all .so, .a files in /usr/lib/llvm-6.0/lib as LD_LIBRARY_PATH by doing:
export LD_LIBRARY_PATH=/usr/lib/llvm-6.0/lib
ldconfig
Having gone through the process myself of creating a program that uses
Clang as a library, I thought I'd post my own working Makefile.
Key elements:
It uses a binary distribution downloaded from
https://releases.llvm.org/download.html rather than
installing through apt-get so I can control exactly
what version is in use.
Like the OP, I'm using (GNU) make rather than cmake
to minimize the mystery of what is happening.
It uses the llvm-config program to get most of the required
compile and link options. Specifically, llvm-config --cxxflags
gets the preprocessor and compilation options, and
llvm-config --ldflags --libs --system-libs gets the linker options.
I'm using the same hardcoded list of clang libraries as the OP.
I do not know a way to obtain this list other than by studying what
cmake does in an llvm source tree build. There is not anything
like clang-config to help.
The llvm libraries must come after the clang libraries.
(This is obvious in retrospect, but I wasted a fair bit of time since
the linker error messages are not easy to diagnose when dealing with
literally hundreds of unfamiliar libraries.)
For completeness, I'm using GCC-9.3.0 on Linux Mint 20.1, x86_64.
My Makefile:
# clang-as-lib/Makefile
# Attempt to compile and link with clang as a library.
# Originally based on:
# https://stackoverflow.com/questions/59888374/using-clang-as-a-library-in-c-project
# Default target.
all:
.PHONY: all
# ---- Paths ----
# Installation directory from a binary distribution.
# Has five subdirectories: bin include lib libexec share.
# Downloaded from: https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz
CLANG_LLVM_INSTALL_DIR = $(HOME)/opt/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04
# Program to query the various LLVM configuration options.
LLVM_CONFIG = $(CLANG_LLVM_INSTALL_DIR)/bin/llvm-config
# ---- Compiler options ----
# C++ compiler.
CXX = g++
# Compiler options, including preprocessor options.
CXXFLAGS =
# Without optimization, adding -g increases compile time by ~20%.
#CXXFLAGS += -g
# Without -g, this increases compile time by ~10%. With -g -O2, the
# increase is ~50% over not having either.
#CXXFLAGS += -O2
CXXFLAGS += -Wall
# Silence a warning about a multi-line comment in DeclOpenMP.h.
CXXFLAGS += -Wno-comment
# Get llvm compilation flags.
CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags)
# Linker options.
LDFLAGS =
# Set of clang libraries to link with.
LDFLAGS += -lclangTooling
LDFLAGS += -lclangFrontendTool
LDFLAGS += -lclangFrontend
LDFLAGS += -lclangDriver
LDFLAGS += -lclangSerialization
LDFLAGS += -lclangCodeGen
LDFLAGS += -lclangParse
LDFLAGS += -lclangSema
LDFLAGS += -lclangStaticAnalyzerFrontend
LDFLAGS += -lclangStaticAnalyzerCheckers
LDFLAGS += -lclangStaticAnalyzerCore
LDFLAGS += -lclangAnalysis
LDFLAGS += -lclangARCMigrate
LDFLAGS += -lclangRewrite
LDFLAGS += -lclangRewriteFrontend
LDFLAGS += -lclangEdit
LDFLAGS += -lclangAST
LDFLAGS += -lclangLex
LDFLAGS += -lclangBasic
LDFLAGS += -lclang
# *After* clang libs, the llvm libs.
LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags --libs --system-libs)
# ---- Recipes ----
# Compile a C++ source file.
%.o: %.cpp
$(CXX) -c -o $# $(CXXFLAGS) $<
# Executable.
all: FindClassDecls.exe
FindClassDecls.exe: FindClassDecls.o
$(CXX) -g -Wall -o $# $^ $(LDFLAGS)
# Run it.
.PHONY: run
run: FindClassDecls.exe
./FindClassDecls.exe "namespace n { namespace m { class C {}; } }"
.PHONY: clean
clean:
$(RM) *.o *.exe
# EOF
FindClassDecls.cpp (from RAVFrontendAction.html):
// FindClassDecls.cpp
// https://clang.llvm.org/docs/RAVFrontendAction.html
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Tooling/Tooling.h"
using namespace clang;
class FindNamedClassVisitor
: public RecursiveASTVisitor<FindNamedClassVisitor> {
public:
explicit FindNamedClassVisitor(ASTContext *Context)
: Context(Context) {}
bool VisitCXXRecordDecl(CXXRecordDecl *Declaration) {
if (Declaration->getQualifiedNameAsString() == "n::m::C") {
FullSourceLoc FullLocation = Context->getFullLoc(Declaration->getBeginLoc());
if (FullLocation.isValid())
llvm::outs() << "Found declaration at "
<< FullLocation.getSpellingLineNumber() << ":"
<< FullLocation.getSpellingColumnNumber() << "\n";
}
return true;
}
private:
ASTContext *Context;
};
class FindNamedClassConsumer : public clang::ASTConsumer {
public:
explicit FindNamedClassConsumer(ASTContext *Context)
: Visitor(Context) {}
virtual void HandleTranslationUnit(clang::ASTContext &Context) {
Visitor.TraverseDecl(Context.getTranslationUnitDecl());
}
private:
FindNamedClassVisitor Visitor;
};
class FindNamedClassAction : public clang::ASTFrontendAction {
public:
virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
clang::CompilerInstance &Compiler, llvm::StringRef InFile)
{
return std::make_unique<FindNamedClassConsumer>(&Compiler.getASTContext());
}
};
int main(int argc, char **argv) {
if (argc > 1) {
clang::tooling::runToolOnCode(std::make_unique<FindNamedClassAction>(), argv[1]);
}
}
// EOF

Why do I have an error while compiling my code in C with Qt creator but can easily do this using make file?

I use gstreamer in my project, and if I compile program with make - IT WORKS well.
SOURCES= \
main.cpp
all: main.cpp
g++ $(INC) -std=gnu++11 $(SOURCES) -g -o myexe -lpthread -Wall -lgstapp-1.0 `pkg-config --cflags --libs gstreamer-1.0`
clean:
rm -rf *.o myexe
But I wrote the same in my .pro file in Qt creator and I get an error:
/usr/include/gstreamer-1.0/gst/gstelement.h:55: gst/gstconfig.h: No such file or directory
This is my full .pro file:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
TEMPLATE = app
INCLUDEPATH += /usr/include/gstreamer-1.0/ \
/usr/include/glib-2.0/ \
/usr/lib/x86_64-linux-gnu/glib-2.0/include/ \
/usr/include/libxml2/
LIBS += -std=gnu++11
LIBS += -lgstapp-1.0
LIBS += -lpthread
LIBS += `pkg-config --cflags --libs gstreamer-1.0`
SOURCES += main.cpp
Please tell, how to fix this ? I really want to use Qt creator.
Here is the correct .pro file with all needed paths:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
TEMPLATE = app
INCLUDEPATH += /usr/include/gstreamer-1.0/ \
/usr/lib/x86_64-linux-gnu/gstreamer-1.0/include \
/usr/include/glib-2.0/ \
/usr/lib/x86_64-linux-gnu/glib-2.0/include/ \
/usr/include/libxml2/
LIBS += -std=gnu++11
LIBS += -lgstapp-1.0
LIBS += -lpthread
LIBS += `pkg-config --cflags --libs gstreamer-1.0`
SOURCES += main.cpp

"file format not recognized" when compiling CUDA code with nvcc and gcc using qmake

I have to following two files in my project:
home/cuda_compilation_test/
main.cpp
libcudatest.cu
cuda_compilation_test.pro
I am using QtCreator with qmake for compilation. However, when I am building the project using the project file shown below, I recieve a linking error file format not recognized; treating as linker script.
It nonetheless produces two object files in the debug directory
home/build-cuda_compilation_test-Desktop-Debug/
main.o
libcudatest.o
How can I
check, that the object file is indeed correctly produced and
include the seperately compiled libcudatest.o in the main project
For further reference, this is the compiler output
g++ -m64 -o cuda_compilation_test_2 libcudatest.o main.o -L/usr/lib/x86_64-linux-gnu -L/usr/local/cuda/lib64 -lcudart -lcudatest -lQtGui -lQtCore -lpthread
/usr/bin/ld:libcudatest.o: file format not recognized; treating as linker script
/usr/bin/ld:libcudatest.o:1: syntax error
collect2: error: ld returned 1 exit status
make: *** [cuda_compilation_test_2] Error 1
11:19:20: The process "/usr/bin/make" exited with code 2.
and the project file:
TEMPLATE =
# Files
SOURCES += main.cpp
OTHER_FILES += libcudatest.cu
LIBS += -L/usr/local/cuda/lib64
LIBS += -lcudart -lcudatest
# CUDA path
CUDA_DIR = /usr/local/cuda
CUDA_CC = $$CUDA_DIR/bin/nvcc
# CUDA Setup
CUDA_SOURCES = libcudatest.cu
NVCCINCLUDES +=
NVCCFLAGS = --shared -arch sm_35 -Xcompiler -fPIC --ptxas-options=-v
INCLUDEPATH +=
LIBS +=
# Configuration of the Cuda compiler
# http://doc.qt.io/qt-4.8/qmake-environment-reference.html#customizing
CONFIG(debug, debug|release) {
# Debug mode
cuda_d.input = CUDA_SOURCES
cuda_d.output = ${QMAKE_FILE_BASE}.o
cuda_d.commands = $$CUDA_CC -D_DEBUG $$NVCCFLAGS $$NVCCINCLUDES $$LIBS -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda_d.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
# Release mode
cuda.input = CUDA_SOURCES
cuda.output = ${QMAKE_FILE_BASE}.o
cuda.commands = $$CUDA_CC $$NVCCFLAGS $$NVCCINCLUDES $$LIBS -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda
}
I am trying to compile on linux.
Thank you very much for any help on this topic.

Compiling c++ and cuda code with MinGW in QTCreator

Im trying to compile simple cuda program (i took source code from Compiling Cuda code in Qt Creator on Windows)
This is my .pro file:
TARGET = Cuda
# Define output directories
DESTDIR = release
OBJECTS_DIR = release/obj
CUDA_OBJECTS_DIR = release/cuda
# Sourcefiles
SOURCES += main.cpp
# This makes the .cu files appear in your project
OTHER_FILES += vectorAddition.cu
# CUDA settings <-- may change depending on your system
CUDA_SOURCES += vectorAddition.cu
CUDA_SDK = "C:/Cuda/CudaSamples" # Path to cuda SDK install
CUDA_DIR = "C:/Cuda/CudaToolkit" # Path to cuda toolkit install
SYSTEM_NAME = Win32 # Depending on your system either 'Win32', 'x64', or 'Win64'
SYSTEM_TYPE = 32 # '32' or '64', depending on your system
CUDA_ARCH = sm_11 # Type of CUDA architecture, for example 'compute_10', 'compute_11', 'sm_10'
TEMP = 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin' #tried to add VS compiler path, seems woring. When i changed it to higher version error appeared
VS = $$join(TEMP,'" -ccbin "','-ccbin "','"') #joing path to VS compiler with quotes
NVCC_OPTIONS = --use_fast_math $$VS
# include paths
INCLUDEPATH += $$CUDA_DIR/include \
$$CUDA_SDK/common/inc/ \
$$CUDA_SDK/../shared/inc/ \
# library directories
QMAKE_LIBDIR += $$CUDA_DIR/lib/$$SYSTEM_NAME \
$$CUDA_SDK/common/lib/$$SYSTEM_NAME \
$$CUDA_SDK/../shared/lib/$$SYSTEM_NAME \
C:/CUDA/VS10/VC/lib \ #tried to add VS runtime libraries, after that some errors disappeared, and some new emerged so i guess it worked
QMAKE_LIBS += -lmsvcrt -llibcmt -llibcpmt #after adding VS runtime to QMAKE_LIBDIR this line seems to have no effect
# Add the necessary libraries
LIBS += -lcuda -lcudart
#LIBS += -lmsvcr100
QMAKE_CFLAGS_RELEASE += -v
MSVCRT_LINK_FLAG_DEBUG = "/MTd"
MSVCRT_LINK_FLAG_RELEASE = "/MT"
# The following makes sure all path names (which often include spaces) are put between quotation marks
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
#this was nested in CONFIG (see link above) but i dont think it worked
cuda.input = CUDA_SOURCES
cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH \
-Xcompiler "/wd4819,/EHsc,/W3,/nologo,/O2,/Zi" \
-Xptxas -v \
-Xcompiler $$MSVCRT_LINK_FLAG_RELEASE \
-c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME} #Xptxas -v is command for some extra output during cuda compiling (nvvc). -Xcompiler, honesly i have no idea what "/wd4819,/EHsc,/W3,/nologo,/O2,/Zi" \ means,i copied those from some chinese webpage and again some errors went away
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda
HEADERS += \
vectorAddition.h #empty header, i was just trying something.
This is compiler output:
13:09:17: Running steps for project Cuda...
13:09:17: Starting: "F:\Programs\Qt5.1.1\Tools\mingw48_32\bin\mingw32-make.exe" clean
F:/Programs/Qt5.1.1/Tools/mingw48_32/bin/mingw32-make -f Makefile.Release clean
mingw32-make[1]: Entering directory 'F:/workspaceSchool/build-Cuda-Desktop_Qt_5_1_1_MinGW_32bit-Release'
del release\cuda\vectorAddition_cuda.o
del release\cuda\vectorAddition_cuda.o release\obj\main.o
Could Not Find F:\workspaceSchool\build-Cuda-Desktop_Qt_5_1_1_MinGW_32bit-Release\release\cuda\vectorAddition_cuda.o
mingw32-make[1]: Leaving directory 'F:/workspaceSchool/build-Cuda-Desktop_Qt_5_1_1_MinGW_32bit-Release'
F:/Programs/Qt5.1.1/Tools/mingw48_32/bin/mingw32-make -f Makefile.Debug clean
mingw32-make[1]: Entering directory 'F:/workspaceSchool/build-Cuda-Desktop_Qt_5_1_1_MinGW_32bit-Release'
del release\cuda\vectorAddition_cuda.o
Could Not Find F:\workspaceSchool\build-Cuda-Desktop_Qt_5_1_1_MinGW_32bit-Release\release\cuda\vectorAddition_cuda.o
del release\cuda\vectorAddition_cuda.o debug\obj\main.o
Could Not Find F:\workspaceSchool\build-Cuda-Desktop_Qt_5_1_1_MinGW_32bit-Release\release\cuda\vectorAddition_cuda.o
Could Not Find F:\workspaceSchool\build-Cuda-Desktop_Qt_5_1_1_MinGW_32bit-Release\debug\obj\main.o
mingw32-make[1]: Leaving directory 'F:/workspaceSchool/build-Cuda-Desktop_Qt_5_1_1_MinGW_32bit-Release'
13:09:18: The process "F:\Programs\Qt5.1.1\Tools\mingw48_32\bin\mingw32-make.exe" exited normally.
13:09:18: Starting: "F:\Programs\Qt5.1.1\5.1.1\mingw48_32\bin\qmake.exe" F:\workspaceSchool\Cuda\Cuda.pro -r -spec win32-g++ -v
QMake version 3.0
Using Qt version 5.1.1 in F:\Programs\Qt5.1.1\5.1.1\mingw48_32\lib
13:09:18: The process "F:\Programs\Qt5.1.1\5.1.1\mingw48_32\bin\qmake.exe" exited normally.
13:09:18: Starting: "F:\Programs\Qt5.1.1\Tools\mingw48_32\bin\mingw32-make.exe"
F:/Programs/Qt5.1.1/Tools/mingw48_32/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'F:/workspaceSchool/build-Cuda-Desktop_Qt_5_1_1_MinGW_32bit-Release'
C:\Cuda\CudaToolkit\bin\nvcc.exe --use_fast_math -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" -I"C:/Cuda/CudaToolkit/include" -I"C:/Cuda/CudaSamples/common/inc/" -I"C:/Cuda/CudaSamples/../shared/inc/" -lcuda -lcudart --machine 32 -arch=sm_11 -Xcompiler /wd4819,/EHsc,/W3,/nologo,/O2,/Zi -Xptxas -v -Xcompiler /MT -c -o release\cuda\vectorAddition_cuda.o ..\Cuda\vectorAddition.cu
ptxas : info : 0 bytes gmem
ptxas : info : Compiling entry function '__cuda_dummy_entry__' for 'sm_11'
ptxas : info : Used 0 registers
g++ -c -pipe -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\Cuda -I"C:\Cuda\CudaToolkit\include" -I"C:\Cuda\CudaSamples\common\inc" -I"C:\Cuda\CudaSamples\..\shared\inc" -I"..\..\Programs\Qt5.1.1\5.1.1\mingw48_32\include" -I"..\..\Programs\Qt5.1.1\5.1.1\mingw48_32\include\QtGui" -I"..\..\Programs\Qt5.1.1\5.1.1\mingw48_32\include\QtCore" -I"release" -I"." -I"..\..\Programs\Qt5.1.1\5.1.1\mingw48_32\mkspecs\win32-g++" -o release\obj\main.o ..\Cuda\main.cpp
In file included from C:\Cuda\CudaToolkit\include/device_types.h:53:0,
from C:\Cuda\CudaToolkit\include/builtin_types.h:56,
from ..\Cuda\main.cpp:2:
C:\Cuda\CudaToolkit\include/host_defines.h:79:0: warning: "__cdecl" redefined [enabled by default]
#define __cdecl
^
..\Cuda\main.cpp:1:0: note: this is the location of the previous definition
#include <cuda.h>
^
In file included from C:\Cuda\CudaToolkit\include/builtin_types.h:60:0,
from ..\Cuda\main.cpp:2:
C:\Cuda\CudaToolkit\include/vector_types.h:73:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning(push)
^
C:\Cuda\CudaToolkit\include/vector_types.h:74:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning(disable: 4201 4408)
^
C:\Cuda\CudaToolkit\include/vector_types.h:350:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning(pop)
^
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\Cuda.exe release/cuda/vectorAddition_cuda.o release/obj/main.o -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmain -LC:\Cuda\CudaToolkit\lib\Win32 -LC:\Cuda\CudaSamples\common\lib\Win32 -LC:\Cuda\CudaSamples\..\shared\lib\Win32 -LC:\CUDA\VS10\VC\lib -LQMAKE_LIBS -L+= -L-lmsvcrt -L-llibcmt -L-llibcpmt -lcuda -lcudart -LF:\Programs\Qt5.1.1\5.1.1\mingw48_32\lib -lQt5Gui -lQt5Core
Warning: .drectve `/FAILIFMISMATCH:"_MSC_VER=1600" /FAILIFMISMATCH:"_ITERATOR_DEBUG_LEVEL=0" /DEFAULTLIB:"libcpmt" /DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES" ' unrecognized
f:/programs/qt5.1.1/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0xcf): undefined reference to `_imp___fmode'
f:/programs/qt5.1.1/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x2de): undefined reference to `_imp___acmdln'
f:/programs/qt5.1.1/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x3cf): undefined reference to `_imp____initenv'
f:/programs/qt5.1.1/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bin/ld.exe: f:/programs/qt5.1.1/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/lib/../lib/crt2.o: bad reloc address 0x0 in section `.CRT$XCAA'
collect2.exe: error: ld returned 1 exit status
Makefile.Release:78: recipe for target 'release\Cuda.exe' failed
mingw32-make[1]: Leaving directory 'F:/workspaceSchool/build-Cuda-Desktop_Qt_5_1_1_MinGW_32bit-Release'
makefile:34: recipe for target 'release' failed
mingw32-make[1]: *** [release\Cuda.exe] Error 1
mingw32-make: *** [release] Error 2
13:09:28: The process "F:\Programs\Qt5.1.1\Tools\mingw48_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project Cuda (kit: Desktop Qt 5.1.1 MinGW 32bit)
When executing step 'Make'
13:09:28: Elapsed time: 00:11.
And all issues (Can't post images due low rep): issues
If im not mistaken, then problem is with linking cuda object file (vectorAddition_cuda.o) which is compiled by nvvc.exe with cl.exe and with VS libs. Then MinGW(g++ compiler) is trying somehow link together cuda object file and c++ object file (main.o) with all libs into the executable file. g++ however doesnt know about VS runtime libs and is throwing these errors. So i guess i need somehow pass VS libs to g++.
How can i fix this?
I'm a bit confused, are you using MinGW or Visual? The title seems to state that you are using MinGW but the project file seems to use a mix of both. You can't mix those two. If you compiled (or downloaded the binary directly from NVidia) CUDA with Visual Studio 2010, you HAVE to use VS10 to compile your project, otherwise it won't work.
I never used CUDA myself but it seems that the system requirements mention only Visual Studio 2008, 2010 and 2012. If you want to use it with Qt, it's possible, you just have to grab a Qt compiled with VS (there are builds for 32 and 64 bit for both on the download page. You can get Visual Studio Express for free as long as you don't create any commercial application with it.
To use QtCreator with the MSVC backend compiler go to Tools > Options > Build and Run > Kits and add a new Kit with the MSVC compiler, cdb as the debugger and the Qt version you just downloaded (it must have been compiled with the same Visual Studio version otherwise it won't work). Then open your project, go to the Projects tab (on the left) and select the Kit you just created. You should probably clean your .pro file as well before everything work smoothly.
On a side note, there are a few things that seems out of place in your linker line:
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\Cuda.exe release/cuda/vectorAddition_cuda.o release/obj/main.o -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmain -LC:\Cuda\CudaToolkit\lib\Win32 -LC:\Cuda\CudaSamples\common\lib\Win32 -LC:\Cuda\CudaSamples\..\shared\lib\Win32 -LC:\CUDA\VS10\VC\lib -LQMAKE_LIBS -L+= -L-lmsvcrt -L-llibcmt -L-llibcpmt -lcuda -lcudart -LF:\Programs\Qt5.1.1\5.1.1\mingw48_32\lib -lQt5Gui -lQt5Core
First this -L+=, which might be caused by the escaping backslash at the end of the QMAKE_LIBDIR.
Then the syntax -L-lmsvcrt seems wrong. It might be because you are using QMAKE_LIBS, I personally never had to use it, and according to the documentation you shouldn't either as it is an internal variable. Same goes for QMAKE_LIBDIR btw. I would just use the LIBS variable for any external dependency.
You can add these to your .pro file which be used to link to CUDA on Windows using VS2010 and on Linux:
# Define output directories
CONFIG(release, debug|release): CUDA_OBJECTS_DIR = release/cuda
else: CUDA_OBJECTS_DIR = debug/cuda
# This makes the .cu files appear in your project
OTHER_FILES += vectorAddition.cu
# CUDA settings <-- may change depending on your system
CUDA_SOURCES += vectorAddition.cu
win32:{
CUDA_SDK = "C:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 5.5/C" # Path to cuda SDK install
CUDA_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.5" # Path to cuda toolkit install
}
else:unix{
CUDA_SDK = "/usr/local/cuda-5.5/" # Path to cuda SDK install
CUDA_DIR = "/usr/local/cuda-5.5/" # Path to cuda toolkit install
}
win32: SYSTEM_NAME = win32 # Depending on your system either 'Win32', 'x64', or 'Win64'
else:unix: SYSTEM_NAME = unix
SYSTEM_TYPE = 32 # '32' or '64', depending on your system
CUDA_ARCH = sm_30 # Type of CUDA architecture, for example 'compute_10', 'compute_11', 'sm_10'
NVCC_OPTIONS = --use_fast_math
# include paths
INCLUDEPATH += $$CUDA_DIR/include
#$$CUDA_SDK/common/inc/ \
#$$CUDA_SDK/../shared/inc/
# library directories
win32:{
QMAKE_LIBDIR += $$CUDA_DIR/lib/$$SYSTEM_NAME
#$$CUDA_SDK/common/lib/$$SYSTEM_NAME \
#$$CUDA_SDK/../shared/lib/$$SYSTEM_NAME
}
else:unix:{
QMAKE_LIBDIR += $$CUDA_DIR/lib
}
win32:{
# The following library conflicts with something in Cuda
QMAKE_LFLAGS_RELEASE = /NODEFAULTLIB:msvcrt.lib
QMAKE_LFLAGS_DEBUG = /NODEFAULTLIB:msvcrtd.lib
}
# Add the necessary libraries
win32:{
CUDA_LIBS = cuda cudart
# The following makes sure all path names (which often include spaces) are put between quotation marks
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
NVCC_LIBS = $$join(CUDA_LIBS,' -l','-l', '')
LIBS += $$join(CUDA_LIBS,'.lib ', '', '.lib')
}
else:unix:
{
CUDA_LIBS = -lcuda -lcudart
# The following makes sure all path names (which often include spaces) are put between quotation marks
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
NVCC_LIBS = $$join(CUDA_LIBS,' -l','-l', '')
LIBS += $$CUDA_LIBS
}
# Configuration of the Cuda compiler
CONFIG(debug, debug|release) {
# Debug mode
cuda_d.input = CUDA_SOURCES
cuda_d.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
win32: cuda_d.commands = $$CUDA_DIR/bin/nvcc.exe -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
else:unix: cuda_d.commands = $$CUDA_DIR/bin/nvcc -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda_d.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
# Release mode
cuda.input = CUDA_SOURCES
cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
win32: cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
else:unix: cuda.commands = $$CUDA_DIR/bin/nvcc $$NVCC_OPTIONS $$CUDA_INC $$NVCC_LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda
}

How to supply compiler options in Qt?

I am trying to learn Qt, I have file test.cpp that I run via the terminal using the following command:
g++ `pkg-config --cflags --libs libsbml` test.cpp -L /usr/local/lib -lsbml -lstdc++ -lm
How can I suppl the same options to Qt?
Thank you.
You could write the qmake snippet below. In short, you would need to take a look at the following qmake variables:
LIBS
INCLUDEPATH
TEMPLATE
TARGET
HEADERS
SOURCES
CONFIG
PKGCONFIG
test.pro
TEMPLATE = app
TARGET = test
INCLUDEPATH += .
LIBS += -L /usr/local/lib -lsbml -lstdc++ -lm
unix {
CONFIG += link_pkgconfig
PKGCONFIG += libsbml
}
HEADERS += test.h
SOURCES += test.cpp
In .pro file add:
LIBS += -L /usr/local/lib -lsbml -lstdc++ -lm
look at the Makefile to figure out what variables are used. The makefile is in the build folder made by Qt.