-1

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

thank you

1 Answers1

1
  • You are trying to pound a nail with a screwdriver - you are using the wrong tool for the job.
  • You are trying to speak mandarin to (mono-lingual) frenchman - you are using the wrong language.

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
Community
  • 1
  • 1
Digital Trauma
  • 15,475
  • 3
  • 51
  • 83
  • thanks for your response. Yes, I do have home work, but it's different. I just can't understand how it works. I have way bigger code than this. I know how to do it with just a script. I got a lot of tutorials how to do make file, but I still can't understand in clearly. – Yuriy Mikhailovich Oct 02 '13 at 18:43
  • @YuriyMikhailovich - if you are writing a script (which it appears you are), then you don't need `make` at all. Makefiles generally contain a bunch of rules which tell the compiler how a particular program is to be compiled and linked. On the other hand, you ***don't*** compile scripts - they are interpreted - so there should be no need for `make` here at all. – Digital Trauma Oct 02 '13 at 18:48
  • Alternatively, if you do want to compile something (and use make), then you must write your program in a language the compiler understands - c is an example. Compilers simply don't understand interpreted languages, such as bash shell script. – Digital Trauma Oct 02 '13 at 18:50