#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    not sure yet
    Posts
    5
    Rep Power
    0

    Post Need quick guideline about C programming


    :D Hi, everybody

    I am about to work on c project on linux (windows is ok too).
    I want to know about how to manage c project,e.g, compile, run, make it software.

    I had learn c in college, but never used in software developing.
    so I want to master everything about it now.
    so any one could tell me how to go on this path?
    at beginning what should I do,then what....
    first , second ...how can I smoothly know about c programming, and projects on linux?
    should I do like this
    1. c programming on linux, learn complie single code files...
    2.learn makefiles....
    3...anything also

    tell me steps in general,
    6
    :D thanks in advance.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,895
    Rep Power
    481
    Write, build, and run good-ol' "hello world". You'll figure out how to use a text editor (emacs is my long-time friend), where the files go, and how to invoke your compiler.

    I use a Makefile something like this:
    Code:
    #remember pkg-config
    
    override CFLAGS += -Wall -g -fpic
    override CXXFLAGS += -Wall -g
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,174
    Rep Power
    2222
    There are several books on Linux programming available. They tend to concentrate on Linux system calls, spawining new processes, inter-process communication, etc.

    A number of these books will also have a chapter on makefiles, so use that criterion in picking your book. If all else fails, there's the O'Reilly book, Managing Projects with make. What we usually do is that we will create or "research" a working makefile for one project and then copy that same makefile to the next project and edit it for the new project. We end up forgetting how to write a makefile from scratch, but we know how to modify them.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    not sure yet
    Posts
    5
    Rep Power
    0

    Post Hi, thanks


    Originally Posted by dwise1_aol
    There are several books on Linux programming available. They tend to concentrate on Linux system calls, spawining new processes, inter-process communication, etc.

    A number of these books will also have a chapter on makefiles, so use that criterion in picking your book. If all else fails, there's the O'Reilly book, Managing Projects with make. What we usually do is that we will create or "research" a working makefile for one project and then copy that same makefile to the next project and edit it for the new project. We end up forgetting how to write a makefile from scratch, but we know how to modify them.
    I learned how to compile and run single source code file like "HelloWorld",it is easy. and I searched some about make file, but not much success. but I realized there is a tool called "automake" ,I think this what people are using, right?

    is there any good source for beginners about how to create, manage C project from scratch? I think in this way I can understand many questions in my head.

    thank you very much ;)
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    not sure yet
    Posts
    5
    Rep Power
    0

    Hi


    I have able to open C project in eclipse , but it seems I only can edit codes, but could not compile and run C project with eclipse.

    :cool: so is commands on terminal only way to compile and run C project? :rolleyes:
  10. #6
  11. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,174
    Rep Power
    2222
    Originally Posted by alim428
    I learned how to compile and run single source code file like "HelloWorld",it is easy. and I searched some about make file, but not much success. but I realized there is a tool called "automake" ,I think this what people are using, right?
    I have heard about automake, but never used it. I think that it's supposed to automate part of the process of creating a makefile.

    The utility in question is called make. It "executes" a makefile, which by default is a file named makefile, but you can give it another name with the extension of .mak which you give to make. A makefile names the target, which is usually an executable, and what that target depends on (namely, a list of object and library files). Then the makefile gives the command needed generate those object and library files, which would be the command-line invocation of the compiler with the appropriate options.

    That makefile also has a dependency list which says what source and header files a particular object file depends on. One of the features of the make process is to only recompile the files that have changed and to leave the others alone; this was a very important consideration early on when computers were far slower and less powerful than they are now. If you change a source file (a .c), then it needs to be recompiled, but not a source file that you didn't change. However, if you change a header file (a .h), then all the header and source files that include that header file also need to be recompiled. It's that dependency list that make uses to decide what to recompile and what to leave alone. The decision as to which files had changed are based on comparing their modified timestamp with the timestamp of the target.

    However, what most people use is the project management features of their integrated development environment (IDE). In your IDE (I believe you say you're trying to use Eclipse, whereas I currently use Visual Studio, but used to use the Borland C++ IDE), you create a new project and then you add files to that project. This eliminates the need for a makefile, though a number of IDEs give you the option of generating a makefile from the project.

    I've never used Eclipse, but I would assume that it includes project management.

    Originally Posted by alim428
    is there any good source for beginners about how to create, manage C project from scratch? I think in this way I can understand many questions in my head.
    As I said, some Linux programming books include instructions on working with make; eg, Wrox' Beginning Linux Programming 2nd ed by Stones and Matthew. For a more complete treatment of make, I already mentioned the O'Reilly book. I'm sure there must be web pages as well.

    But if you're using gcc, then you can simply use it from the command line to compile multiple files. In the invocation, you simply list all the source files; eg:
    gcc -Wall -o myprog main.c file1.c file2.c
    Or, you could devote an entire directory to the project and only put the source files into that directory that are part of the project. Then you could work with a hundred source files with the simple command:
    gcc -Wall -o myprog *.c
  12. #7
  13. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,174
    Rep Power
    2222
    Originally Posted by alim428
    I have able to open C project in eclipse , but it seems I only can edit codes, but could not compile and run C project with eclipse.

    :cool: so is commands on terminal only way to compile and run C project? :rolleyes:
    As I understand it, you need to set Eclipse up correctly to do that.

    You should start a new thread that specifically asks for help in setting Eclipse up. Be sure to mention Eclipse in the title so as to draw the attention of someone familiar with it.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    not sure yet
    Posts
    5
    Rep Power
    0
    Originally Posted by dwise1_aol
    As I understand it, you need to set Eclipse up correctly to do that.

    You should start a new thread that specifically asks for help in setting Eclipse up. Be sure to mention Eclipse in the title so as to draw the attention of someone familiar with it.
    Thank you very much, it is much clear to me now. :D

IMN logo majestic logo threadwatch logo seochat tools logo