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
Related
How to make libtool don't use (in compile mode) .libs folder for generated PIC object files but another one or even change the name of PIC file, for example: object-file.lo, object-file.o, object-file-pic.o -> these three in one folder.
Standard procedure:
$ libtool --mode=compile gcc -O -o call.o -c called.c
libtool: compile: gcc -O -c called.c -fPIC -DPIC -o .libs/call.o
libtool: compile: gcc -O -c called.c -o call.o >/dev/null 2>&1
I have the cuda 4.0 toolkit installed in my Ubuntu 12.04 server. When I am trying to build a cuda code present in Rodinia benchmark suite. I was getting the following error. i.e, after running the make command
ncclab#slave13:~/Downloads/rodinia_2.4$ make
cd cuda/cfd; make; cp euler3d euler3d_double pre_euler3d pre_euler3d_double /home/ncclab/Downloads/rodinia_2.4/bin/linux/cuda
make[1]: Entering directory `/home/ncclab/Downloads/rodinia_2.4/cuda/cfd'
nvcc -O2 -Xptxas -v --gpu-architecture=compute_20 --gpu-code=compute_20 euler3d.cu -o euler3d -I/if10/kw5na/NVIDIA_GPU_Computing_SDK4/C/common/inc -L/if10/kw5na/NVIDIA_GPU_Computing_SDK4/C/lib
euler3d.cu:35: warning: #warning "the kernels may fail too launch on some systems if the block length is too large"
euler3d.cu:35: warning: #warning "the kernels may fail too launch on some systems if the block length is too large"
By here the euler3d was built
nvcc -Xptxas -v -O3 --gpu-architecture=compute_20 --gpu-code=compute_20 euler3d_double.cu -o euler3d_double -I/if10/kw5na/NVIDIA_GPU_Computing_SDK4/C/common/inc -L/if10/kw5na/NVIDIA_GPU_Computing_SDK4/C/lib
/tmp/tmpxft_0000532d_00000000-12_euler3d_double.o: In function `main':
tmpxft_0000532d_00000000-1_euler3d_double.cudafe1.cpp:(.text+0x22d9): undefined reference to `cutCreateTimer'
tmpxft_0000532d_00000000-1_euler3d_double.cudafe1.cpp:(.text+0x22f7): undefined reference to `cutStartTimer'
tmpxft_0000532d_00000000-1_euler3d_double.cudafe1.cpp:(.text+0x2457): undefined reference to `cutStopTimer'
tmpxft_0000532d_00000000-1_euler3d_double.cudafe1.cpp:(.text+0x246c): undefined reference to `cutGetAverageTimerValue'
collect2: ld returned 1 exit status
make[1]: *** [euler3d_double] Error 1
make[1]: Leaving directory `/home/ncclab/Downloads/rodinia_2.4/cuda/cfd'
cp: cannot stat `euler3d_double': No such file or directory
cp: cannot stat `pre_euler3d': No such file or directory
cp: cannot stat `pre_euler3d_double': No such file or directory
make: *** [CUDA] Error 1
By searching I came to know that there may be a problem with libcutil
But I had the libcutil_x86_64.a in ~/NVIDIA_GPU_Computing_SDK/C/lib
Edit: The contents of various folders are
ncclab#slave13:~/NVIDIA_GPU_Computing_SDK/C/lib$ ls
libcutil_x86_64.a libparamgl_x86_64.a librendercheckgl_x86_64.a
~/Downloads/rodinia_2.4/cuda/cfd$ ls
euler3d euler3d_double.cu Makefile~ pre_euler3d.cu README
euler3d.cu Makefile Makefile_nvidia pre_euler3d_double.cu run
ncclab#slave13:~/NVIDIA_GPU_Computing_SDK/C/common/inc$ ls
bank_checker.h cutil_inline.h GL nvVector.h stopwatch_base.h
cmd_arg_reader.h cutil_inline_runtime.h multithreading.h nvWidgets.h stopwatch_base.inl
cuda_drvapi_dynlink.c cutil_math.h nvGlutWidgets.h paramgl.h stopwatch.h
cutil_gl_error.h dynlink nvGLWidgets.h param.h stopwatch_linux.h
cutil_gl_inline.h dynlink_d3d10.h nvMath.h rendercheck_d3d10.h
cutil.h dynlink_d3d11.h nvMatrix.h rendercheck_d3d11.h
cutil_inline_bankchecker.h error_checker.h nvQuaternion.h rendercheck_d3d9.h
cutil_inline_drvapi.h exception.h nvShaderUtils.h rendercheck_gl.h
the partial contents of the makefile are
all: euler3d euler3d_double pre_euler3d pre_euler3d_double
euler3d: euler3d.cu
nvcc -O2 -Xptxas -v --gpu-architecture=compute_20 --gpu-code=compute_20 euler3d.cu -o euler3d -I$(CUDA_SDK_PATH)/common/inc -L$(CUDA_SDK_PATH)/lib $(CUTIL_LIB)
euler3d_double: euler3d_double.cu
nvcc -Xptxas -v -O3 --gpu-architecture=compute_20 --gpu-code=compute_20 euler3d_double.cu -o euler3d_double -I$(CUDA_SDK_PATH)/common/inc -L$(CUDA_SDK_PATH)/lib $(CUTIL_LIB)
pre_euler3d: pre_euler3d.cu
nvcc -Xptxas -v -O3 --gpu-architecture=compute_20 --gpu-code=compute_20 pre_euler3d.cu -o pre_euler3d -I$(CUDA_SDK_PATH)/common/inc -L$(CUDA_SDK_PATH)/lib $(CUTIL_LIB)
pre_euler3d_double: pre_euler3d_double.cu
nvcc -Xptxas -v -O3 --gpu-architecture=compute_20 --gpu-code=compute_20 pre_euler3d_double.cu -o pre_euler3d_double -I$(CUDA_SDK_PATH)/common/inc -L$(CUDA_SDK_PATH)/lib $(CUTIL_LIB)
The euler3d has been successfully built. The errors are occurring for all the remaining three files.So I don't think there is any problems in the directories they are referring to
I really don't understand why the undefined reference to `cutCreateTimer' and others are occurring. But searching in SE I came to know that when there is any problem with cutil.h or libcutil these problems exits. I was a newbie of linux environment. So please help me
Edit 2: In a include file named make.config the following lines were present
# CUDA SDK installation path
#SDK_DIR = $(HOME)/NVIDIA_GPU_Computing_SDK/C
SDK_DIR =/if10/kw5na/NVIDIA_GPU_Computing_SDK4/C
#SDK_DIR =/if10/kw5na/NVIDIA_CUDA_Computing_SDK4/C
Here by default the 2nd option was selected and the euler3d was built. So I thought there may be a problem because of this. But changing it does not change the problem I was facing
and about cutil library present in make file
CUDA_SDK_PATH := $(SDK_DIR)
# Determine the correct version of the cutil library
CUTIL_LIB = # -lcutil
ifeq ($(shell uname -m), x86_64)
ifeq ($(shell if test -e $(SDK_DIR)/lib/libcutil_x86_64.a; then echo T; else echo F; fi), T)
CUTIL_LIB = #-lcutil_x86_64
endif
endif
Which I think was correct
The problem is that your compile command is specifying the library path, but not the library itself that is providing the cut... functionality.
This is apparently the makefile line that is generating the nvcc compile command for euler3d_double:
euler3d_double: euler3d_double.cu
nvcc -Xptxas -v -O3 --gpu-architecture=compute_20 --gpu-code=compute_20 euler3d_double.cu -o euler3d_double -I$(CUDA_SDK_PATH)/common/inc -L$(CUDA_SDK_PATH)/lib $(CUTIL_LIB)
This is the generated compile command:
nvcc -Xptxas -v -O3 --gpu-architecture=compute_20 --gpu-code=compute_20 euler3d_double.cu -o euler3d_double -I/if10/kw5na/NVIDIA_GPU_Computing_SDK4/C/common/inc -L/if10/kw5na/NVIDIA_GPU_Computing_SDK4/C/lib
You'll note that the last two tokens in the makefile line are:
-L$(CUDA_SDK_PATH)/lib $(CUTIL_LIB)
The -L$... token is getting converted to the correct library path. But the $(CUTIL_LIB) token should be getting converted to something like -lcutil or perhaps -lcutil_x86_64, but that is not happening. As a result, the library that provides the cut...Timer... functions is missing, and so those appear to be undefined.
I would inspect the Makefile carefully to see if there are any end-of-line characters or other oddities that are different between the line that specifies how euler3d_double should be built and the previous lines that specify how euler3d should be built.
You should also be able to confirm this by looking at the nvcc compile command line generated for euler3d (which you don't show) and comparing it to the one for euler3d_double (which is failing).
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 ?
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.
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.