LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   LinuxAnswers Discussion (https://www.linuxquestions.org/questions/linuxanswers-discussion-27/)
-   -   DISCUSSION: Building C programs on Linux (https://www.linuxquestions.org/questions/linuxanswers-discussion-27/discussion-building-c-programs-on-linux-81346/)

crabboy 08-12-2003 02:28 PM

DISCUSSION: Building C programs on Linux
 
This thread is to discuss the article titled: Building C programs on Linux

darin3200 08-13-2003 08:11 PM

Looks nice. Hopefully java expierence will be helpful, I want to learn C and my school never has enough people sign up for the class to have it. Thanks

genesis1923 08-14-2003 04:22 AM

Looks good but my problem is that SuSE Office desktop does not come with a C compiler. What would be really useful for me is a section on how to get started if you don't have a C compiler.

svar 08-21-2003 09:42 AM

??? what do you mean Suse does not come with a C compiler?
gcc is the GNU C compiler
and it is packaged with Suse, last time I checked(up to SuSe 8)

svar

jim mcnamara 10-31-2003 04:32 PM

make comment:

under several flavors of unix make does not require tab characters in rules. They don't break anything if they are there.

The other thing which confuses new folks : K&R, ANSI "styles"
Code:

/* ----- version 1 */
int main(argc, argv)
int argc;
char **argv;
{
      return 0;
}

/* ---- version 2 */
int main(int argc, char *argv[])
{
      return 0;
}

/* --------- version 3 */
int main(int argc, char *argv[]){
        return 0;
}

Believe it or not, C shops usually prefer style #3 - very 'ANSI'
Style 2 is "okay", style 1 is a no-no.

A lot of examples I've seen that come with downloads were written in 1985 and look like version 1.

While it doesn't REALLY matter, this is confusing as hell to newbies.

You might want to consider adding a section talking about style.
Plus, version 1 won't compile under cc -Aa on HPUX v11.0 for example. So, it can cause some issues down the road.

wilson-china 03-02-2004 09:49 PM

a good subject

Dazed_75 01-19-2006 11:57 PM

Although you begin the article saying it is inended for folks who know C but do not know how to build a program under Linux, you spend much of the article expplaining the simple C program. You spend very little of the article saying how building it is different in Linux. I have some 15= year old experience In C under DOS, Windows and Unix (a little). I was hoping to see this article show how to set up my environment under Linux and how some of the tools differ or have improved.

When I saw the first line in the 1st program as "#include" with no argument as to WHAT to include and your statement that it meant you were using the stdio library, I thought I was on the right track. However, gcc gives the expected errors on that line (yes, I named the file differently):

inctest.c:1:9: error: #include expects "FILENAME" or <FILENAME>
inctest.c: In function ‘main’:
inctest.c:5: warning: incompatible implicit declaration of built-in function ‘printf’

I infer not that your article is wrong, but that your environment is set up differently. Specifically, I found some other articles referring to default includes but they did not help either. Now I don't mind; in fact, I like being explicit about my includes so this is not a big deal detail. What I would like to find though is some information that really IS about how building C programs in Linux is different from other environments. Any suggestions?

robin2190 01-21-2006 09:35 AM

how do i install simply mepis 2004 2.6.7.? HELPPPPPPPPP

Darkhack 03-20-2006 01:45 PM

Quote:

Originally Posted by Dazed_75
When I saw the first line in the 1st program as "#include" with no argument as to WHAT to include and your statement that it meant you were using the stdio library, I thought I was on the right track. However, gcc gives the expected errors on that line (yes, I named the file differently):

inctest.c:1:9: error: #include expects "FILENAME" or <FILENAME>
inctest.c: In function ‘main’:
inctest.c:5: warning: incompatible implicit declaration of built-in function ‘printf’

Sadly, the author must have forgotten that his text would be displayed "as-is" in a browser and that they don't render < or > very well. In order to display the greater-than or less-than signs, you must use the following... (hopefully the author will fix it)

> = &gt;
< = &lt;

xushi 03-25-2006 12:07 PM

I understand the author's kind intentions, but this is a very poor article. I'm not sure how the LQ mods allowed it to be posted, and furthermore, i'm not sure why or how the author didn't preview his work, or check/fix any mistakes afterwards. I'm not referring to tricky or blind-eye mistakes, but big ones such as the #include bit on the top.

Furthermore, adding to the comments said above, this hasn't really shown us any differences between building a typical C program, and building a C program for Linux.

And as an added suggestion, some outside links to more indepth tutorials for certain sections would do good.

I hope this article gets fixed. It is valuable and it's needed in LQ.

kumar.anupam 02-19-2008 01:29 AM

storage of temporary variables in C
 
where does the temporary variables gets stored while executing C program.

bigearsbilly 04-21-2008 05:42 AM

also, you don't need a makefile to use make's implicit rules
for simple C files:

Code:


$ printf '#include <stdio.h>\nmain()\n{\nputs("hello");\n}\n' > dummy.c
$ make dummy
cc    dummy.c  -o dummy
$ ./dummy
hello


kitiya 04-15-2009 02:50 AM

anyone know the coding for this progarmmes
 
i got 2 questions and i try to write codes for this. its dosent working propoerly. anyone know how to do coding for this questions. thanks

1) Instead of producing the summation of the given non-negative integer,
modify this program and make it create only one
thread that will calculate the factorial. When the thread finishes execution,
the parent thread will output the factorial calculated by the child thread


2 ) Besides of producing the summation of the given non-negative integer,
modify this program and make it create two threads.
One thread is to produce the summation of the given non-negative integer;
the other thread is to calculate the factorial. When the two child threads
finish execution, the parent thread will output the summation and the
factorial of the given non-negative integer

linux.sridhark 05-03-2009 11:13 PM

Sri
 
Nice tutorial

ahmedtaw 05-12-2009 01:59 PM

help help :(
 
char c[20];
printf("\n\nPlease enter the name of the file: ");
scanf("%s",c);
printf("\nthe name you type is : %s\n",c);
system("mkdir c");

problem now in line 5 ,it make the folder name as c not the string i have enter


All times are GMT -5. The time now is 02:10 AM.