bashmakefile

expected asm before string


so I'm new here and i have this problem I have a project where I have to do a makefile also I have 3 files , but let's take one at least this is makefile

333.o: 333.c
gcc -c 333.c 


clean: rm *.o hell  

this is file I want to compile

#!/bin/bash    
echo "enetered number $1 threshold $2"

Error c:1:2 invalid preprocessing directive #! c:2: expected '=', ',',';','asm' or '_attribute' before string constant

what is wrong? can't figure out


Solution

  • The contents of file you are trying to compile indicate that it is a shell script and not a c file. However when make sees that the file has a .c extension, it will try to compile it as if it were a c file, which its contents patently are not.

    Before you go further I suggest you look at the differences between compiled and interpreted languages

    bash is an interpreted language - there is no need for a compiler at all. Just give the file execute permissions and run it. bash will parse and interpret the file line by line and take the necessary actions

    c is a compiled language. Before the source that defines a c program can run, it must be compiled. The compiler parses the .c files and generates binary object files, which contain machine instructions that your CPU directly understands.

    To run your bash shell script, I would do the following:

    mv 333.c 333.sh           ; # rename to prevent any confusion
    chmod +x 333.sh           ; # give the bash script executable permissions
    ./333.sh 42 69            ; # run the script - give it some args, since your script references $1 and $2