Create a script called create_static_lib.sh that creates a static library called liball.a from all the .c files that are in the current directory.julien@ubuntu:~/0x09. Static Librairies$ ls *.c0-isupper.c 0-strcat.c 1-isdigit.c 1-strncat.c 2-strlen.c 3-islower.c 3-strcmp.c 4-isalpha.c 5-strstr.c 9-strcpy.c _putchar.c0-memset.c 100-atoi.c 1-memcpy.c 2-strchr.c 2-strncpy.c 3-puts.c 3-strspn.c 4-strpbrk.c 6-abs.cjulien@ubuntu:~/0x09. Static Librairies$ ./create_static_lib.sh julien@ubuntu:~/0x09. Static Librairies$ ls *.aliball.ajulien@ubuntu:~/0x09. Static Librairies$ ar -t liball.a0-isupper.o0-memset.o0-strcat.o100-atoi.o1-isdigit.o1-memcpy.o1-strncat.o2-strchr.o2-strlen.o2-strncpy.o3-islower.o3-puts.o3-strcmp.o3-strspn.o4-isalpha.o4-strpbrk.o5-strstr.o6-abs.o9-strcpy.o_putchar.ojulien@ubuntu:~/0x09. Static Librairies$
Question
Create a script called create_static_lib.sh that creates a static library called liball.a from all the .c files that are in the current directory.julien@ubuntu:~/0x09. Static Librairies ./create_static_lib.sh julien@ubuntu:~/0x09. Static Librairies ar -t liball.a0-isupper.o0-memset.o0-strcat.o100-atoi.o1-isdigit.o1-memcpy.o1-strncat.o2-strchr.o2-strlen.o2-strncpy.o3-islower.o3-puts.o3-strcmp.o3-strspn.o4-isalpha.o4-strpbrk.o5-strstr.o6-abs.o9-strcpy.o_putchar.ojulien@ubuntu:~/0x09. Static Librairies$
Solution
To create a script that creates a static library from all the .c files in the current directory, follow these steps:
-
Open your terminal.
-
Navigate to the directory containing your .c files using the
cdcommand. -
Create a new file called
create_static_lib.shusing thetouchcommand like so:touch create_static_lib.sh. -
Open this file in your text editor. You can use the
nanocommand for this:nano create_static_lib.sh. -
In the opened file, write the following script:
#!/bin/bash
gcc -c *.c
ar -rc liball.a *.o
This script first compiles all .c files in the current directory into object files (.o files) with the gcc -c *.c command. Then it archives these object files into a static library called liball.a with the ar -rc liball.a *.o command.
-
Save and close the file. If you're using
nano, you can do this by pressingCtrl+X, thenY, thenEnter. -
Now you need to make your script executable. You can do this with the
chmodcommand like so:chmod +x create_static_lib.sh. -
You can now run your script with the following command:
./create_static_lib.sh. -
If everything went well, you should now have a static library called liball.a in your current directory. You can check this with the
lscommand. -
To see the object files contained in your static library, you can use the
ar -t liball.acommand.
Similar Questions
What command(s) can be used to list the symbols stored in a static library?
What command(s) can be used to list the symbols stored in a static library?ldarranlibnm
What command(s) can be used to list the symbols stored in a static library?Select all valid answersldarranlibnmI don't knowSubmit
Which of the following is an example of a dynamic linking library in Linux?Select one:a. .lib (library)b. .dylib (dynamic library)c. .so (shared object)d. .dll (dynamic link library)
Write a script that compiles a C file but does not link.The C file name will be saved in the variable $CFILEThe output file should be named the same as the C file, but with the extension .o instead of .c.Example: if the C file is main.c, the output file should be main.o
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.