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
}
Related
This software compiles for x86_64 linux and windows. It's written in C+ and relies heavily on the SDL as well as depending on libraries such as curl, microhttp, libharu, etc. Some 2 years ago it also compiled for android x86 and arm32 using Pelya's [commandergenious][1] port but that knowledge was lost, development continued and i'm the newcomer. I'm not that versed on Android or their take on makefiles.
I managed to include one library (haru) in commandergenious but trying to include other libraries resulted in multiple failures, so kinda stopped at that. I also had some issues using custom makefiles as suggested in the readme.
I've adapted an existing regular makefile but it ends up conflicting with existing dependencies, i.e., ndk-compiled cyptopp.so would cause undefined symbols on clang-compiled app, even though the signatures are "the same" (std::__ndk1::basic_string vs std::__cxx11::basic_string).
I've since taken to recompiling the code with clang instead of gcc (fixing a few bugs on the way due to clang being more strict) and using Android.mk instead of regular makefiles so i could cross-compile all components using just the NDK.
I tried giving a go at Android's LOCAL_MODULEs but the interdependent LOCAL_PATHs became too messy. I may get back to this route using [prebuilts][2] instead. It'll help segregate some issues should they arise.
Since my host is x86_68 Ubuntu Xenial i took the (maybe incorrect) path of setting up a directory with armeabi-v7a arm64-v8a x86 x86_64 subdirectories and ar xing .deb files (from Debian Buster as Xenial has sparse arm .debs) into those for all the libraries and includes i need. (It's $(HOME)/dev/multiarch bellow.)
At the moment, this is my Application.mk
APP_OPTIM := debug
APP_DEBUG := true
APP_ABI := armeabi-v7a
APP_STL := c++_shared # default
APP_PLATFORM := android-16 # Jelly Bean, android v4.1 - 4.3.1, rel July 9 2012
APP_PROJECT_PATH := $(call my-dir)
NDK_PROJECT_PATH := $(APP_PROJECT_PATH)
APP_BUILD_SCRIPT := $(APP_PROJECT_PATH)/Android.mk
APP_CPPFLAGS := -frtti -fexceptions
And this is my Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := mylocalmodule
# { target architecture, arch-specific include paths, arch-specific library paths
#
MULTILIB_IDIR := -I$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/usr/include
ifeq ($(TARGET_ARCH_ABI),x86)
CLANG_TARGET := -target i386-unknown-linux-android
MULTILIB_IDIR += -I$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/usr/include/i386-linux-gnu
MULTILIB_LDIR := -L$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/usr/lib/i386-linux-gnu
MULTILIB_LDIR += -L$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/lib/i386-linux-gnu
endif
ifeq ($(TARGET_ARCH_ABI),x86_64)
CLANG_TARGET := -target x86_64-unknown-linux-android
MULTILIB_IDIR += -I$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/usr/include/x86_64-linux-gnu
MULTILIB_LDIR := -L$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/usr/lib/x86_64-linux-gnu
MULTILIB_LDIR += -L$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/lib/x86_64-linux-gnu
endif
ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
CLANG_TARGET := -target armv7a-unknown-linux-android
MULTILIB_IDIR += -I$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/usr/include/arm-linux-gnueabi
MULTILIB_LDIR := -L$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/usr/lib/arm-linux-gnueabi
MULTILIB_LDIR += -L$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/lib/arm-linux-gnueabi
endif
ifeq ($(TARGET_ARCH_ABI), arm64-v8a)
CLANG_TARGET := -target arm64v8a-unknown-linux-android
MULTILIB_IDIR += -I$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/usr/include/aarch64-linux-gnu
MULTILIB_LDIR := -L$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/usr/lib/aarch64-linux-gnu
MULTILIB_LDIR += -L$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/lib/aarch64-linux-gnu
endif
#
# } target architecture, arch-specific include paths, arch-specific library paths
# { source files
#
PROJECT_FILES += $(wildcard $(LOCAL_PATH)/*.c)
PROJECT_FILES += $(wildcard $(LOCAL_PATH)/*.cpp)
PROJECT_FILES := $(PROJECT_FILES:$(LOCAL_PATH)/%=%)
PROJECT_FILES := $(filter-out file01.cpp file02.cpp subdir/file03.cpp,$(PROJECT_FILES)) # windows only
LOCAL_SRC_FILES := $(PROJECT_FILES)
#
# } source files
# { compiler flags
#
INCLUDES := -I. -I.. -I../libjson/ -I$(HOME)/dev/commandergenius/project/jni/xml2/include -I$(HOME)/dev/libharu/libharu-2.0.8/include
#INCLUDES += -I$(ANDROID_NDK_ROOT)/sources/android/cpufeatures # crypto++
INCLUDES += -I$(ANDROID_NDK_ROOT)/sources/cxx-stl/llvm-libc++/include # STL
INCLUDES += $(MULTILIB_IDIR)
DEFINES := -D_LINUX_ -D__LINUX__ -DMYSQLDB -DANDROID -D_ANDROID -D_ANDROID_ -D__ANDROID__ -D__DEBUG__ -DDEBUG_SAFE #-DHAVE_CONFIG_H # libQRcode
ALL_FLAGS := $(CLANG_TARGET) $(ALL_FLAGS) -v -w -Wno-gnu-array-member-paren-init -fpermissive -g -Wall $(DEFINES)
# C/C++:
LOCAL_CFLAGS += $(INCLUDES) -Wno-return-type $(ALL_FLAGS) -nostdinc++
# C only:
LOCAL_CONLYFLAGS += -std=c99 -Wabi-tag -D_GLIBCXX_USE_CXX11_ABI=0
# C++ only:
LOCAL_CPPFLAGS += -std=c++11 -Wno-return-type #-stdlib=libc++
#
# } compiler flags
# { linker flags
#
LOCAL_LDFLAGS += -Wl,--verbose -Wl,--exclude-libs,ALL -Wl,--as-needed
LOCAL_LDFLAGS += -L/home/myuser/dev/myapp/libjson/bin/debug -L/home/myuser/dev/myapp/anothercomponent/bin/debug
LOCAL_LDFLAGS += -L$(HOME)/dev/commandergenius/project/jni/xml2/libs/$(TARGET_ARCH_ABI)
LOCAL_LDFLAGS += -L$(HOME)/dev/libharu/libharu-2.0.8/libs/$(TARGET_ARCH_ABI)
LOCAL_LDFLAGS += -L$(HOME)/dev/libqrencode-android/library/libs/$(TARGET_ARCH_ABI)
LOCAL_LDFLAGS += -L$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/lib
LOCAL_LDFLAGS += -lmysqlclient -lpthread -lz -lm -lrt -lssl -lcrypto -ldl -lcurl -lSDL_image -lSDL_gfx -lSDL_ttf -lSDL
LOCAL_LDFLAGS += -lmicrohttpd -lzip -lxml2 -lvncserver -lhpdf -lanothercomponent -ljson -lqrencode -lpng
#
# } linker flags
include $(BUILD_EXECUTABLE)
When compiling with ndk-build NDK_PROJECT_PATH="$PWD" NDK_APPLICATION_MK="$PWD/Application.mk" V=1 i get this error:
<ANDROID_NDK_ROOT>/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/android/asset_manager.h:140:5: error: expected function body after function declarator
__RENAME_IF_FILE_OFFSET64(AAsset_seek64);
^
because __RENAME_IF_FILE_OFFSET64 is not defined. Nor, i think, it should be, as i'm currently only targetting armeabi-v7a which is 32bit. Other files are correctly compiled as ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV).
I assume the main issue is my confusion with which C libraries to use and how the "regular" PC libs interact with android's.
For completeness, here's the full compile line (the first error is because i added an #ifndef):
a b Compile++ thumb: myapp <= myfile.cpp
rm -f /home/myuser/dev/myproject/nyapp/obj/local/armeabi-v7a/objs-debug/myapp/myfile.o
/home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -MMD -MP -MF /home/myuser/dev/myproject/nyapp/obj/local/armeabi-v7a/objs-debug/myapp/myfile.o.d -target armv7-no
Android (6875598, based on r399163b) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d)
Target: armv7a-unknown-linux-android
Thread model: posix
InstalledDir: /home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin
Found candidate GCC installation: /home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x
Selected GCC installation: /home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x
Candidate multilib: thumb;#mthumb
Candidate multilib: armv7-a;#march=armv7-a
Candidate multilib: armv7-a/thumb;#march=armv7-a#mthumb
Candidate multilib: .;
Selected multilib: armv7-a/thumb;#march=armv7-a#mthumb
(in-process)
"/home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++" -cc1 -triple thumbv7-unknown-linux-android -emit-obj -mrelax-all -mnoexecstack -disable-free -disable-llvm-ve
clang -cc1 version 11.0.5 based upon LLVM 11.0.5git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot/include"
ignoring duplicate directory "/home/myuser/dev/myproject/nyapp"
ignoring duplicate directory "/home/myuser/Android/Sdk/ndk/22.0.7026061/sources/cxx-stl/llvm-libc++/include"
#include "..." search starts here:
#include <...> search starts here:
/home/myuser/Android/Sdk/ndk/22.0.7026061/sources/cxx-stl/llvm-libc++/include
/home/myuser/Android/Sdk/ndk/22.0.7026061/sources/cxx-stl/llvm-libc++/../llvm-libc++abi/include
/home/myuser/dev/myproject/nyapp
..
../libjson
/home/myuser/dev/commandergenius/project/jni/xml2/include
/home/myuser/dev/libharu/libharu-2.0.8/include
/home/myuser/dev/multiarch/armeabi-v7a/usr/include
/home/myuser/dev/multiarch/armeabi-v7a/usr/include/arm-linux-gnueabi
/home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include
/home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/11.0.5/include
/home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/arm-linux-androideabi
/home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
End of search list.
In file included from /home/myuser/dev/myproject/nyapp/myfile.cpp:17:
In file included from /home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/android/native_activity.h:34:
/home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/android/asset_manager.h:141:2: error: __RENAME_IF_FILE_OFFSET64 is not defined
#error __RENAME_IF_FILE_OFFSET64 is not defined
^
/home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/android/asset_manager.h:143:5: error: expected function body after function declarator
__RENAME_IF_FILE_OFFSET64(AAsset_seek64);
^
/home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/android/asset_manager.h:172:5: error: expected function body after function declarator
__RENAME_IF_FILE_OFFSET64(AAsset_getLength64);
^
/home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/android/asset_manager.h:184:5: error: expected function body after function declarator
__RENAME_IF_FILE_OFFSET64(AAsset_getRemainingLength64);
^
/home/myuser/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/android/asset_manager.h:202:5: error: expected function body after function declarator
__RENAME_IF_FILE_OFFSET64(AAsset_openFileDescriptor64);
^
5 errors generated.
make: *** [/home/myuser/Android/Sdk/ndk/22.0.7026061/build/core/build-binary.mk:478: /home/myuser/dev/myproject/nyapp/obj/local/armeabi-v7a/objs-debug/myapp/myfile.o] Error 1
Any pointers would greatly appreciated.
MULTILIB_IDIR += -I$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/usr/include/arm-linux-gnueabi
MULTILIB_LDIR := -L$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/usr/lib/arm-linux-gnueabi
MULTILIB_LDIR += -L$(HOME)/dev/multiarch/$(TARGET_ARCH_ABI)/lib/arm-linux-gnueabi
You can't do this. Android is not a GNU system. All of your dependencies must be built for Android, not for your GNU system.
https://developer.android.com/ndk/guides/other_build_systems is the doc you're looking for.
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 ...
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.
I tried to compile a cuda file in Qt 5.2 and MSVC2012 environment.
Before I started my project, I carefully read the question and reply in :Compiling Cuda code in Qt Creator on Windows.
But there are still some errors popping out even though I simply copied the code and generated 2 files in qt
/main.cpp
/vectorAddition.cu
the error is :
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in vectorAddition_cuda.o
I just totally have no idea how to fix this bug. I read some article online about fixing the mismatch in MSVC2012. But few of them mentioned how to do it in Qt .pro file. Does any one happen to have this problem?
I also attached the pro file here (with minor modified according to my own directory)
#-------------------------------------------------
#
# Project created by QtCreator 2014-10-05T13:22:19
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled
TEMPLATE = app
SOURCES += main.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
# Define output directories
DESTDIR = debug
OBJECTS_DIR = debug/obj
CUDA_OBJECTS_DIR = debug/obj
# Source files
# 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:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.0/C" # Path to cuda SDK install
CUDA_DIR = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5" # 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_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
QMAKE_LIBDIR += $$CUDA_DIR/lib/$$SYSTEM_NAME \
$$CUDA_SDK/common/lib/$$SYSTEM_NAME \
$$CUDA_SDK/../shared/lib/$$SYSTEM_NAME
# Add the necessary libraries
LIBS += -lcuda -lcudart
# MSVCRT link option (static or dynamic, it must be the same with your Qt SDK link option)
MSVCRT_LINK_FLAG_DEBUG = "/MDd"
MSVCRT_LINK_FLAG_RELEASE = "/MD"
# The following makes sure all path names (which often include spaces) are put between quotation marks
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
# 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
cuda_d.commands = $$CUDA_DIR/bin/nvcc.exe -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$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
cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda
}
And here is my log
13:58:14: Running steps for project untitled...
13:58:14: Configuration unchanged, skipping qmake step.
13:58:14: Starting: "C:\Qt\Qt5.2.0\Tools\QtCreator\bin\jom.exe"
C:\Qt\Qt5.2.0\Tools\QtCreator\bin\jom.exe -f Makefile.Debug
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin\nvcc.exe" -D_DEBUG --use_fast_math -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5/include" -I"C:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.0/C/common/inc/" -I"C:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.0/C/../shared/inc/" -lcuda -lcudart --machine 32 -arch=sm_30 -c -o debug\obj\vectorAddition_cuda.obj ..\untitled\vectorAddition.cu
vectorAddition.cu
echo 1 /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ "debug\\untitled.exe.embed.manifest">debug\untitled.exe_manifest.rc
if not exist debug\untitled.exe if exist debug\untitled.exe.embed.manifest del debug\untitled.exe.embed.manifest
if exist debug\untitled.exe.embed.manifest copy /Y debug\untitled.exe.embed.manifest debug\untitled.exe_manifest.bak
link /NOLOGO /DYNAMICBASE /NXCOMPAT /NODEFAULTLIB:msvcrtd.lib /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST /MANIFESTFILE:debug\untitled.exe.embed.manifest /OUT:debug\untitled.exe #C:\Users\JYOU\AppData\Local\Temp\untitled.exe.4748.3744.jom
main.obj : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in vectorAddition_cuda.obj
moc_mainwindow.obj : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in vectorAddition_cuda.obj
LINK : fatal error LNK1181: cannot open input file 'C:\Program.obj'
jom: C:\Qt\Qt5.2.0\Tools\QtCreator\bin\build-untitled-Desktop_Qt_5_2_0_MSVC2012_32bit-Debug\Makefile.Debug [debug\untitled.exe] Error 1181
jom: C:\Qt\Qt5.2.0\Tools\QtCreator\bin\build-untitled-Desktop_Qt_5_2_0_MSVC2012_32bit-Debug\Makefile [debug] Error 2
13:58:18: The process "C:\Qt\Qt5.2.0\Tools\QtCreator\bin\jom.exe" exited with code 2.
Error while building/deploying project untitled (kit: Desktop Qt 5.2.0 MSVC2012 32bit)
When executing step 'Make'
13:58:18: Elapsed time: 00:04.
Explanation for "question duplication":
I also read the article Mismatch Detected for 'RuntimeLibrary'
But the difference is that my question is about NVCC set up in Qt which is more complex than in MSVC environment. Even though /MDd is set by the following code, without the correct setting of NVCC, cu file still not able to compile. Simple change of runtime library did not totally solve my question. It is the setting of NVCC eventually made it.
# MSVCRT link option (static or dynamic, it must be the same with your Qt SDK link option)
MSVCRT_LINK_FLAG_DEBUG = "/MDd"
MSVCRT_LINK_FLAG_RELEASE = "/MD"
I got my question solved by reading another article
http://robot9.me/cuda_qtcreator_windows/
As the question Mismatch Detected for 'RuntimeLibrary' suggested. MSVCRT link option needs to keep consistent. So the /MDd setting is added before NVCC config.
But the key is to set cuda.commands correctly. Different from question: Compiling Cuda code in Qt Creator on Windows (i tried that config but does not work for me)
my nvcc is set like this:
# MSVCRT link option (static or dynamic, it must be the same with your Qt SDK link option)
MSVCRT_LINK_FLAG_DEBUG = "/MDd"
MSVCRT_LINK_FLAG_RELEASE = "/MD"
CONFIG(debug, debug|release) {
#Debug settings
# Debug mode
cuda_d.input = CUDA_SOURCES
cuda_d.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.obj
cuda_d.commands = $$CUDA_DIR/bin/nvcc.exe -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$LIBS \
--machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH \
--compile -cudart static -g -DWIN32 -D_MBCS \
-Xcompiler "/wd4819,/EHsc,/W3,/nologo,/Od,/Zi,/RTC1" \
-Xcompiler $$MSVCRT_LINK_FLAG_DEBUG \
-c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda_d.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
# Release settings
cuda.input = CUDA_SOURCES
cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.obj
cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$LIBS \
--machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH \
--compile -cudart static -DWIN32 -D_MBCS \
-Xcompiler "/wd4819,/EHsc,/W3,/nologo,/O2,/Zi" \
-Xcompiler $$MSVCRT_LINK_FLAG_RELEASE \
-c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda
}
Even though I still do not fully understand some of cuda.commands, but it really works.
Please refer to http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#axzz3FOBrgXpc for more detail of NVCC config.
Here is the full version of my .pro file
#-------------------------------------------------
#
# Project created by QtCreator 2013-09-01T16:29:35
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = FFTW //your project name
TEMPLATE = app
HEADERS += dialog.h \
include/fftw3.h \ //header i need for my project
SOURCES += main.cpp\
dialog.cpp
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
DESTDIR = debug
OBJECTS_DIR = debug/obj # directory where .obj files will be saved
CUDA_OBJECTS_DIR = debug/obj # directory where .obj of cuda file will be saved
# This makes the .cu files appear in your project
OTHER_FILES += intmapping.cu # this is my cu file need to compile
# CUDA settings <-- may change depending on your system
CUDA_SOURCES += intmapping.cu # let NVCC know which file you want to compile CUDA NVCC
CUDA_SDK = "C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C" # Path to cuda SDK install
CUDA_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v6.5"
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_20 # Type of CUDA architecture, for example 'compute_10', 'compute_11', 'sm_10'
NVCC_OPTIONS += --use_fast_math # default setting
# include paths
INCLUDEPATH += $$CUDA_DIR/include\
$$CUDA_SDK/common/inc\
$$CUDA_SDK/../shared/inc\
# library directories
QMAKE_LIBDIR += $$join(CUDA_DIR,'" -I"','-I"','"')/lib/$$SYSTEM_NAME\
$$join(CUDA_SDK,'" -I"','-I"','"')/common/lib/$$SYSTEM_NAME\
$$join(CUDA_SDK,'" -I"','-I"','"')/../shared/lib/$$SYSTEM_NAME
# Add the necessary libraries
CUDA_LIBS= -lcuda -lcudart -lcufft
#add quotation for those directories contain space (Windows required)
CUDA_INC +=$$join(INCLUDEPATH,'" -I"','-I"','"')
LIBS += $$CUDA_LIBS
#nvcc config
# MSVCRT link option (static or dynamic, it must be the same with your Qt SDK link option)
MSVCRT_LINK_FLAG_DEBUG = "/MDd"
MSVCRT_LINK_FLAG_RELEASE = "/MD"
CONFIG(debug, debug|release) {
#Debug settings
# Debug mode
cuda_d.input = CUDA_SOURCES
cuda_d.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.obj
cuda_d.commands = $$CUDA_DIR/bin/nvcc.exe -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$LIBS \
--machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH \
--compile -cudart static -g -DWIN32 -D_MBCS \
-Xcompiler "/wd4819,/EHsc,/W3,/nologo,/Od,/Zi,/RTC1" \
-Xcompiler $$MSVCRT_LINK_FLAG_DEBUG \
-c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda_d.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
# Release settings
cuda.input = CUDA_SOURCES
cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.obj
cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$LIBS \
--machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH \
--compile -cudart static -DWIN32 -D_MBCS \
-Xcompiler "/wd4819,/EHsc,/W3,/nologo,/O2,/Zi" \
-Xcompiler $$MSVCRT_LINK_FLAG_RELEASE \
-c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda
}
FORMS += \
dialog.ui
win32: LIBS += -L$$PWD/lib/ -llibfftw3f-3 #library i need in my project
INCLUDEPATH += $$PWD/lib
DEPENDPATH += $$PWD/lib
I have compiled FreeImage 3.10.0 from source at /lib/FreeImage on Mac OS X 10.6.
I can see that after compilation these files were copied:
/usr/local/lib/libfreeimage-3.10.0.dylib
/usr/local/lib/libfreeimage.a
/usr/local/include/FreeImage.h
CMake cannot find FreeImage, but I cannot even do
#include <FreeImage.h> // not found
I am assuming I need to add FreeImage.h to the Mac OS X environment path, except I don't know which path is the right one as there are a few different files which store environment path variables.
What do I need to do to get FreeImage header to be found by my C++ app or CMake?
Here is the first part of my Makefile.osx is this helps:
# -*- Makefile -*-
# Mac OSX makefile for FreeImage
# This file can be generated by ./gensrclist.sh
include Makefile.srcs
# General configuration variables:
CC_PPC = gcc-4.0
CC_I386 = gcc-4.0
CPP_PPC = g++-4.0
CPP_I386 = g++-4.0
COMPILERFLAGS = -Os -fexceptions -fvisibility=hidden
COMPILERFLAGS_PPC = -arch ppc
COMPILERFLAGS_I386 = -arch i386
COMPILERPPFLAGS = -Wno-ctor-dtor-privacy
INCLUDE +=
INCLUDE_PPC = -isysroot /Developer/SDKs/MacOSX10.6.sdk
INCLUDE_I386 = -isysroot /Developer/SDKs/MacOSX10.6.sdk
CFLAGS_PPC = $(COMPILERFLAGS) $(COMPILERFLAGS_PPC) $(INCLUDE) $(INCLUDE_PPC)
CFLAGS_I386 = $(COMPILERFLAGS) $(COMPILERFLAGS_I386) $(INCLUDE) $(INCLUDE_I386)
CPPFLAGS_PPC = $(COMPILERPPFLAGS) $(CFLAGS_PPC)
CPPFLAGS_I386 = $(COMPILERPPFLAGS) $(CFLAGS_I386)
LIBRARIES_PPC = -Wl,-syslibroot /Developer/SDKs/MacOSX10.6.sdk
LIBRARIES_I386 = -Wl,-syslibroot /Developer/SDKs/MacOSX10.6.sdk
LIBTOOL = libtool
LIPO = lipo
Update: I added these lines into my Makefile as per Nicholas' instructions, then rebuilt but this didn't work:
CFLAGS = -I/usr/local/include
LDFLAGS = -L/usr/local/lib
You have to add -I/usr/local/include to CFLAGS and -L/usr/local/lib to LDFLAGS when compiling.
The 'INCLUDE +=' line looks like the one to attack:
INCLUDE += -I/usr/local/include
If the library is missing too, then you will need to find another line to add '-L/usr/include/lib' to.
Compiling with gcc -c file.c -o file.o -I /usr/local/include should compile your file that refers FreeImage.h.
However, when using isysroot everything becomes relative to the system root (i.e. your refrence to /usr/local/include is in fact isysroot/usr/local/include). "gcc -v" will show everything that goes on, making things easy:
tmp diciu$ gcc -v -isysroot /Developer/SDKs/MacOSX10.6.sdk test.c
[..]
ignoring nonexistent directory "/Developer/SDKs/MacOSX10.6.sdk/usr/local/include"