I've installed CUDA on debian,i've successfully ran make file in C folder withing cuda folder.but whn i'm trying to run individual file like matMult.cu with nvcc i'm getting following error
error:matrixMult.cu:no such file or directory
error:cutil_inline:no such file or directory
n also it is complaining about other header files...please help me out
The CUDA SDK examples use a custom makefile based on rules defined in a common.mk file. In order to compile individually the examples you can make use of that Makefiles which can be tuning to add more dependencies or extra info.
To compile the matrixMul example by hand using the nvcc compiler, for an architecture of 64 bits and a Fermi device you can use:
g++ -Wall -m64 -fno-strict-aliasing -I. -I/usr/local/cuda/include -I../../common/inc -I../../../shared//inc -DUNIX -O2 -o obj/x86_64/release/matrixMul_gold.cpp.o -c matrixMul_gold.cpp
/usr/local/cuda/bin/nvcc -gencode=arch=compute_20,code=\"sm_20,compute_20\" -m64 --compiler-options -fno-strict-aliasing -I. -I/usr/local/cuda/include -I../../common/inc -I../../../shared//inc -DUNIX -O2 -o obj/x86_64/release/matrixMul.cu.o -c matrixMul.cu
g++ -m64 -o ../../bin/linux/release/matrixMul obj/x86_64/release/matrixMul_gold.cpp.o obj/x86_64/release/matrixMul.cu.o -L/usr/local/cuda/lib64 -L../../lib -L../../common/lib/linux -L../../../shared//lib -lcudart -L/usr/local/cuda/lib64 -L../../lib -L../../common/lib/linux -L../../../shared//lib -lcudart -lcutil_x86_64 -lshrutil_x86_64
Compile the CUDA SDK examples by hand it's a little weary. I recommend you use the makefile of each example or start a new project from the scratch.
Related
I am trying to develop an application in C in a target Linux system which requires Mysql Conectivity but i dont know where to include in NETBEANS the required directives for the libmysqlclient-dev library.
I have the following:
A laptop with NETBEANS IDE 8.0.2 and remote build host setup.
A remote Ubuntu linux target which is the remote build host for netbeans.
apt-get install libmysqlclient-dev in the Ubuntu Target
mysql_config --libs gives:
-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -ldl
mysql_config --libs gives:
-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -ldl
According to the Mysql C Api Building I have to include the following:
gcc -c `mysql_config --cflags` progname.c
gcc -o progname progname.o `mysql_config --libs`
Although I am able to build my program manually in the target system, I am not sure where to add the above information in Netbeans.
P.S.1 at the momment my Netbeans build command looks like this:
gcc -o dist/Debug/GNU-Linux-x86/arguments_1 build/Debug/GNU-Linux-x86/src/args.o
P.S.2 Please be gentle. I am a newbie with Netbeans, Remote builds, C and Linux development.
Ok I have managed to get it working.
First I needed to include the Mysql Library paths to the Netbeans makefile as per this post:
gcc wont compile and run MySQL C libraries
# These are the flags that gcc requires in order to link correctly against our installed
# client packages
MYSQL_LIBS := $(shell mysql_config --cflags --libs)
Then right click on my project node , select Properties->Build->Linker->Compilation Line->Additional Options and add $(MYSQL_LIBS) to the Additional options parameter.
My problem was that I was adding it into the C compiler Additional options parameter.
But this post helped to clarify the order:
Why does the order in which libraries are linked sometimes cause errors in GCC?
So now my Netbeans gcc command looks like:
gcc -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/src/args.o.d" -o build/Debug/GNU-Linux-x86/src/args.o src/args.c
gcc -o dist/Debug/GNU-Linux-x86/arguments_1 build/Debug/GNU-Linux-x86/src/args.o -I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -g -DNDEBUG -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -ldl
Thank you Lumi, Thanassis
I would like to cross compile a simple program that uses libncurses on my x86_64. Target system is MIPS.
My crosstool-ng-1.20 build went fine (with sample mips-unknown-elf)
However, a simple hello world ends badly.
#include <stdio.h>
int main(void)
{
printf("OH HAI.\n");
return 0;
}
--
x86host:~/toolchain$ mips-unknown-elf-gcc -o hello hello.c
hello.c:1:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^
compilation terminated.
I'm clearly doing something terribly wrong here, but where do i start?
[Edit]
Thank you markgz. Codesourcery is exactly what i needed.
mips-linux-gnu-gcc.exe -static -o helloStatic hello.c
Proof of concept complete. Now off to compile my ncurses program.
[Switch:/]$ file /mnt/sd3/user/helloStatic
/mnt/sd3/user/helloStatic: ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1,
statically linked, for GNU/Linux 2.6.16, with unknown capability
0x41000000 = 0xf676e75, not stripped
[Switch:/]$ uname -a
Linux Switch 2.6.32.59-cavium-octeon2.cge-cavium-octeon #1
SMP PREEMPT Fri May 10 11:48:14 PDT 2013 mips64 GNU/Linux
[Switch:/]$ /mnt/sd3/user/helloStatic
HOLIDAYS ARE COMING.
You probably needed to build mips-linux-elf-gcc. Are you sure your MIPS target system is configured as big-endian?
Anyway, you can avoid all these problems by downloading the free Mentor/Codesourcery MIPS gnu/gcc cross compilation tool chain from here. This toolchain is available for both Windows and Linux.
root#x86host:~/ncurses-5.9-20141101# export CC=mips-linux-gnu-gcc
root#x86host:~/ncurses-5.9-20141101# ./configure --target=mips-linux-gnu --host=mips-linux-gnu
[..]
root#x86host:~/ncurses-5.9-20141101# make
Then, i copied over a few headers from /usr/include/ to make these go away:
root#x86host:~/ninvaders-0.1.1# make
In file included from ./ncurses.h:1685:0,
from view.h:25,
from view.c:25:
./unctrl.h:54:20: fatal error: curses.h: No such file or directory
#include <curses.h>
^
compilation terminated.
make: *** [view.o] Error 1
root#x86host:~/ninvaders-0.1.1# make
mips-linux-gnu-gcc -static -c -I. -O -Wall globals.c
mips-linux-gnu-gcc -static -c -I. -O -Wall view.c
mips-linux-gnu-gcc -static -c -I. -O -Wall aliens.c
mips-linux-gnu-gcc -static -c -I. -O -Wall ufo.c
mips-linux-gnu-gcc -static -c -I. -O -Wall player.c
mips-linux-gnu-gcc -static -c -I. -O -Wall nInvaders.c
mips-linux-gnu-gcc -static -L /root/ncurses-5.9-20141101/lib -onInvaders globals.o view.o aliens.o ufo.o player.o nInvaders.o -lncurses
root#x86host:~/ninvaders-0.1.1# ls -l nInvaders
-rwxr-xr-x 1 root root 933003 Nov 6 16:18 nInvaders
root#x86host:~/ninvaders-0.1.1# mv nInvaders nInvaders_IOSXE_MIPS
For future googlers, Makefile is:
CC=mips-linux-gnu-gcc -static
CFLAGS=-O -Wall
LIBS=-lncurses
LDFLAGS=-L /root/ncurses-5.9-20141101/lib
CFILES=globals.c view.c aliens.c ufo.c player.c nInvaders.c
HFILES=globals.h view.h aliens.h ufo.h player.h nInvaders.h
OFILES=globals.o view.o aliens.o ufo.o player.o nInvaders.o
all: nInvaders
nInvaders: $(OFILES) $(HFILES)
$(CC) $(LDFLAGS) -o$# $(OFILES) $(LIBS)
.c.o:
$(CC) -c -I. $(CFLAGS) $(OPTIONS) $<
clean:
rm -f nInvaders $(OFILES)
End result:
root#x86host:~/ninvaders-0.1.1# file nInvaders_IOSXE_MIPS
nInvaders_IOSXE_MIPS: ELF 32-bit MSB executable, MIPS,
MIPS32 rel2 version 1, statically linked, for GNU/Linux 2.6.16, not stripped
Screenshots:
http://imgur.com/a/kf8cu
https://www.youtube.com/watch?v=-qbmKYQ2jCA
I have trouble installing the mysql udf (https://github.com/mysqludf/lib_mysqludf_sys). Here's what I'm getting:
Compiling the MySQL UDF
gcc -Wall -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o /usr/lib/lib_mysqludf_sys.so
/usr/bin/ld: /tmp/ccw6HRtN.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/tmp/ccw6HRtN.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [install] Error 1
ERROR: You need libmysqlclient development software installed
to be able to compile this UDF, on Debian/Ubuntu just run:
apt-get install libmysqlclient15-dev
Any ideas? TIA
UPDATED:
I have already the libmysqlclient15-dev installed.
Try to recompile with -fPIC flag. It obviously hints at it:
/usr/bin/ld: /tmp/ccw6HRtN.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
I know this is an old question, however I've just had this issue using Ubuntu 16.
I solved changing the Makefile in the following way, as explained in a GitHub issue:
LIBDIR=/usr/lib/mysql/plugin
install:
gcc -DMYSQL_DYNAMIC_PLUGIN -fPIC -Wall -I/usr/include/mysql -I. -shared lib_mysqludf_sys.c -o $(LIBDIR)/lib_mysqludf_sys.so
These commands were generated procedurally by a Makefile that I essentially copied from NVIDIA's tutorial pages; it's over 100 lines long and will post it if you think it's necessary, but these commands are sufficient to reproduce the errors.
g++ -m64 -I/usr/local/cuda/include -I. -I.. -I../../common/inc -I/usr/local/cuda/lib64 -o shallowwater.o -c shallowwater.cpp
/usr/local/cuda/bin/nvcc -m64 -gencode arch=compute_10,code=sm_10 -gencode arch=compute_20,code=sm_20 -I/usr/local/cuda/include -I. -I.. -I../../common/inc -I/usr/local/cuda/lib64 -o shallowwatercudamain.o -c shallowwatercudamain.cu
g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L -lcudart
The first two work; there is no compile error for either of the two source files, but when the third command is run, I get the following error:
shallowwatercudamain.o: In function `__cudaUnregisterBinaryUtil()':
tmpxft_00004e70_00000000-4_shallowwatercudamain.compute_20.cudafe1.cpp:(.text+0x36): undefined reference to `__cudaUnregisterFatBinary'
shallowwatercudamain.o: In function `__sti____cudaRegisterAll_66_tmpxft_00004e70_00000000_6_shallowwatercudamain_compute_20_cpp1_ii_runIt()':
tmpxft_00004e70_00000000-4_shallowwatercudamain.compute_20.cudafe1.cpp:(.text+0x46): undefined reference to `__cudaRegisterFatBinary'
collect2: ld returned 1 exit status
make: *** [shallowwater] Error 1
Here is some relevant system information:
[foo#bar code]$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2012 NVIDIA Corporation
Built on Thu_Apr__5_00:24:31_PDT_2012
Cuda compilation tools, release 4.2, V0.2.1221
[foo#bar code]$ uname -a
Linux intel19 2.6.32-71.el6.x86_64 #1 SMP Wed Sep 1 01:33:01 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
I found someone with a similar error here, seen here: /usr/bin/ld: cannot find -lcudart
I'm embarrassed to say I found this, made the same change except for g++ instead of gfortran, and it worked. Afterwards, I tried it again and it did not work. I get the same error with:
g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L -L/usr/local/cuda/lib64
This command does not look right to me:
g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L -lcudart
And this command does not look right to me:
g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L -L/usr/local/cuda/lib64
This command looks right to me:
g++ -m64 -o shallowwater shallowwater.o shallowwatercudamain.o -L/usr/local/cuda/lib64 -lcudart
You need to tell g++ where to look for the cudart library, that is what the -L/usr/local/cuda/lib64 switch is for (so it needs a path, you cannot just use -L by itself) and you need to tell g++ the name of the library to use, that is what the -lcudart is for.
I realized you didnt put "-lcudart" in your last line. Did you link to cudart when you were doing actual compilation ?
This might sound like a dumb question. But here goes..... I am using a C program called db_access.c which interacts with MySQL (in Ubuntu 10.10 with MySQL Server version: 5.1.49-1ubuntu8.1 (Ubuntu)). Inside the program, I have: include "mysql.h"
When I do the following, everything works out right:
gcc -I/usr/include/mysql db_access.c -lmysqlclient -o db_access
./db_access
Problem arises when I try to integrate it into an existing (and working makefile). The contents of the makefile:
all: MappingServer
#Macro definitions
CC = gcc
CFLAGS = -lm
INCLUDES = -I/usr/include/mysql
LIBS = -L/usr/lib/mysql -lmysqlclient
MappingServer.o: MappingServer.c map_registration.h
$(CC) $(CFLAGS) -c MappingServer.c
route_aggregation.o: route_aggregation.c map_registration.h
$(CC) $(CFLAGS) -c route_aggregation.c
db_access.o: db_access.c map_registration.h mysql.h
$(CC) $(CFLAGS) $(INCLUDES) -c db_access.c
MappingServer: MappingServer.o route_aggregation.o db_access.o
$(CC) $(LIBS) -o MappingServer MappingServer.o route_aggregation.o db_access.o
clean:
-rm MappingServer.o route_aggregation.o db_access.o
I have two other C programs, MappingServer.c and route_aggregation.c. These 3 files need to be compiled together. By the way, I also did:
root#ahuq-kitchen:/home/ahuq/MappingServer# mysql_config --cflags
-I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
and
root#ahuq-kitchen:/home/ahuq/MappingServer# mysql_config --libs
-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient
So I think the paths are OK. When I do: make all
I get:
root#ahuq-kitchen:/home/ahuq/MappingServer# make all
gcc -lm -c MappingServer.c
gcc -lm -c route_aggregation.c
route_aggregation.c: In function ‘vtysh_input’:
route_aggregation.c:602: warning: function returns address of local variable
make: *** No rule to make target `mysql.h', needed by `db_access.o'. Stop.
Why is this happening?
the line
db_access.o: db_access.c map_registration.h mysql.h
tells make that db_access.o depends on db_access.c, map_registration.h and mysql.h. make complains because mysql.h cannot be found in the current directory (it's in /usr/include/mysql).
see the question Makefile updated library dependency for how to specify libraries as dependencies in make
You put "mysql.h" as a dependency, but it's not in the current directory, so Make thinks it needs to build it, but doesn't know how.
try to remove all the lines like:
MappingServer.o: MappingServer.c map_registration.h
if the map_registration.h is included in the c file, make is smart enough to find it. The only thing to be noticed may be to set the search file path using: -I.