I am using cc to link a CUDA kernel written in C to Rust.
Here is my build.rs file:
extern crate cc;
fn main() {
cc::Build::new()
.cuda(true)
.flag("-cudart=shared")
.flag("-gencode")
.flag("arch=compute_61,code=sm_61")
.file("kernel/kernel.cu")
.compile("kernel/kernel.a");
}
I have this error :
running: "nvcc" "-ccbin=c++" "-O0" "-Xcompiler" "-ffunction-sections"
"-Xcompiler" "-fdata-sections" "-Xcompiler" "-fPIC" "-G" "-Xcompiler"
"-g" "-m64" "-Xcompiler" "-Wall" "-Xcompiler" "-Wextra"
"-cudart=shared" "-gencode" "arch=compute_61,code=sm_61" "-o"
"/home/ltei/Dev/Workspaces/rust_cudnn/target/debug/build/rust_cudnn-df924982e63c2363/out/kernel/kernel.o"
"-c" "kernel/kernel.cu" cargo:warning=In file included from
/usr/include/cuda_runtime.h:78:0, cargo:warning= from
:0: cargo:warning=/usr/include/host_config.h:119:2:
error: #error -- unsupported GNU version! gcc versions later than 5
are not supported! cargo:warning= #error -- unsupported GNU version!
gcc versions later than 5 are not supported! cargo:warning= ^~~~~
exit code: 1
I know that it would work if I could change the -ccbin=c++ in the command into -ccbin=clang-3.8, but I have no idea how to do it.
I could also install another version of GCC, but I'd prefer the first solution.
You can set the CXX environment variable to whatever you want.
CXX=this-is-my-cpp-compiler cargo build
This will be used as the argument to ccbin:
"nvcc" "-ccbin=this-is-my-cpp-compiler" "-O0" "-Xcompiler" "-ffunction-sections" "-Xcompiler" "-fdata-sections" "-Xcompiler" "-fPIC" "-G" "-Xcompiler" "-g" "-m64" "-Xcompiler" "-Wall" "-Xcompiler" "-Wextra" "-cudart=shared" "-gencode" "arch=compute_61,code=sm_61" "-o" "/private/tmp/c/target/debug/build/c-67ec4fdcff2f35d1/out/kernel/kernel.o" "-c" "kernel/kernel.cu"
Related
I want to build MySQL 8.0.30 but it fails with the following error:
[3199/3567] Linking CXX executable
runtime_output_directory\mysqlrouter_plugin_info.exe FAILED:
runtime_output_directory/mysqlrouter_plugin_info.exe cmd.exe /C "cd .
&& "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe
--intdir=router\src\plugin_info\src\CMakeFiles\mysqlrouter_plugin_info.dir
--rc=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100220~1.0\x64\mt.exe --manifests -- C:\PROGRA~1\MICROS~4\2022\ENTERP~1\VC\Tools\MSVC\1433~1.316\bin\Hostx64\x64\link.exe
/nologo
router\src\plugin_info\src\CMakeFiles\mysqlrouter_plugin_info.dir\library_file.cc.obj
router\src\plugin_info\src\CMakeFiles\mysqlrouter_plugin_info.dir\main.cc.obj
router\src\plugin_info\src\CMakeFiles\mysqlrouter_plugin_info.dir\plugin_info_app.cc.obj
router\src\plugin_info\src\CMakeFiles\mysqlrouter_plugin_info.dir\plugin.cc.obj
router\src\plugin_info\src\CMakeFiles\mysqlrouter_plugin_info.dir____\versioninfo_exe.rc.res
/out:runtime_output_directory\mysqlrouter_plugin_info.exe
/implib:router\src\plugin_info\src\mysqlrouter_plugin_info.lib
/pdb:runtime_output_directory\mysqlrouter_plugin_info.pdb /version:0.0
/machine:x64 /debug /INCREMENTAL /INCREMENTAL:NO /subsystem:console
ws2_32.lib router\src\harness\src\harness-library.lib
archive_output_directory\mysys.lib
archive_output_directory\strings.lib
archive_output_directory\mysys.lib
archive_output_directory\strings.lib
archive_output_directory\mytime.lib archive_output_directory\zlib.lib
archive_output_directory\zstd.lib crypt32.lib shlwapi.lib
ws2_32.lib
C:\OpenSSL\openssl-1.1.1q\static\x64\debug\lib\libsslMTd.lib
C:\OpenSSL\openssl-1.1.1q\static\x64\debug\lib\libcryptoMTd.lib
crypt32.lib kernel32.lib user32.lib gdi32.lib winspool.lib
shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib
&& cd ." LINK Pass 1: command
"C:\PROGRA~1\MICROS~4\2022\ENTERP~1\VC\Tools\MSVC\1433~1.316\bin\Hostx64\x64\link.exe
/nologo
router\src\plugin_info\src\CMakeFiles\mysqlrouter_plugin_info.dir\library_file.cc.obj
router\src\plugin_info\src\CMakeFiles\mysqlrouter_plugin_info.dir\main.cc.obj
router\src\plugin_info\src\CMakeFiles\mysqlrouter_plugin_info.dir\plugin_info_app.cc.obj
router\src\plugin_info\src\CMakeFiles\mysqlrouter_plugin_info.dir\plugin.cc.obj
router\src\plugin_info\src\CMakeFiles\mysqlrouter_plugin_info.dir____\versioninfo_exe.rc.res
/out:runtime_output_directory\mysqlrouter_plugin_info.exe
/implib:router\src\plugin_info\src\mysqlrouter_plugin_info.lib
/pdb:runtime_output_directory\mysqlrouter_plugin_info.pdb /version:0.0
/machine:x64 /debug /INCREMENTAL /INCREMENTAL:NO /subsystem:console
ws2_32.lib router\src\harness\src\harness-library.lib
archive_output_directory\mysys.lib
archive_output_directory\strings.lib
archive_output_directory\mysys.lib
archive_output_directory\strings.lib
archive_output_directory\mytime.lib archive_output_directory\zlib.lib
archive_output_directory\zstd.lib crypt32.lib shlwapi.lib ws2_32.lib
C:\OpenSSL\openssl-1.1.1q\static\x64\debug\lib\libsslMTd.lib
C:\OpenSSL\openssl-1.1.1q\static\x64\debug\lib\libcryptoMTd.lib
crypt32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib
ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST
/MANIFESTFILE:router\src\plugin_info\src\CMakeFiles\mysqlrouter_plugin_info.dir/intermediate.manifest router\src\plugin_info\src\CMakeFiles\mysqlrouter_plugin_info.dir/manifest.res"
failed (exit code 1169) with the following output:
harness-library.lib(harness-library.dll) : error LNK2005: "public: int
__cdecl std::basic_streambuf<char,struct std::char_traits >::pubsync(void)" (?pubsync#?$basic_streambuf#DU?$char_traits#D#std###std##QEAAHXZ)
already defined in plugin_info_app.cc.obj
harness-library.lib(harness-library.dll) : error LNK2005: "public: int
__cdecl std::basic_streambuf<char,struct std::char_traits >::sputc(char)" (?sputc#?$basic_streambuf#DU?$char_traits#D#std###std##QEAAHD#Z)
already defined in plugin_info_app.cc.obj
harness-library.lib(harness-library.dll) : error LNK2005: "public:
__int64 __cdecl std::basic_streambuf<char,struct std::char_traits >::sputn(char const *,__int64)"
(?sputn#?$basic_streambuf#DU?$char_traits#D#std###std##QEAA_JPEBD_J#Z)
already defined in plugin_info_app.cc.obj
runtime_output_directory\mysqlrouter_plugin_info.exe : fatal error
LNK1169: one or more multiply defined symbols found [3208/3567]
Linking CXX executable runtime_output_directory\mysqld.exe ninja:
build stopped: subcommand failed.
C:\mysql-8.0.30\build>
I use this command to build MySQL:
cmake -H. -B"C:\\mysql-8.0.30\\build" -DWITH_UNIT_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="C:\\MySQL\\mysql-8.0.30-winx64\\debug" -DLINK_STATIC_RUNTIME_LIBRARIES=1 -DFORCE_INSOURCE_BUILD=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST="C:\\Boost" -DWITH_SSL="C:\OpenSSL\openssl-1.1.1q\static\x64\debug" -DOPENSSL_LIBRARY="C:\OpenSSL\openssl-1.1.1q\static\x64\debug\lib\libsslMTd.lib" -DCRYPTO_LIBRARY="C:\OpenSSL\openssl-1.1.1q\static\x64\debug\lib\libcryptoMTd.lib" -G "Ninja"
Any ideas how to fix this issue? Thank you for your help.
I have fixed this issue by adding the following option: -DWITH_ROUTER=OFF to my command. Now, it compiles without issues. The issue is resolved.
I am trying to use fstream and exceptions but alway I run a program using exception it crash, no erros reported from compiller.
I think is a bug in MinGw compiler or compatibility with my windows system.
could you help me solve my problem. Thank you!
Code::Blocks 17.12! rev 11256 Win32 / gcc version 3.4.5 (mingw-vista special r3) / Windows 7 ServicePack1
Example code:
#include <iostream>
#include <fstream>
int main() {
int ivalue;
try {
std::ifstream in("in.txt");
in.exceptions(std::ifstream::failbit);
in >> ivalue;
} catch (std::ios_base::failure &fail) {
// handle exception here
}
}
```
Link:https://es.cppreference.com/w/cpp/io/basic_ios/exceptions
Compiller:
-------------- Build: Release in Exceptions (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -O2 -IC:\C++\TestExecLibs\Include -c C:\Programing\C&C++\Exceptions\main.cpp -o obj\Release\main.o
mingw32-g++.exe -o bin\Release\Exceptions.exe obj\Release\main.o -s "C:\Program Files\CodeBlocks\MinGW\lib\libcomctl32.a"
Output file is bin\Release\Exceptions.exe with size 784.50 KB
Process terminated with status 0 (0 minute(s), 4 second(s))
0 error(s), 0 warning(s) (0 minute(s), 4 second(s))-------------- Build: Release in Exceptions (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -O2 -IC:\C++\TestExecLibs\Include -c C:\Programing\C&C++\Exceptions\main.cpp -o obj\Release\main.o
mingw32-g++.exe -o bin\Release\Exceptions.exe obj\Release\main.o -s "C:\Program Files\CodeBlocks\MinGW\lib\libcomctl32.a"
Output file is bin\Release\Exceptions.exe with size 784.50 KB
Process terminated with status 0 (0 minute(s), 4 second(s))
0 error(s), 0 warning(s) (0 minute(s), 4 second(s))
After Run CMD:
terminate called after throwing an instance of 'std::ios_base::failure'
what(): basic_ios::clear
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Process returned 3 (0x3) execution time : 2.948 s
Press any key to continue.
[CMD Window Result][1]
[1]: https://i.stack.imgur.com/vCudt.jpg
I'm building a Vala program with gnome-builder and flatpak. I wan't to connect to a mySQL Database. Thats why I need to run mysql_config to get the right compiler flags.
So I added mysql_config = find_program('mysql_config')to my meson.build file.
When I try to compile I get meson.build:7:0: ERROR: Program(s) ['mysql_config'] not found or not executable.
When I run whereis mysql_config on command line I get the expected result mysql_config: /usr/bin/mysql_config. Also I can run mysql_config --cflags from command line with the expected result -I/usr/include/mysql -I/usr/include/mysql.
Thats why I think that the problem is that I'm building with flatpak-builder.
My ./meson.build:
project('zeiterfassunggtk', ['c', 'vala'], version: '0.1.0',
meson_version: '>= 0.40.0',
)
i18n = import('i18n')
mysql_config = find_program('mysql_config')
mysql_vapi = meson.get_compiler('vala').find_library('mysql')
mysql_dep = declare_dependency(c_args: run_command([mysql_config, '--cflags']).stdout().split(),
link_args: run_command([mysql_config, '--libs']).stdout().split(),
dependencies: [mysql_vapi])
subdir('data')
subdir('src')
subdir('po')
meson.add_install_script('build-aux/meson/postinstall.py')
My ./src/meson.build
zeiterfassunggtk_sources = [
'main.vala',
'window.vala',
'mysql.vala',
]
zeiterfassunggtk_deps = [
dependency('gio-2.0', version: '>= 2.50'),
dependency('gtk+-3.0', version: '>= 3.22'),
]
gnome = import('gnome')
zeiterfassunggtk_sources += gnome.compile_resources('zeiterfassunggtk-resources',
'zeiterfassunggtk.gresource.xml',
c_name: 'zeiterfassunggtk'
)
executable('zeiterfassunggtk', zeiterfassunggtk_sources,
vala_args: '--target-glib=2.50', dependencies: zeiterfassunggtk_deps,
install: true,
)
The full output of the build process:
flatpak build --env=LANG=de_AT.UTF-8 --env=USER=g.zehetner --env=HOME=/home/g.zehetner --env=PATH=/usr/bin:/bin --env=TERM=xterm-256color --env=V=0 --env=CCACHE_DIR=/home/g.zehetner/.cache/gnome-builder/flatpak-builder/ccache --env=PATH=/app/bin:/usr/bin --build-dir=/home/g.zehetner/.cache/gnome-builder/projects/ZeiterfassungGtk/builds/org.gnome.Zeiterfassunggtk.json-flatpak-org.gnome.Platform-x86_64-3.26-master --share=network --nofilesystem=host --filesystem=/home/g.zehetner/.cache/gnome-builder --filesystem=/home/g.zehetner/Projekte/ZeiterfassungGtk --filesystem=/home/g.zehetner/.cache/gnome-builder/projects/ZeiterfassungGtk/builds/org.gnome.Zeiterfassunggtk.json-flatpak-org.gnome.Platform-x86_64-3.26-master --env=V=1 '--env=CFLAGS=-O2 -g' '--env=CXXFLAGS=-O2 -g' --env=NOCONFIGURE=1 /home/g.zehetner/.cache/gnome-builder/projects/ZeiterfassungGtk/flatpak/staging/x86_64-master ninja
[0/1] Regenerating build files.
The Meson build system
Version: 0.46.0
Source dir: /home/g.zehetner/Projekte/ZeiterfassungGtk
Build dir: /home/g.zehetner/.cache/gnome-builder/projects/ZeiterfassungGtk/builds/org.gnome.Zeiterfassunggtk.json-flatpak-org.gnome.Platform-x86_64-3.26-master
Build type: native build
Project name: zeiterfassunggtk
Native C compiler: ccache cc (gcc 6.2.0 "cc (GCC) 6.2.0")
Appending CFLAGS from environment: '-O2 -g'
Appending LDFLAGS from environment: '-L/app/lib '
Native Vala compiler: valac (valac 0.38.2)
Appending LDFLAGS from environment: '-L/app/lib '
Build machine cpu family: x86_64
Build machine cpu: x86_64
Program mysql_config found: NO
meson.build:7:0: ERROR: Program(s) ['mysql_config'] not found or not executable
A full log can be found at /home/g.zehetner/.cache/gnome-builder/projects/ZeiterfassungGtk/builds/org.gnome.Zeiterfassunggtk.json-flatpak-org.gnome.Platform-x86_64-3.26-master/meson-logs/meson-log.txt
FAILED: build.ninja
/usr/bin/python3 /usr/bin/meson --internal regenerate /home/g.zehetner/Projekte/ZeiterfassungGtk /home/g.zehetner/.cache/gnome-builder/projects/ZeiterfassungGtk/builds/org.gnome.Zeiterfassunggtk.json-flatpak-org.gnome.Platform-x86_64-3.26-master --backend ninja
ninja: error: rebuilding 'build.ninja': subcommand failed
You can find the full code at Github.com
The way I tried it (see question title) it compiled, but I get a segmentation fault. So is it me, CMake or CUDA which doesn't support direct kernel calls from a shared library? The solution doesn't have to be with CMake
Further details:
I have the following file structure:
testKernel.hpp
__global__ void kernelTest( float x );
void callKernel( float x );
testKernel.cu
#include "testKernel.hpp"
__global__ void kernelTest( float x ) {}
void callKernel( float x ) { kernelTest<<<1,1>>>( x ); }
useKernel.cu
#include <cstdio>
#include "testKernel.hpp"
int main( void )
{
kernelTest<<<1,1>>>( 3.0f );
//callKernel( 3.0f );
printf("OK\n");
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.3.1)
project(testKernelCall)
find_package(CUDA REQUIRED)
cuda_add_library( ${PROJECT_NAME} SHARED testKernel.cu testKernel.hpp )
target_link_libraries( ${PROJECT_NAME} ${CUDA_LIBRARIES} )
cuda_add_executable("useKernel" useKernel.cu)
target_link_libraries("useKernel" ${PROJECT_NAME})
Compiling and running this with:
cmake .; make && ./useKernel
results in a segmentation fault. The backtrace with gdb is:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff75726bd in cudart::configData::addArgument(void const*, unsigned long, unsigned long) ()
from ./libtestKernelCall.so
(gdb) bt
#0 0x00007ffff75726bd in cudart::configData::addArgument(void const*, unsigned long, unsigned long) ()
from ./libtestKernelCall.so
#1 0x00007ffff7562eb7 in cudart::cudaApiSetupArgument(void const*, unsigned long, unsigned long) ()
from ./libtestKernelCall.so
#2 0x00007ffff7591ca2 in cudaSetupArgument ()
from ./libtestKernelCall.so
#3 0x00007ffff7556125 in __device_stub__Z10kernelTestf (__par0=3)
at /tmp/tmpxft_00003900_00000000-4_testKernel.cudafe1.stub.c:7
#4 0x00007ffff755616c in kernelTest (__cuda_0=3) at ./testKernel.cu:2
#5 0x000000000040280e in main () at ./useKernel.cu:6
Tested with (which means the segfault appears in those setups):
Setup 1
cmake 3.4.1
CUDA 7.0.27
g++ 4.9.2
Debian
Setup 2
cmake 3.3.1
CUDA 6.5.14
g++ 4.7.1
There are two ways to solve this error:
change SHARED to STATIC in CMakeList.txt
use the wrapper function callKernel instead of calling the kernel directly
I don't really know how to build a CUDA shared library without CMake. I know how to build a CUDA static library, but that case seems to work with CMake, so I didn't test it without CMake.
Here are the relevant CMake commands I got with make VERBOSE=1. I changed absolute paths to relative paths, where possible, but I wasn't sure about all these library paths. Putting these commands in a file and sourcing that file compiles the shared library and the program correctly and "correctly" leads to the segmentation fault. I also added command because for me nvcc is aliased with the `-ccbin`` option.
make.sh
command nvcc "./testKernel.cu" -c -o "./testKernel.cu.o" -ccbin /usr/bin/cc -m64 -DtestKernelCall_EXPORTS -Xcompiler ,\"-fPIC\",\"-g\" -DNVCC -I/opt/cuda-7.0/include -I/opt/cuda-7.0/include
/usr/bin/c++ -fPIC -shared -Wl,-soname,libtestKernelCall.so -o libtestKernelCall.so ./testKernel.cu.o /opt/cuda-7.0/lib64/libcudart_static.a -lpthread /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libdl.so /opt/cuda-7.0/lib64/libcudart_static.a -lpthread /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libdl.so
command nvcc "./useKernel.cu" -c -o "./useKernel.cu.o" -ccbin /usr/bin/cc -m64 -Xcompiler ,\"-g\" -DNVCC -I/opt/cuda-7.0/include -I/opt/cuda-7.0/include
/usr/bin/c++ ./useKernel.cu.o -o useKernel -rdynamic /opt/cuda-7.0/lib64/libcudart_static.a -lpthread /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libdl.so libtestKernelCall.so /opt/cuda-7.0/lib64/libcudart_static.a -lpthread /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libdl.so -Wl,-rpath,"."
Your code compiles and runs correctly for me using ordinary nvcc commands (not CMake) if I add the -cudart shared switch to each nvcc command. Here's a fully-worked sequence:
$ cat testKernel.hpp
__global__ void kernelTest( float x );
void callKernel( float x );
$ cat testKernel.cu
#include "testKernel.hpp"
__global__ void kernelTest( float x ) {}
void callKernel( float x ) { kernelTest<<<1,1>>>( x ); }
$ cat useKernel.cu
#include <cstdio>
#include "testKernel.hpp"
int main( void )
{
kernelTest<<<1,1>>>( 3.0f );
//callKernel( 3.0f );
cudaDeviceSynchronize();
printf("OK\n");
return 0;
}
$ nvcc -shared -cudart shared -o test.so -Xcompiler -fPIC testKernel.cu
$ nvcc -cudart shared -o test test.so useKernel.cu
$ cuda-memcheck ./test
========= CUDA-MEMCHECK
OK
========= ERROR SUMMARY: 0 errors
$
If I omit -cudart shared on either of the above nvcc commands, then the compile will still proceed, but on execution I will witness the aforementioned seg fault. Tested with CUDA 7.5 on Fedora 20.
Regarding your CMake setup, it's necessary to link against the shared cudart, according to my testing. Therefore it's insufficient to add -cudart shared to the -c commands (which are compile commands. Sorry if I was unclear. My "compile" commands above are doing both compiling and linking, at each step.)
When linking with nvcc, the correct switch is -cudart shared. However, your make.sh indicates final link is being done by the host c++ compiler:
command nvcc "./testKernel.cu" -c -o "./testKernel.cu.o" -ccbin /usr/bin/cc -m64 -DtestKernelCall_EXPORTS -Xcompiler ,\"-fPIC\",\"-g\" -DNVCC -I/opt/cuda-7.0/include -I/opt/cuda-7.0/include
/usr/bin/c++ -fPIC -shared -Wl,-soname,libtestKernelCall.so -o libtestKernelCall.so ./testKernel.cu.o /opt/cuda-7.0/lib64/libcudart_static.a -lpthread /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libdl.so /opt/cuda-7.0/lib64/libcudart_static.a -lpthread /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libdl.so
command nvcc "./useKernel.cu" -c -o "./useKernel.cu.o" -ccbin /usr/bin/cc -m64 -Xcompiler ,\"-g\" -DNVCC -I/opt/cuda-7.0/include -I/opt/cuda-7.0/include
/usr/bin/c++ ./useKernel.cu.o -o useKernel -rdynamic /opt/cuda-7.0/lib64/libcudart_static.a -lpthread /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libdl.so libtestKernelCall.so /opt/cuda-7.0/lib64/libcudart_static.a -lpthread /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libdl.so -Wl,-rpath,"."
In that case, you don't want to link against:
/opt/cuda-7.0/lib64/libcudart_static.a
but instead against libcudart.so:
/opt/cuda-7.0/lib64/libcudart.so
If you were editing your make.sh directly, you would want to make that change in both of the /usr/bin/c++ command lines you have shown. For example, if I were to modify my compile sequence already presented to reflect your usage of the host c++ compiler to do the linking, it would look like this:
$ nvcc -c -Xcompiler -fPIC testKernel.cu
$ g++ -fPIC -shared -o test.so -L/usr/local/cuda/lib64 -lcudart testKernel.o
$ nvcc -c useKernel.cu
$ g++ -o test -L/usr/local/cuda/lib64 -lcudart test.so useKernel.o
$ cuda-memcheck ./test
========= CUDA-MEMCHECK
OK
========= ERROR SUMMARY: 0 errors
$
put set(CUDA_USE_STATIC_CUDA_RUNTIME OFF) before find_package(CUDA REQUIRED) will do the job equivalent to set(CUDA_LIBRARIES "${CUDA_TOOLKIT_ROOT_DIR}/lib64/libcudart.so")
This is an extension to Robert Crovella's answer.
I use the following CMakeLists.txt and it works well.
cmake_minimum_required(VERSION 3.8)
project(cmake_and_cuda LANGUAGES CXX CUDA)
add_library(my_cu SHARED testKernel.cu testKernel.h)
target_link_libraries(my_cu PRIVATE cudart) #MUST!!
set(CMAKE_CUDA_FLAGS "-shared -cudart shared -Xcompiler -fPIC"
CACHE STRING "Use libcudart.dylib" FORCE)
set(CMAKE_MACOSX_RPATH FALSE)
add_executable(app useKernel.cu)
target_link_libraries(app PRIVATE cudart) #MUST!!
target_link_libraries(app PRIVATE my_cu)
I'm using CMake 3.10 and my OS is OS X EI Capitan 10.11.6.
For me, if I don't set CMAKE_MACOSX_RPATH to FALSE, I will get a Library not loaded error. Maybe it is not necessary for you.
Note that since CMake 3.8, the FindCUDA is superseded, so setting CUDA_USE_STATIC_CUDA_RUNTIME affects nothing.
You can check this post and this document for details.
In addition, this post provides a good example about how to deal with CUDA after CMake 3.8.
I am trying to compile MySQL++ 3.1.0 with the command:
mingw32-make -f Makefile.mingw
After a set of files gets compiled (e.g. beemutex.cpp, cmdline.cpp, connection.cpp, ...), I get these errors:
g++ -c -o mysqlpp_sql_buffer.o -g -mthreads -DUNICODE -D_UNICODE -DMYSQLPP_NO_DLL -DHAVE_MYSQL_SSL_SET -I"C:\Program Files\MySQL\MySQL Server 5.5\include" -MT
mysqlpp_sql_buffer.o -MFmysqlpp_sql_buffer.o.d -MD -MP lib/sql_buffer.cpp
In file included from lib/sql_buffer.h:31:0,
from lib/sql_buffer.cpp:26:
lib/refcounted.h:258:2: error: 'size_t' does not name a type
lib/refcounted.h: In constructor 'mysqlpp::RefCountedPointer<T, Destroyer>::RefCountedPointer()':
lib/refcounted.h:89:2: error: class 'mysqlpp::RefCountedPointer<T, Destroyer>' does not have any field named 'refs_'
lib/refcounted.h: In constructor 'mysqlpp::RefCountedPointer<T, Destroyer>::RefCountedPointer(T*)':
lib/refcounted.h:100:2: error: class 'mysqlpp::RefCountedPointer<T, Destroyer>' does not have any field named 'refs_'
lib/refcounted.h:104:4: error: 'refs_' was not declared in this scope
lib/refcounted.h:104:16: error: expected type-specifier before 'size_t'
lib/refcounted.h:104:16: error: expected ';' before 'size_t'
lib/refcounted.h: In constructor 'mysqlpp::RefCountedPointer<T, Destroyer>::RefCountedPointer(const ThisType&)':
lib/refcounted.h:112:2: error: class 'mysqlpp::RefCountedPointer<T, Destroyer>' does not have any field named 'refs_'
lib/refcounted.h:115:8: error: 'refs_' was not declared in this scope
lib/refcounted.h: In destructor 'mysqlpp::RefCountedPointer<T, Destroyer>::~RefCountedPointer()':
lib/refcounted.h:125:7: error: 'refs_' was not declared in this scope
lib/refcounted.h: In member function 'void mysqlpp::RefCountedPointer<T, Destroyer>::swap(mysqlpp::RefCountedPointer<T, Destroyer>::ThisType&)':
lib/refcounted.h:246:13: error: 'refs_' was not declared in this scope
mingw32-make: *** [mysqlpp_sql_buffer.o] Error 1
Something could be wrong in my configuration, but I can't find what. It seems strange that it cannot find, e.g., size_t.
Thank you!
Platform:
Windows 7
MinGW 2011.09 / GCC 4.6.1
MySQL 5.5
mysql++ 3.1.0
Changing size_t() with std::size_t() in refcounted.h solved the problem. It now compiles.
I still have linking problems, but they should be different issues.