Fedora Linux Support Community & Resources Center
  #1  
Old 14th August 2009, 06:34 PM
physicsRocks Offline
Registered User
 
Join Date: Aug 2009
Posts: 34
linuxfedorafirefox
Question How to compile c program on fedora?

Hi folks,

This is my first time experience with Linux OS. I got some code from my professors to run. It is a program written by other. But I am not sure how to compile it and run it on the fedora.

I need some guides, what information may I provide to let you help me better?

Thanks
Reply With Quote
  #2  
Old 14th August 2009, 08:03 PM
jd50 Offline
Registered User
 
Join Date: Aug 2009
Location: Richmond, VA
Age: 32
Posts: 14
windows_vistafirefox
You'll need to use the gcc compiler.
Reply With Quote
  #3  
Old 14th August 2009, 08:35 PM
physicsRocks Offline
Registered User
 
Join Date: Aug 2009
Posts: 34
linuxfedorafirefox
How may I get the GCC? Or is Fedora 11 has it too.

If so, how may I open it and load my code on it? I guess I am having trouble to load the code into the complier and run it. Mechanically, what are the steps should I do if I have the code in a folder and the complier. How can I link them together?

Thanks
Reply With Quote
  #4  
Old 14th August 2009, 09:40 PM
l0vvrider Offline
Registered User
 
Join Date: Dec 2005
Age: 26
Posts: 35
linuxfedorafirefox
Well, first you need to install it with yum:

Code:
su -c 'yum install gcc -y'
I am not sure about correct syntax, but you can always check man pages for gcc.

Code:
man gcc
It should be something like this:

Code:
gcc filename.c -o filename
Then you run it with:

Code:
./filename
I would recommend you to install Geany maybe, open file with source code and then check Build menu. Probably all you need is compile and execute option.
Reply With Quote
  #5  
Old 15th August 2009, 06:03 AM
JohnVV Offline
Registered User
 
Join Date: Aug 2005
Location: Ann Arbor
Age: 47
Posts: 3,936
linuxfedorafirefox
you might want to install the devel tools and libraries along with just gcc
Code:
yum groupinstall "Development Tools" "Development Libraries"
see
Code:
 yum --help
man yum 
yum grouplist
for help
__________________
OpenSUSE 13.1-64bit & Scientific Linux 6.5-64bit ( fedora 4 to 11) and 19/20 on KVM
My Celestia Downloads

h t t p ://celestiamotherlode.net/catalog/show_creator_details.php?creator_id=10
Reply With Quote
  #6  
Old 15th August 2009, 09:15 AM
physicsRocks Offline
Registered User
 
Join Date: Aug 2009
Posts: 34
linuxfedorafirefox
Question

Thanks all for your help,

I have install the development libraries.

But when I am reading the INSTALL instruction from the program, there is a step I don't understand.
Quote:
3) Set the desired compiler flag in the makefiles in
`Analysis_progs` and `Initial_conditions` directories
There are folders named Analysis_progs and Initial_conditions, and there are a 'make' file in each folder. Those folder are part of my code. But I don't know what it means by "set desired compiler flag in the makefiles" What is that? How should i do it?

Thanks
Reply With Quote
  #7  
Old 15th August 2009, 10:51 PM
physicsRocks Offline
Registered User
 
Join Date: Aug 2009
Posts: 34
windows_vistafirefox
Hey folks,

what should I do with that instruction?

I appreciate your help.
Reply With Quote
  #8  
Old 15th August 2009, 11:48 PM
sonoran Offline
Registered User
 
Join Date: May 2005
Location: Sonoran Desert
Posts: 2,312
linuxmozilla
Try info make, info gcc, or google. It is YOUR homework.
Reply With Quote
  #9  
Old 16th August 2009, 03:52 PM
jd50 Offline
Registered User
 
Join Date: Aug 2009
Location: Richmond, VA
Age: 32
Posts: 14
linuxfedorafirefox
Quote:
Originally Posted by physicsRocks View Post
Hey folks,

what should I do with that instruction?

I appreciate your help.
Do what l0vvrider suggested. That should work for you.
Reply With Quote
  #10  
Old 16th August 2009, 10:25 PM
JohnVV Offline
Registered User
 
Join Date: Aug 2005
Location: Ann Arbor
Age: 47
Posts: 3,936
linuxfedorafirefox
with out seeing the Makefile , i can take a guess .That you need to edit the makefile to point to
( Analysis_progs` and `Initial_conditions ) these two folders .

Quote:
I got some code from my professors to run
I take it this is for a class ??? what dose your textbook say to do ?
__________________
OpenSUSE 13.1-64bit & Scientific Linux 6.5-64bit ( fedora 4 to 11) and 19/20 on KVM
My Celestia Downloads

h t t p ://celestiamotherlode.net/catalog/show_creator_details.php?creator_id=10
Reply With Quote
  #11  
Old 16th August 2009, 11:10 PM
physicsRocks Offline
Registered User
 
Join Date: Aug 2009
Posts: 34
linuxfedorafirefox
Quote:
Originally Posted by JohnVV View Post
with out seeing the Makefile , i can take a guess .That you need to edit the makefile to point to
( Analysis_progs` and `Initial_conditions ) these two folders .


I take it this is for a class ??? what dose your textbook say to do ?
Hi, this is a research project I am working on.
I realized now that I was never change my directory into the folder where the code are. No wonder whether how many time I tried with the gcc, it keep telling me I don't have the file in the directory.

I have change the directory into the file I need, and there is a makefile, so I type 'make' in the terminal, but there is an error pops up:

Quote:
gcc -arch x86_64 -o print_power_spec print_power_spec.c -lfftw3f -lm
gcc: x86_64: No such file or directory
cc1: error: unrecognized command line option "-arch"
make: *** [print_power_spec] Error 1
Did I do something wrong?

Cheers
Reply With Quote
  #12  
Old 17th August 2009, 05:24 AM
JohnVV Offline
Registered User
 
Join Date: Aug 2005
Location: Ann Arbor
Age: 47
Posts: 3,936
linuxfedorafirefox
Are you running fedora 11 64 bit operating system ?

i do think we will need to see the code for this .
at the very least the "Makefile"
something is not right hear . It might not be your fault but the codes fault .

some code can be a real " pain in the ( you know what ) "

also ask your prof this
" what VERSION of gcc did he/she write/build this for "
fedora 11 is using gcc 4.4 , and there have been A LOT of changes in it since gcc 4.0
so much so that most code older than 1 to 2 years needs to be edited to build with gcc 4.4 .
and if it was built for the VERY old gcc 3.4 then it will need a full rewrite

or built using the gcc34 legacy compiler ( it is in the fedora repos and can be installed with yum .)
__________________
OpenSUSE 13.1-64bit & Scientific Linux 6.5-64bit ( fedora 4 to 11) and 19/20 on KVM
My Celestia Downloads

h t t p ://celestiamotherlode.net/catalog/show_creator_details.php?creator_id=10
Reply With Quote
  #13  
Old 17th August 2009, 08:19 PM
physicsRocks Offline
Registered User
 
Join Date: Aug 2009
Posts: 34
linuxfedorafirefox
Quote:
Originally Posted by JohnVV View Post
Are you running fedora 11 64 bit operating system ?
I am not sure, how may I check that whether mine is 32 or 64 bit?

Quote:
i do think we will need to see the code for this .
at the very least the "Makefile"
something is not right hear . It might not be your fault but the codes fault .
I have post the makefile:
Quote:
# C compiler and flags
CC = gcc -arch x86_64 #for 64-bit intel processors
#CC = gcc #for general 32-bit machines

# Directory hosting the non-project specific code
COSMO_DIR = ../Cosmo_c_files

# Directory containing parameter files, definint relevant constants
PARAMETER_DIR = ../Parameter_files

# non-project dependencies
COSMO_FILES = ${PARAMETER_DIR}/COSMOLOGY.H \
${COSMO_DIR}/ps.c \
${COSMO_DIR}/integrator.c \
${COSMO_DIR}/cosmo_progs.c \
${PARAMETER_DIR}/INIT_PARAMS.H \
${PARAMETER_DIR}/ANAL_PARAMS.H \
${PARAMETER_DIR}/FLUX_PARAMS.H

# object files
OBJ_FILES = update_halo_pos \
halo_ps \
delta_T \
find_HII_bubbles \
paint_halos \
find_halos \
gen_size_distr \
halo_centered_extract_LOSs_nv \
halo_centered_extract_LOSs_xHI \
perturb_field \
flux_gen \
concat_flux
################################################## #######################

drive_zscroll: drive_zscroll.c \
bubble_helper_progs.c \
${OBJ_FILES} \
${COSMO_FILES} \

${CC} -o drive_zscroll drive_zscroll.c -lm


flux_gen: flux_gen.c \
${COSMO_FILES}

${CC} -lm -o flux_gen flux_gen.c


concat_flux: concat_flux.c \
${COSMO_FILES}

${CC} -lm -o concat_flux concat_flux.c


perturb_field: perturb_field.c \
${COSMO_FILES}

${CC} -o perturb_field perturb_field.c -lfftw3f -lm


halo_centered_extract_LOSs_nv: halo_centered_extract_LOSs_nv.c \
${COSMO_FILES}

${CC} -lm -o halo_centered_extract_LOSs_nv halo_centered_extract_LOSs_nv.c


halo_centered_extract_LOSs_xHI: halo_centered_extract_LOSs_xHI.c \
${COSMO_FILES}

${CC} -lm -o halo_centered_extract_LOSs_xHI halo_centered_extract_LOSs_xHI.c


update_halo_pos: update_halo_pos.c \
${COSMO_FILES}

${CC} -lm -o update_halo_pos update_halo_pos.c


halo_ps: halo_ps.c \
${COSMO_FILES}

${CC} -o halo_ps halo_ps.c -lfftw3f -lm



delta_T: delta_T.c \
${COSMO_FILES}

${CC} -o delta_T delta_T.c -lfftw3f -lm


find_HII_bubbles: find_HII_bubbles.c \
bubble_helper_progs.c \
${COSMO_FILES}

${CC} -o find_HII_bubbles find_HII_bubbles.c -lgsl -lgslcblas -lfftw3f -lm


paint_halos: paint_halos.c \
bubble_helper_progs.c \
${COSMO_FILES}

${CC} -lm -o paint_halos paint_halos.c


find_halos: find_halos.c \
filter.c \
${COSMO_FILES}

${CC} -o find_halos find_halos.c -lfftw3f -lm


clean:
rm drive_zscroll ${OBJ_FILES} *~

Thanks
Reply With Quote
  #14  
Old 17th August 2009, 08:34 PM
JohnVV Offline
Registered User
 
Join Date: Aug 2005
Location: Ann Arbor
Age: 47
Posts: 3,936
linuxfedorafirefox
at first glance it looks like the Makefile is for 32 bit AND 64 bit systems
you will need to move the #
Code:
# C compiler and flags
CC = gcc -arch x86_64 #for 64-bit intel processors
#CC = gcc #for general 32-bit machines
to look like this
Code:
# C compiler and flags
#CC = gcc -arch x86_64 #for 64-bit intel processors
CC = gcc #for general 32-bit machines
also this " -lfftw3f " ( lib fast Fourier 3 ) is not installed by default
to install -- it is in the fedora repos -- run
Code:
yum search fftw
--- i get this list ---
fftw.i586 : Fast Fourier Transform library
fftw-devel.i586 : Headers, libraries and docs for the FFTW library
fftw-static.i586 : Static version of the FFTW library
fftw2.i586 : Fast Fourier Transform library
fftw2-devel.i586 : Headers, libraries and docs for the FFTW library
to install
Code:
su -
( your root password when asked )
yum install fftw-devel fftw
if you get a error saying that lfftw3f is missing
edit the makefile to this " -lfftw3 "
__________________
OpenSUSE 13.1-64bit & Scientific Linux 6.5-64bit ( fedora 4 to 11) and 19/20 on KVM
My Celestia Downloads

h t t p ://celestiamotherlode.net/catalog/show_creator_details.php?creator_id=10
Reply With Quote
  #15  
Old 17th August 2009, 08:47 PM
physicsRocks Offline
Registered User
 
Join Date: Aug 2009
Posts: 34
linuxfedorafirefox
Hi JohnW,

I run yum to install the fftw, and I did installed couple days ago.

This is what it give me back

Quote:
Setting up Install Process
Package fftw-devel-3.2.1-2.fc11.i586 already installed and latest version
Package fftw-3.2.1-2.fc11.i586 already installed and latest version
Nothing to do
And I have change the # as you mentioned. The new error has prompted:

Quote:
gcc -lm -o update_halo_pos update_halo_pos.c
In file included from update_halo_pos.c:1:
../Parameter_files/INIT_PARAMS.H:16:33: error: gsl/gsl_integration.h: No such file or directory
../Parameter_files/INIT_PARAMS.H:17:25: error: gsl/gsl_rng.h: No such file or directory
../Parameter_files/INIT_PARAMS.H:18:29: error: gsl/gsl_randist.h: No such file or directory
make: *** [update_halo_pos] Error 1
Wow, jesh, for sure this is not a good first experience in dealing to Linux wew

Would that help if I am gonna post the .H file too? They are in a different folder.
Reply With Quote
Reply

Tags
compile, fedora, program

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot compile a simple c program dash Using Fedora 21 13th February 2009 01:56 PM
help me compile the program dvdbackup d_GeNeRiT Using Fedora 6 14th April 2006 11:06 AM
Compile program issue GreyWizzard Using Fedora 5 14th April 2006 12:37 AM
cant compile simple c++ program... help! sirbrett Programming & Packaging 3 1st September 2005 08:37 PM


Current GMT-time: 22:32 (Monday, 28-07-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat