How to make a file appear to 'ls' in xv6 QEMU? - c

I'm messing around with xv6 in QEMU, and I made a new file in the directory I'm in, and when I'm in QEMU and type ls the file isn't listed. In fact, lots of files aren't listed, and I can't figure out why it lists the ones it does. It seems to only list compiled .c files, and for some reason a README, but not the compiled .c file I just made.

Possibly because you forgot to add your .c file in the Makefile. Suppose test.c is the file you want to add. You need to add it in the Makefile under UPROGS as:
UPROGS=\
....
....
_test\
and under EXTRA as:
EXTRA=\
mkfs.c ulib.c user.h cat.c echo.c forktest.c grep.c kill.c\
ln.c ls.c mkdir.c rm.c stressfs.c usertests.c wc.c zombie.c\
printf.c umalloc.c **test.c**\
README new.txt dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\
.gdbinit.tmpl gdbutil\
If you want to add generic files like README to Xv6, refer to this question:
Add a generic file in xv6 makefile

Related

How to use functions in a package that is written in C in a different location

I am trying to use a linear algebra package called hnfprof. I have done the installation with the given instructions and now its ready to use. Now I want to use some functions in hnfproj/src/lift/lift.c file. I want to create my own matrix examples and check outputs for each functions separately. I am not clear how to do this. (I know only basics of C language, creating .c files in a folder and running it in my Ubuntu terminal.)
I know that I should write a C file including this "#include <lift.c>" file name and creating a matrix in my file "main.c". I don't know how to include a file name in a different location. When I compile I can not use "gcc -o program main.c lift.c". My "main.c" file is in a different folder. I don't want to create any make file inside the package folder. So how I can just use the "lift.c" file inside my "main.c" file which is in a separate folder "Main" and create all executable make files inside "Main" folder?
If its difficult to give a answer, appreciate if you can suggest me some source to learn this. Thank you
No need to include lift.c directly in main.c, and you can call function in lift.c from main.
When it comes to compilation, you can use:
gcc -o program main.c file_location/lift.c
If you need other options, add them (most flags at the start; libraries at the end, after the source code). You can also compile each file to object code separately and then link the object files together:
gcc -c main.c
gcc -c file_location/lift.c
gcc -o program main.o lift.o
refer
Compiling multiple C files with gcc

how to connect source files and header files in vscode in C

I received 3 files from my teacher, main.c , something.c , something.h .
the header file contains the declarations of the functions.
something.c contains the functions.
main.c contains several calls to the functions.
my question is, how can i run main.c and have everything connected? in python i just import the module and im done (as long the file im importing is saved at the system variables directory or same directory).
thanks
You need to compile both something.c and main.c and link them together in one binary executable file. I don't know which OS are you supposed to run this on, if using Ubuntu, or any linux for that matter you could install gcc or clang to compile your code.
For example:
clang -c something.c main.c
clang something.o main.o
./a.out
First line compiles your files individually (creating main.o and something.o files) Second line links them together creating one executable file (a.out) Third line runs the executable file.

Add a generic file in xv6 makefile

I'm currently studying the xv6 OS.
I found out here how to add a system call by modifying the MAKEFILE file.
My question is: how do we add simple text files or any other kind of file to be seen in the xv6 system once it boots?
README file in Xv6 is a generic file too. Searching for occurrences of README in the MakeFile and adding your required file will be sufficient.
Suppose new.txt is the file you want to add.
Parts of the MakeFile to be changed are:
1)
fs.img: mkfs README new.txt $(UPROGS)
./mkfs fs.img README new.txt $(UPROGS)
2)
PRINT = runoff.list runoff.spec README new.txt toc.hdr toc.ftr $(FILES)
3)
EXTRA=\
mkfs.c ulib.c user.h cat.c echo.c forktest.c grep.c kill.c\
ln.c ls.c mkdir.c rm.c stressfs.c usertests.c wc.c zombie.c\
printf.c umalloc.c\
README new.txt dot-bochsrc *.pl toc.* runoff runoff1 runoff.list\
.gdbinit.tmpl gdbutil\
Like Sravani suggested, I added my "new.txt" adjecent to all occurences of README. I got the error:
make: No rule to make target `sample.txt', needed by `fs.img'. Stop.
Then I removed the file type, i.e ".txt". Works well now!

Compiling with .lst file

I am trying to install the MIRACL library for my crypto system. While I was configuring the library, it gave me "miracle.lst" that contains list of files I need to compile. I was just wondering is there any way me to compile all files inside of .lst file once? I don't think it is an assembly file because it only contains names. I saw this link but it is nothing related with my situation.
List File In C (.LST)
Inside of miracl.lst
mrcore.c
mrarth0.c
mrarth1.c
mrarth2.c
...
In my case
gcc -I./include -c -O2 source/mr*.c

generating a makefile for the dumb

I got 10 C files.
10 h files all in one folder.
I need those files to create 1 executable in the same folder using unix makefile.
EDIT :
the soultion
create a file named "makefile"
write the following make sure you have a single TAB before the word "gcc" this will create a.out executable
all:
gcc *.c
if you need flags just add them for example to make the filename BOB:
all:
gcc *.c -o BOB
I don't think you want what you say you want, but how about:
all:
gcc *.c
"missing separator" is commonly caused by a missing tab in front of a command line. The lines with $(CXX) need to be indented by a tab - not 8 spaces, not any number of spaces, but a tab.
Additionally, I don't think that empty lines between rule and commands are allowed.
Apart from obviously writing the Makefile yourself, you can also use CMake which is a convenient build system generator.
A simple example of a CMakeLists.txt file:
cmake_minimum_required(VERSION 2.6)
project(yourproject C)
add_executable(yourexecutable file1.c file1.h file2.c file2.h ...)
You can then do in a terminal:
$ cmake .
$ make
and your executable will be built.
Be careful however that the generated makefile uses cmake and is therefore not distributable per se.

Resources