LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-30-2005, 04:43 AM   #1
BBPS
LQ Newbie
 
Registered: Aug 2003
Posts: 18

Rep: Reputation: 0
Problem Compiling C code on FC4


Hi,

I am not a C programmer at all, but have been given the task of compiling some custom C programs on Fedora Core 4.

When compiling some C code that compiles fine on another machine, I was getting some errors, so I tried the most basic of code to compile and this too had errors.

This is the simple code I tried to compile:
Quote:
#include <stdlib.h>

static void cleanup(void) __attribute__ ((destructor));

main()
{
printf("\nHello World\n");
exit(0);
}

void cleanup(void)
{
printf("\nCleaning up using destructors\n\n");
}
When I compile it using the command:

gcc test.c -o test.exe

...I get the following warnings:
Quote:
test.c: In function 'main':
test.c:7: warning: incompatible implicit declaration of built-in function 'printf'
test.c: In function 'cleanup':
test.c:13: warning: incompatible implicit declaration of built-in function 'printf'
It does compile, and creates the test.exe which works as I would expect:

Quote:
# ./test.exe

Hello World

Cleaning up using destructors
I am running Kernel 2.6.12

Quote:
Linux svr-fc4 2.6.12-1.1456_FC4smp #1 SMP Thu Sep 22 02:22:14 EDT 2005 i686 i686 i386 GNU/Linux
I have version 4.0.1 of GCC Installed:
Quote:
#gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --host=i386-redhat-linux
Thread model: posix
gcc version 4.0.1 20050727 (Red Hat 4.0.1-5)
Does anyone know how I can get it to compile without the warnings please ?

Many thanks,


Paul.
 
Old 09-30-2005, 06:01 AM   #2
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
Hi!

You are passing wrong arguments to the GNU compiler. .exe are also Windows executables. Try:

gcc -o test test.c

That will compile test.c into an executable file called test. You should be able to execute that file by typing ./test on the same folder where the source code is.

Regards!
 
Old 09-30-2005, 06:07 AM   #3
BBPS
LQ Newbie
 
Registered: Aug 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Hi Mega Man,

Many thanks for taking the time to reply. I did try before with different extensions for the output file, but had the same results.

I tried doing it how you suggested, but still get the same warnings:

Quote:
# gcc -o test test.c
test.c: In function 'main':
test.c:7: warning: incompatible implicit declaration of built-in function 'printf'
test.c: In function 'cleanup':
test.c:13: warning: incompatible implicit declaration of built-in function 'printf'
# ./test

Hello World

Cleaning up using destructors

#
...any other suggestions ?

Thanks,


Paul.
 
Old 09-30-2005, 07:51 AM   #4
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
You must include stdio.h; that contains the prototype for printf.

Be carefull with the use of the name test for your resulting program as it's a standard Linux command.
 
Old 09-30-2005, 11:23 AM   #5
BBPS
LQ Newbie
 
Registered: Aug 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Hi Wim, many thanks for that, I managed to compile that fine....and even managed to work out why the main program I was compiling didn't work.

Cheers,


Paul.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
compiling problem qmailmrtg on FC4 planetdar420 Fedora 1 10-28-2005 04:51 AM
Where is FC4 bootCD init source code? caljjc Fedora 2 10-24-2005 04:09 PM
RedHat3.0: problem when compiling C++ code using the 'ldap' structure WuKitty Linux - Software 0 09-12-2005 01:52 PM
Problem compiling code in g++ works for gcc juan_de_margo Programming 3 02-24-2005 03:41 AM
Problem in compiling source code JIV Linux - Software 1 02-14-2004 03:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration